How to use property value as textarea value in struts 2 - struts2

Instead of just displaying list values using <s:property/>, i need to display it in textarea.The reason why i am doing this is <s:property/> does not have "name" attribute in order to submit the values to the action class. Is there any way to do that.I wrote down piece fo code below to make it clear so that you can understand my requirement though it is wrong.Please help me.
<s:iterator value="map" status="stat">
<s:textarea value="<s:property/>" />
</s:iterator>

As Jagan said, assume that map is java.util.List
<s:iterator value="map" status="stat">
<s:textarea value="%{top}" />
</s:iterator>
or
<s:iterator value="map" status="stat">
<s:textarea>
<s:param name="value">
<s:property/>
</s:param>
</s:textarea>
</s:iterator>
or
<s:iterator value="map" status="stat">
<s:textarea>
<s:param name="value">
${top}
</s:param>
</s:textarea>
</s:iterator>
#Jagan : if it is map how to do this ?
Assume map is java.util.Map
<s:iterator value="map" status="stat">
<s:textarea value="%{key}" />
<!-- or -->
<s:textarea value="%{value}" />
</s:iterator>
IteratorComponent
if (value == null && begin == null && end == null) {
value = "top";
}
top is not a attribute of iterator and not a keyword of OGNL. (I may be wrong)
top : top of Stack / element of the current iteration
e.g.
<s:property value="top" />
or
<s:property value="[0].top" />
Iterator tag examples of Struts2 Cookbook have better explanation

Related

how can i get last element iterator struts2

I'm looking for ideas to show only last element of iterator using struts 2
i have this code :
<s:iterator value="listuser" status="userStatus">
<tr class="<s:if test="#userStatus.odd == true ">odd</s:if><s:else>even</s:else>">
<td><s:property value="nameuser" /></td>
// and others
</s:iterator>
The Struts2 Iterator Status not only provide odd and even methods, it provides also a last and first method.
<s:iterator value="listuser" status="userStatus">
<s:if test="#userStatus.last == true ">
<td><s:property value="nameuser" /></td>
</s:if>
</s:iterator>
Something like this will do the trick :
<s:if test="#userStatus.index==listuser.size()-1">
//Show the last element here
</s:if>
[UPDATE]
As per Quaternion's comment, here's how to get it in one line :
<s:set name="lastUser" value="listuser[listuser.size()-1]"/>
Above we set the last element in lastUser and here's how to use it else-where in the same page.
<s:property value="#lastUser.name"/>

struts2 TreeMap: keys with spaces not appearing in action

JSP Code:
<s:iterator value="#currentRequisitionGroup.plFldWrap.allPFields" var="pMap" status="hStatus">
<s:iterator value="#pMap.value.paramMdlList" var="paramModel" status="fStat">
<li>
<label>
<s:property value="#paramModel.parameterName" />
</label>
<s:set var="cEdit" value="%{#paramModel.isEditable}"> </s:set>
<s:if test="%{#cEdit == true}">
<s:textfield id="paramId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[% {#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].prmValue"/>
</s:if>
<s:else>
<s:textfield id="paramId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[% {#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].prmValue" readonly="true"/>
</s:else>
</li>
<s:hidden id="prmId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].parameterId"></s:hidden>
<s:hidden id="paramName_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].parameterName"></s:hidden>
<s:hidden id="pGId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].parameterGroupId"></s:hidden>
<s:hidden id="seqNo_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].sequenceNumber"></s:hidden>
</s:iterator>
</s:iterator>
The problem is that some values do not appear in action.
Investigation till now indicates that, if the corresponding html input has space in the key of allPFields, that value doesn't appear in action.
<input id="prmId_30" type="hidden" value="30"
name="rqPGPrmMdl.rqGrp[1].plFldWrap.allPFields['Emp System'].paramMdlList[0].parameterId">
However, if the corresponding html input has no space in the key of allPFields, that value appears in action.
<input id="prmId_46" type="hidden" value="30" name="rqPGPrmMdl.rqGrp[1].plFldWrap.allPFields['Emp'].paramMdlList[0].parameterId">
Here is what the logs say:
xwork2.interceptor.ParametersInterceptor - Parameter [rqPGPrmMdl.rqGrp[1].plFldWrap.allPFields['Emp System'].paramMdlList[0].parameterId] **didn't match acceptedPattern pattern!**
This is happening because white spaces are not accepted in parameter names. You can change acceptParamNames parameter of the ParametersInterceptor, BUT as the documentation states
acceptParamNames - a comma delimited list of regular expressions to describe a whitelist of accepted parameter names. Don't change the default unless you know what you are doing in terms of security implications
So I suggest you to get rid of white spaces in parameters names.

Increment a variable in struts2

Is it possible to increment a variable in struts 2?
I have a group of check boxes, each checkbox comes under different group. And I name the check boxes based on the group id and its own id from the database
//namesHead : list contains all the group Ids and names
//subHead : list contains all the subgroups id,Name and the reference of main group
<s:iterator status="status" value="namesHead">
<input type="checkbox" onclick="selectSimilarSubGroup('<s:property value="%{id}" />')" />Select All
<s:set name="itrVar" value="1"></s:set>
<s:iterator status="status1" value="subHead" >
<s:set name="var1" value="%{refer_id}"></s:set>
<s:set name="var2" value="%{id}"></s:set>
<s:if test="%{#var1==#var2}">
<s:set name="itrVar" value="%{#status1.count}"></s:set>
<input type="checkbox" multiple id="chk_grp<s:property value="%{id}"/>_<s:property value="%{#status1.count}" />" name="chk_grp" value="<s:property value="%{id_grp}"/>" />
<s:property value="%{name_grp}"/>
</s:if>
</s:iterator>
<s:hidden name="grp_count_%{id}" value="%{#itrVar}" />
</s:iterator>
I think its because the iterator is skipping the initial counts in the second loop. How can i modify the code to get that expected output. Or is there any way to increment a variable inside the page itself?
Mmm... sub-iterator status should reset on every iteration of the parent iterator, with both "two separate lists" or "a list inside another list"...
Something is messing up the counter. Try removing the <s:set line inside the <s:if, just for debugging, and ignoring the <s:hidden for now:
<s:iterator status="status" value="namesHead">
<input type="checkbox" onclick="selectSimilarSubGroup('<s:property value="%{id}" />')" />Select All
<s:set name="itrVar" value="1"></s:set>
<s:iterator status="status1" value="subHead" >
<s:set name="var1" value="%{refer_id}"></s:set>
<s:set name="var2" value="%{id}"></s:set>
<s:if test="%{#var1==#var2}">
<!-- Nothing here -->
<input type="checkbox" multiple id="chk_grp<s:property value="%{id}"/>_<s:property value="%{#status1.count}" />" name="chk_grp" value="<s:property value="%{id_grp}"/>" />
<s:property value="%{name_grp}"/>
</s:if>
</s:iterator>
<!-- Nothing here -->
</s:iterator>
What do you see ?

Date comparision in struts2 using OGNL

enter code hereIn my JSP I have display a hyperlink depending upon the date field if it falls between certain range. I am using struts 2 and ONGL
<s:set name="cDate" value="accDate"/>
<s:if test="%{#cDate gt '4/4/11' && #cDate gt '4/4/12}">
<td class="viewCellLast"><s:url id="editURL" action="editActivities">
<s:param name="id" value="%{id}"></s:param>
</s:url> <s:a href="%{editURL}" onclick="return nanCompany();" >Edit</s:a></td>
</s:if>
its failing, can anybody suggest the me how this can achieved.
thanks
smitha.
I got it resolved; I missed # in front fsDate:
<s:set name="fsDate" value="finStartDate"/>
<s:if test="%{#acDate.before(#fsDate}">
<td class="viewCellLast"><s:url id="editURL" action="editActivities">
<s:param name="id" value="%{id}"></s:param>
</s:url> <s:a href="%{editURL}" >Edit</s:a> </td>
</s:if>

How To Generate unique HTML id attributes within Struts 2 iterator tag

I need to generate unique id attributes within the struts iterator on the lines of
<div id="divId1"/>
<div id="divId2"/>
etc, etc.
I've tried
<s:iterator value="myListFunction" status="#status">
<s:set var="uniqueId" value="divId#status.count/>
<s:div id="%{uniqueId}/>
</s:iterator>
and variations of the above, but nothing seems to work. Could someone point me in the
right direction please
Try this:
<s:iterator value="myListFunction" status="status">
<s:div id="divId%{#status.count}/>
</s:iterator>
Did you try (not tested):
<s:iterator value="myListFunction" status="status">
<s:div id='%{"divId" + #status.count}'/>
</s:iterator>

Resources