Thiêm
Thiêm

Reputation: 155

Struts2 dynamic url action in IBM Portal

I'm trying to create a dynamic menu bar using struts2 url tag. I got the list of menus from webservice and try to generate corresponding URL to each menu. I tried this code

<s:iterator value="roleMenus" id="child">
<s:if test="parentCode == #parent.childCode">
    <s:if test="childCode != #parent.childCode">
        <c:set var="link"><s:property value='menuLink'/></c:set>
        <% menulink = (String)pageContext.getAttribute("link"); 
            System.out.println(menulink);%>
        <li><a id='<s:property value="menuLink"/>' name="menulink" href="<s:url action='xxxxx'/>"><s:property value="menuName"/></a></li>
    </s:if>
</s:if>

with Action attribute value passed in scriptlet

<%=menuLink%>

or JSTL variable

${link}

but it throws an exception

According to TLD or attribute directive in tag file, attribute "[action]" does not accept any expressions.

so I guess this cannot be done using any kind of dynamic expressions in Action attribute.

I'm thinking of overriding the method that generates URL when s:url tag get called but I don't have a clue how to do that. It generates urls like this in IBM Portal:

/wps/myportal/!ut/p/b1/jZDbToNAFEW_pR9gzhmG6-OEyMVhUGCowAsh2BiQS6yI0q-X9qkm1va87WSt7J0DBeTE1C2dWhrVIYNiqObmtZqacai6Yy70MmSpw9mTio9oOujHWkKpESnoHoX8HEBCcAU8LVWEUNZ4m2-7zFONANEMXA195qWxFVGKjF7zn6H4jfyx4AT8V3EC8MIxhNAb-x3kK2Zc3GIiZHOz-4LtMO779XUSMlTLpF3GT56ME3_J94ttvi_p24T1HEoctu1yCKRNs28tFtI2Hg6ilC2JCLO7KKxbkWA_obgj3Knvmctn7n9soC86x_JbNffZ5gdG203G/dl4/d5/L0lDU0NtbUEhL3dPb0JKaVVNcHJDSy80RzNhRFVRZy9aN19OQVVGS0FQNDBPMDhGMElSNVMzMzdRMjA4MC8lMHZpZXclMEFwcExvZw!!/

Does anyone have any ideas for this? Any help will be very much appreciated.

Upvotes: 0

Views: 1167

Answers (1)

MohanaRao SV
MohanaRao SV

Reputation: 1125

This is sample example to generate dynamic url. I hope this helps you.

<s:set name="days" value="{'monday', 'tuesday', 'wednesday','thrusday','friday' }" />

<s:iterator var="day" value="#days">
    <s:url action="%{#day}" var="urlTag"></s:url>
    <s:property value="%{urlTag}"/><br/>
</s:iterator>

Upvotes: 1

Related Questions