Search code examples
javajqueryjspliferaygetter-setter

Setter concatenates value twice separated by comma


I'm trying to pass a value ferm a jsp back to the bean. I create an action url with several parameters and they are all set correctly but the company name is set to "companyName, companyName" instead of just "companyName"

This is my url

var url="<liferay-portlet:actionURL><liferay-portlet:param name='struts.portlet.action' value='/reg/submitStep1'/><liferay-portlet:param name='isSimplified' value='true'/></liferay-portlet:actionURL>&customerNo=" + custNo + "&companyName=" + companyName;

I get the company name variable from the text field using jquery. The text input's id is companyName

var companyName = $('#companyName').val();

When I print it out using console.log(companyName); the value is fine, not concatenated twice.

In the setter, however, the value of the String is set to "companyName, companyName". All otherparameters (isSimplified, customerNo) are fine. Any idea why this is happening?


Solution

  • You are passing companyName as url parameter and form parameter as well, hence you are getting both parameters on server side.

    Keep only one parameter either as url parameter or as form parameter.