on ‎2021 Feb 22 9:30 AM
Hi everyone, I'm having issues using AddressReversePopulator for converting AddressData to AddressModel.
The problem shows up on this line on populate(addressData, addressModel) method
addressModel.setLine1(addressData.getLine1());
addressModel.setLine2(addressData.getLine2());
The method setLineX on AddressModel.java uses
getPersistenceContext().setDynamicValue(this,LINE1, value);
but the DynamicAttributesProvider() in the ItemModelContextImpl.class is null when triying to populate Line1 and Line2.
How can I solve this problem?
Thank You
Request clarification before answering.
Hi,
as you can see from basecommerce-items.xml
<itemtype code="Address" autocreate="false" generate="false">
<description>Extending Address type with additional attributes.</description>
<attributes>
<attribute qualifier="line1" type="java.lang.String">
<description>Address line1 is a dynamic attribute that is stored in the Address.streetname field</description>
<persistence type="dynamic" attributeHandler="addressLine1Attribute" />
</attribute>
<attribute qualifier="line2" type="java.lang.String">
<description>Address line2 is a dynamic attribute that is stored in the Address.streetnumber field</description>
<persistence type="dynamic" attributeHandler="addressLine2Attribute" />
</attribute>
</attributes>
</itemtype>
you can see that 2 attributeHandler have been defined, in basecommerce-spring.xml
<bean id="addressLine1Attribute" class="de.hybris.platform.basecommerce.model.AddressLine1Attribute"/>
<bean id="addressLine2Attribute" class="de.hybris.platform.basecommerce.model.AddressLine2Attribute"/>
public class AddressLine1Attribute extends AbstractDynamicAttributeHandler<String, AddressModel> {
public String get(AddressModel addressModel) {
if (addressModel == null) {
throw new IllegalArgumentException("address model is required");
} else {
return addressModel.getStreetname();
}
}
public void set(AddressModel addressModel, String value) {
if (addressModel != null) {
addressModel.setStreetname(value);
}
}
}
public class AddressLine2Attribute extends AbstractDynamicAttributeHandler<String, AddressModel> {
public String get(AddressModel addressModel) {
if (addressModel == null) {
throw new IllegalArgumentException("address model is required");
} else {
return addressModel.getStreetnumber();
}
}
public void set(AddressModel addressModel, String value) {
if (addressModel != null) {
addressModel.setStreetnumber(value);
}
}
}
when you try to write an information in the line1 field it is saved in the streetname field, when you try to write in the line2 field it is saved in the streetnumber field.
I hope it was helpful.
Regards,
Crescenzo Rega
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try to define the following beans in your *core extension in the *core-spring.xml file
<bean id="addressLine1Attribute" class="de.hybris.platform.basecommerce.model.AddressLine1Attribute"/>
<bean id="addressLine2Attribute" class="de.hybris.platform.basecommerce.model.AddressLine2Attribute"/>
and restart the server
@Accessor(qualifier = "line1", type = Accessor.Type.SETTER)
public void setLine1(final String value)
{
getPersistenceContext().setDynamicValue(this,LINE1, value);
}
And then doesn't get into the if statement because this.getDynamicAttributesProvider = nullpublic <T> void setDynamicValue(AbstractItemModel model, String attribute, T value) {
if (this.getDynamicAttributesProvider() != null) {
this.getDynamicAttributesProvider().set(model, attribute, value);
}}
Hi superpalmi,
obviously the two converters are not the same thing, however the important thing is that you have solved the problem.
Regards,
Crescenzo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.