Search code examples
struts2ognl

More than one parameters in URL Struts2


I wanted to pass more than one parameter for an action. but when i build the URL using Struts2, it builds with only one parameter. May i know what is went wrong in the below code?

<s:url action="loadValidLevelValueDropDown" id="levelvalueURL" escapeAmp="false">
  <s:param name="hierarchyId" value="searchAttribute.hierarchyId.id"></s:param>
  <s:param name="valuebycoulmn" value="refcolumnName%{#level.count}"></s:param>
</s:url>

result is,

/appname/loadValidLevelValueDropDown.action?hierarchyId=1

Solution

  • The value attribute of <s:param> tag takes OGNL expression as a value. Your refcolumnName%{#level.count} value is not a valid expression so parameter is not being appended to url.

    If your refcolumnName is a collection than you can access it like that:

    <s:param name="valuebycoulmn" value="refcolumnName[#level.count]" />
    

    if it supposed to be a string than you need to append it like string:

    <s:param name="valuebycoulmn" value="'refcolumnName' + #level.count" />