cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Item is null in the translator

Former Member
0 Kudos
667

Hello,

Could any one help why I am getting Item as null in the importValue(..) method. Here is my code.. The class extending AbstractValueTranslator.

@Override public Object importValue(final String valueExpr, final Item processedItem) throws JaloInvalidParameterException { String courseName = null; try { courseName = processedItem.getAttribute("name").toString(); } catch (final JaloSecurityException e) { setError(); } return courseName + "translator testing"; } Here is the impex..

insert_update testing;code[unique=true];name[translator=com.test.translators.TestTranslator]

;500;test name

The valueExpr is coming as test name but the Item coming as null..

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi ,

I tried creating a simple translator, just like you did, extending the AbstractValueTranslator. I was able to get the processedItem, and it was not null.

The item object that comes in the parameter, is the jalo item, and hence calling processedItem,getAttribute("name") does not give the desired value.

You will need to either cast the "item" object into target jalo or convert to target jalo. For example: My dummy translator "TestNameValueTranslator "

 public class TestNameValueTranslator extends AbstractValueTranslator{
 
     @Override
     public Object importValue(String arg0, Item arg1) throws JaloInvalidParameterException {
         { 
             String courseName = null;
             courseName = ((Product)arg1).getCode();
             return courseName + "translator testing" +arg0; 
         }
     }
 
     @Override
     public String exportValue(Object arg0) throws JaloInvalidParameterException {
         return arg0.toString();
     }
 

And my impex :

 INSERT_UPDATE Product;code[unique=true];name[translator=hybris.expert.impex.translator.TestNameValueTranslator]
 ;test;abc

My output was: "testtranslator testingabc"

Hope this help !

Regards,

Former Member
0 Kudos

Hi .

The translator is used to return a item type as you can check in hybris wiki link: https://help.hybris.com/6.6.0/hcd/8bee24e986691014b97bcd2c7e6ff732.html.

If you want to return a concatened string I suggest to use decorator instead translator.

Best regards.

Former Member
0 Kudos

Thanks for your quick response. It is not just concatination. I need to perform some logic.. Also the URL that you posted is not working.. I had break point in the translator and I can see the value coming but Item is null. I followed the help document and I didn't get why the item coming as null..