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.
Related
I am able to print value from Java Action Class to JSP Page without textbox, But when I want to put that value in a TextBox in JSP, its not coming.
My Code is :
<S:form>
<s:textfield name="toDate" key="td" > <s:property value="fromDate"/> </s:textfield>
<s:textfield name="fromDate" key="fd"> <s:property value="toDate" /> </s:textfield>
<s:submit value="Confirm"></s:submit>
</s:form>
toDate and fromDate is variables in Java Class.
Just dive in the Struts2 UI Tag documentation:
key : Set the key (name, value, label) for this particular component
If you want them different (eg. toDate the value to set, td the value to read, and so on), specify all of them:
<s:form>
<s:textfield name="toDate" value="td" label="To date" />
<s:textfield name="fromDate" value="fd" label="From date" />
<s:submit value="Confirm" />
</s:form>
(Obviously according to your getters and setters).
You can set value in TextBox using value attribute of <s:textfield> tag to value come from action class.
For this you have your getter and setter method for that variable in action class and read that value by below code:
For Example :
<s:textfield name="some_name" value="%{variable}"/>
your code look like this:
<s:form>
<s:textfield name="toDate" value="%{fromDate}" />
<s:textfield name="fromDate" value="%{toDate}" />
<s:submit value="Confirm" />
</s:form>
<display:table export="true" id="data" name="${sessionScope.forbesList}"requestURI="">
<a href="#" rel="tooltip" content="<span>
Name:<s:property value="#data.rank" /><br/>
Email: <a><s:property value="#data.name" /></a><br/>
Phone:<s:property value="#data.age" /> </span>"> <display:column property="rank" title="Rank" sortable="true" /></a>
<display:column property="name" title="Name" sortable="true" />
<display:column property="age" title="Age" sortable="true" />
</display:table>
In Struts 2 I'm trying to use <s:property> tag inside <display :column> tag but I can only see the <display:column> values and not the values that I access with <s:property>. How to do it?
#1: Anchor (<A>) Tag does not have any content attribute.
Please refer to the documentation to see which attributes it supports and how to use them.
#2: in HTML, when putting the character " into an attribute of a Tag, you can:
substitute " with ', like in
myAttribute="this is 'right'" or
myAttribute='this is "right" too', or
encode the " with the html entity ", like in
myAttribute="this is "right""
You must encode the < and > too, with < (Less Than) or > (Greater Than).
#3: that said, you could put your HTML inside the Anchor Tag, in the place where it is supposed to be inserted, like :
<a href="#" rel="tooltip">
Name:<s:property value="#data.rank" />
</a>
but, in your case, you are injecting a lot of HTML, including another Anchor, that is not possible. I think you should simply use a div or something similar as a container, like:
<div rel="tooltip" >
<span>
Name:<s:property value="#data.rank" /><br/>
Email: <a><s:property value="#data.name" /></a><br/>
Phone:<s:property value="#data.age" />
</span>
</div>
Resolve this before worrying about DisplayTag
EDIT
#4
Change
<s:property value="#data.rank" />
(and all the other tags) to
<s:property value="#attr.data.rank" />
#attr is the OGNL used to access the pageContext,
if it is available, otherwise it searches request, session and application scopes.
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 ?
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
In my Struts2 application I am generating a textual report (in jsp) using iterator tag like
<table>
<tr>
<td>ID</td>
<td>PROOF</td>
<td>DELETE</td>
</tr>
<s:iterator value="listOfVOClassObjects">
<tr>
<td><s:property value="requestId" /></td>
<td><s:property value="requestChecker" /></td>
<td><s:property value="requestProof" /></td>
<td><s:checkbox name="deleteStatus" onclick="submit()"/></td>
</tr>
</s:iterator>
</table>
When user click checkbox page submits and control goes to action class and I need at the same time values of the corresponding row that user has checked should set in setter methods written in VO class so that I can get all these values in my action class.
I tried this by writing a hidden field for every value under iterator tag like
<s:hidden name=" requestId" />
<s:hidden name=" requestChecker" />
<s:hidden name=" requestProof" />
but its not returning the values of corresponding row but the values of all rows separated by commas.
I also tried this by writing these hidden fields outside the iterator tag and that is returning null for every filed.
Please help.
You could update the submit() method to get the correct values and pass them to the action.
In your javascript function, you would set the current values then submit. So you'd have something like this:
<form method="post" action="myAction">
<script>
function submitform(requestId, requestChecker, requestProof) {
document.findElementById('requestId').value = requestId;
document.findElementById('requestChecker').value = requestChecker;
document.findElementById('requestProof').value = requestProof;
document.forms[0].submit();
}
</script>
<s:hidden id="requestId" name="requestId" />
<s:hidden id="requestChecker" name="requestChecker" />
<s:hidden id="requestProof" name="requestProof" />
<table>
<tr>
<td>ID</td>
<td>PROOF</td>
<td>DELETE</td>
</tr>
<s:iterator value="listOfVOClassObjects">
<tr>
<td><s:property value="requestId" /></td>
<td><s:property value="requestChecker" /></td>
<td><s:property value="requestProof" /></td>
<td><s:checkbox name="deleteStatus" onclick="submitForm('<s:property value="requestId" />', '<s:property value="requestChecker" />', '<s:property value="requestProof" />');"/></td>
</tr>
</s:iterator>
</table>
</form>
It depends on what you are doing. If you can recreate the List on the server side then all you need to do is POST the index of the list that you want to get a handle on. For example:
<s:iterator value="myList" status="row">
...
<s:checkbox onclick="deleteRow(%{#row.index})"/>
</s:iterator>
<script>
function deleteRow(index){
location.href=delete?listIndex=index
}
</script>
You would have a setter for listIndex to "receive" the value. This is using a GET, if you want a POST you can do that and make the listIndex a hidden field.
BUT, if you can't recreate the list on the server because the user has modified the list somehow in the browser and you need to preserve that, then you need Struts2 to create the list based on the POST'd parameters. You do that with some special syntax.
<s:iterator value="myList" status="row">
<s:hidden name="myList[%{#row.index}].requestId"/>
<s:hidden name="myList[%{#row.index}].requestChecker"/>
<s:hidden name="myList[%{#row.index}].requestProof"/>
</s:iterator>
This creates fields with names like myList[0].requestId ... myList[5].requestProof. If you have a setter for myList in your action and you POST these parameters to the action, Struts2 will build the List and populate the properties of the objects in the List. You can use Generics List myList to tell Struts2 what kinds of "things" are in your List. You can also look at Type Conversion documentation for Struts2 if Generics doesn't work for you.