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

AddressReversePopulator does not populate Line1 on AddressModel

superpalmi
Explorer
0 Likes
613

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

Accepted Solutions (0)

Answers (1)

Answers (1)

crescenzorega
Active Participant
0 Likes

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

superpalmi
Explorer
0 Likes

Thank you for your response, during debug I discovered that, but It still doesn't populate streetname and streetnumber. It seems like it doesn't enter in the Attribute Handler.

crescenzorega
Active Participant
0 Likes

At the moment the only things that come to mind are

  • addressData.getLine1 () not valued, try to verify the value
  • addressLine1 Attribute and address Line2 Attribute not loaded in the context, try to check from HAC if the beans are present with the command spring.getBean("addressLine1")
superpalmi
Explorer
0 Likes

spring.getBean("addressLine1") gives me this error

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'addressLine1' available]
crescenzorega
Active Participant
0 Likes

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

superpalmi
Explorer
0 Likes
It goes into setDynamicValue()
@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 = null
public <T> void setDynamicValue(AbstractItemModel model, String attribute, T value) {
if (this.getDynamicAttributesProvider() != null) {
this.getDynamicAttributesProvider().set(model, attribute, value);
}}
crescenzorega
Active Participant
0 Likes

I suggest you define the beans as written in the comment above

superpalmi
Explorer
0 Likes

Nope, it still doesn't enter in the if statement

crescenzorega
Active Participant
0 Likes

the beans are present with the command spring.getBean("addressLine1") ?

superpalmi
Explorer
0 Likes

yes, i had this result:

de.hybris.platform.basecommerce.model.AddressLine1Attribute@27b208f3 but the dynamicAttributesProvider in the class is still null

crescenzorega
Active Participant
0 Likes

I think you have 2 ways

  • open a ticket to sap support
  • you write a custom class myAddressReversePopulator where you go to set the fields you need
superpalmi
Explorer
0 Likes

I think I found out the problem:

this doesn't work

addressModel = addressReverseConverter.convert(addressData) 

this works

addressReverseConverter.convert(addressData, addressModel)
crescenzorega
Active Participant

Hi superpalmi,

obviously the two converters are not the same thing, however the important thing is that you have solved the problem.

Regards,

Crescenzo