iterator - Struts2 tags: get a request attribute whose name is itself a value of another request attribute -
i have list of table names in request attribute, "billsummarytables". iterating through list , want utilize each table name request attribute particular table name. corresponding each table name have list in request attribute , want iterate through that.
this doing.
<s:iterator value='#request.billsummarytables' var="tablename" status="itstatus"> <div class="contentbox" role="content"> <table class="rpt"> <s:iterator value="#request.get('%{#tablename}').getdata()" var="ocrow" status="itstatus"> <tr style="border:1px solid #cccccc"> <s:iterator value='#ocrow' var="cell" status="itstatus2"> <td> <s:property value="#cell.getvalue()"/> </td> </s:iterator> </tr> </s:iterator> <tr> <s:iterator value="#request.get('%{#tablename}').getdata()" var="octotal"> <td> <s:property value="#octotal"/> </td> </s:iterator> </tr> </table> </div> </s:iterator> i have tried
#request[<s:property value="#tablename" />].getdata() and
#request['<s:property value="#tablename" />'].getdata() and
#request.%{#tablename} but nil returned in case. however, code works fine if hard code values. i.e. if use: #request['other_charges'].getdata()
note: able retrieve list of tablename (#request.billsummarytables).
#1) using 3 nested iterators, both first , sec have instance of iteratorstatus called itstatus; must have different names work.
#2) if lists corresponding table name is, effectively, list, should iterate list, not getdata() stuff (what ?)
#3) why using request ? why not using hashmap on action (with getter), adding elements dynamically using table names key ?
#4) #request[<s:property value="#tablename" />].getdata() not work if set within struts2 tag, iterator (cannot nest struts2 tags).
however, seek (i stripped sec iterator, create running before, add together stuff), , see if works (and prints):
<s:iterator value='#request.billsummarytables' var="tablename" status="statusalltables"> <div class="contentbox" role="content"> <br/>==== start debug ==== <br/>current table name: [<s:property value="#tablename"/>] <br/>corresponding request object: [<s:property value="#request['%{#tablename}']"/>] <br/>getdata on object: [<s:property value="#request['%{#tablename}'].getdata()"/>] <br/>===== end debug ===== <table class="rpt"> <s:iterator value="#request['%{#tablename}'].getdata()" var="ocrow" status="statusthistable"> <tr style="border:1px solid #cccccc"> <s:iterator value='#ocrow' var="cell" status="statusthisfield"> <td> <s:property value="#cell.getvalue()"/> </td> </s:iterator> </tr> </s:iterator> </table> </div> </s:iterator> edit
ok, why using request.setattribute ? actions created per-request... utilize private list<myobjects> myobjects getter (public list<myobject> getmyobjects()), , phone call jsp <s:iterator value="myobjects"> (in case, <s:iterator value="myobjects.data">.
please note .getdata() in ognl should become .data (i didn't noticed before), removing get, lowering first letter of method, , removing round brackets...
retry , allow know.
struts2 iterator ognl
No comments:
Post a Comment