and then you try to add an address, well there is a bug, you may find while testing it. If you dont fill up any field it will redirect you to
Exception evaluating SpringEL expression: "address.phonePrimary.phoneNumber" (account/manageCustomerAddresses:36)
So, what is the reason and what to do about it?
Well evidently, the problem is with phone number field.
If you look closely at the line in templates/account/manageCustomerAddresses.html
Find Phone field. And you'll find a line something like this:
Code: Select all
<input type="tel" id="address.phonePrimary" name="address.phonePrimary" th:value="*{address.phonePrimary.phoneNumber}" class="field30 cloneable" />
The problem as stated in the error page (scroll down) is
Field or property 'phoneNumber' cannot be found on null
So when you add a new address, if you dont add a phone number, it takes up null value which leads to this error, which i guess we will want to avoid.
Why? Because in the code of Phone text field we have provided its value to be such.
Code: Select all
th:value="*{address.phonePrimary.phoneNumber}"
It was to be used in case we already have an address and we plan on changing it, thus the phone number value will not be null, but i guess nobody noticed a possibility of creating address for the first time and leaving Phone number empty.
But the actual problem, in fact, isn't with the phone number being empty, it is erratic because the input field is getting value from a a form that doesn't exist. A new form can not load phone number as if it already exists. So we need to make sure that a new form doesn't get to access variable address.phonePrimary.phoneNumber.
So what you need to do?
files:
target/mycompany/web-inf/templates/account/manageCustomerAddresses.html
and
site/src/main/webapp/web-inf/templates/account/manageCustomerAddresses.html
Find
Code: Select all
id="address.phonePrimary"
IN the same line, change the th:value
from:
Code: Select all
"*{address.phonePrimary.phoneNumber}"
to:
Code: Select all
"${customerAddressForm.customerAddressId != null} ? *{address.phonePrimary.phoneNumber}"
So finally the line which is(WAS) the cause of error, now, looks like:
Code: Select all
<input type="tel" id="address.phonePrimary" name="address.phonePrimary" th:value=" ${customerAddressForm.customerAddressId != null} ? *{address.phonePrimary.phoneNumber}" class="field30 cloneable" />
EXPLANATION (only if you want it)
We need to tell it to take the value only if the address has already been created. If you look in the <form> you'll find something like this in the action attribute:
Code: Select all
@{'/account/addresses/' + ${customerAddressForm.customerAddressId != null ? customerAddressForm.customerAddressId : ''}}
From this we could figure out the code that decided whether a new address is being saved or we are just editing the previous address.
Code: Select all
${customerAddressForm.customerAddressId != null}
It seemed that customerAddressId is a field in customerAddressForm and thus if its not null for the current form, we are not creating a new form. Thus all we needed to do was use ?: operator and populate th:value only if it wasn't a new form and
Code: Select all
${customerAddressForm.customerAddressId != null} ? *{address.phonePrimary.phoneNumber}
solved the purpose.
For more information and help with images and screenshots, visit : http://new-beee.blogspot.in/2013/09/manage-customer-address-phone-number.html