Question

I have a table with many rows, and each row has a link to a modal dialog box using struts2-jquery. I need to set a unique ID for each dialog in order to set this up, but I've tried multiple options without luck.

        <s:iterator value="myBeanList" var="rrSum" status="status">
            <tr>
                <td>
                    <s:url id="ajax%{status.index}" action="smoRiskRegister" var="ajaxURL">
                        <s:param name="requestRiskID"><s:property value="#rrSum.rid" /></s:param>
                    </s:url>

                    <sj:dialog id="dialog3" href="%{ajaxURL}" title="Testing" />
                    <sj:a openDialog="dialog3"><s:property value="#rrSum.rid" /></sj:a>

                </td>
            </tr>
        </s:iterator>

So instead of "dialog3" I want something like dialog%{status.index}. I can set the ID to this... but how do I reference it in the anchor tag? Unfortunately there is no var parameter for dialog :(

Was it helpful?

Solution

Just use %{#status.index} in anchor tag as well.

<sj:dialog id="dialog%{#status.index}" href="%{ajaxURL}" title="Testing" />
<sj:a openDialog="dialog%{#status.index}"><s:property value="#rrSum.rid" /></sj:a>

Note # sign, one have to use it when accessed object is not in the OGNL root.

The Action instance is always pushed onto the value stack. Because the Action is on the stack, and the stack is the OGNL root, references to Action properties can omit the # marker. But, to access other objects in the ActionContext, we must use the # notation so OGNL knows not to look in the root object, but for some other object in the ActionContext.

Read about OGNL in Struts2: http://struts.apache.org/2.x/docs/ognl.html.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top