Search code examples
jspurlstruts2ognl

Struts2 Dynamic hyperlink generation using Arraylist


I am using struts and iterating over list of strings. I want to generate dynamic hyperlink based on the value of prs element.

"s" is list iterator and prs is one of it's fields needs to be appended after s:url value example.com/web/default/100#data_tab

<td class="R0C0" > <a href="<s:url value="example.com/web/default/<s:property value="prs" />#data_tab"  />" target="_blank"><s:property value="prs" /></a>

So for example if list have two elements and value of prs are 100 and 200 respectively. Then i want url to be generated as follows,

s:url value example.com/web/default/100#data_tab
s:url value example.com/web/default/200#data_tab

Solution

  • You can't use Struts tags like that. You can use OGNL expression to write the value of prs.

    <a href="<s:url value='example.com/web/default/%{prs}' />#data_tab" target="_blank"><s:property value="prs" /></a>