How to call java method from a simple method in ofbiz

489 views Asked by At

I am trying to call java method from simple method like this

<simple-method method-name="getProduct">
    <entity-one entity-name="Product" value-field="product">
      <field-map field-name="productId" from-field="parameters.productId" />
    </entity-one>
    <log message="productView=${product.uom}" level="info"/>
    <entity-one value-field="uomInfo" entity-name="Uom">
      <field-map field-name="uomId" from-field="product.uom" />
    </entity-one>
    <if-compare operator="equals" value="1001" field="product.priceTypeId">
    <entity-one value-field="category" entity-name="ProductCategory">
      <field-map field-name="productCategoryId" from-field="product.priceTypeCategoryId" />
    </entity-one>
    <else>
     <entity-one value-field="category" entity-name="ProductCategory">
      <field-map field-name="productCategoryId" from-field="product.productCategoryId" />
     </entity-one>
    </else>
    </if-compare>
    <set field="product.productCategoryId" from-field="category.categoryName" default-value="all"/>
    <call-class-method method-name="encodeString" ret-field="encodedDescription" class-name="org.ofbiz.base.util.StringUtil">  
    <field field="product.description" type="String" /> 
    </call-class-method> 
    <field-to-result field="product" />
    <field-to-result field="uomInfo" />
  </simple-method>
</simple-methods>

When I am trying to get the value of description field, It is returning the same value of description without updated with encoded value.

Is there any other thing I need to do?

1

There are 1 answers

0
Sonu Gupta On BEST ANSWER

you are not setting the description value with return string.

<call-class-method method-name="encodeString" ret-field="encodedDescription" class-name="org.ofbiz.base.util.StringUtil">  
    <field field="product.description" type="String" /> 
    </call-class-method> 

Your encodeString method will return an encoded string and set it to

return field ret-field="encodedDescription".

So you need to set your description like this

    <call-class-method method-name="encodeString" ret-field="encodedDescription" class-name="org.ofbiz.base.util.StringUtil">  
    <field field="product.description" type="String" /> 
    </call-class-method> 
    <set field="product.description" value="${encodedDescription}"/>