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>
Related
in Grails 2.3.4 i need to set the value that comes from the datePicker
<g:datePicker name="toDate" precision="day" relativeYears="[0..10]" default="${new Date()}" />
to a variable for instance :
<g:set var="fromDate" />
how can i do that ?
Thanks
You can use the <g:set /> tag to set the variable value, then assign the variable to the datePicker using the value attribute.
<g:set var="fromDate" value="${new Date()}" />
<g:datePicker name="toDate" precision="day" value="${fromDate}" />
Here is the documentation.
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.
I'm using below composite component:
<composite:interface>
<composite:attribute name="inputId" />
</composite:interface>
<composite:implementation>
<h:panelGrid id="myTableId">
<h:inputText id="#{cc.attrs.inputId}" value="..." />
...
</h:panelGrid>
</composite:implementation>
And I'm using it in my form as below:
<h:form id="myForm">
<myCompositeComp:test inputId="myInputTextBoxId" />
<h:form>
I've verified the view source for the page and this is how it is generated:
<table id="myForm:j_idt90:myTableId">
...
<input type="text" id="myForm:j_idt90:myInputTextBoxId" />
</table>
How can I get rid of j_idt90 here? Is it the id of my composite component? I read from one of BalusC post that this issue will get fixed if I declare id as static. But I'm not able to identify the place to declare it in my code. Also can I assume <h:panelGrid> is a kind of UINamingContainer?
Yes it is the id of your composite component, <h:panelGrid> is not a UINaminContainer but the composite component is (it has to be, otherwise you would have duplicate IDs if you use it several times inside the same form for example).
Why do you need to get rid of the ID? You can set it yourself if that solves your problem:
<h:form id="myForm">
<myCompositeComp:test id="myComp" attr1="" attr2="" />
<h:form>
the genereated html should look like this:
<table id="myForm:myComp:myTableId">
....
<input type="text" id="myForm:myComp:myInputTextBoxId"
</table>
<s:iterator value="newIssues">
<s:property value="is.description"/>
<s:property value="is.component"/>
</s:iterator>
<input type="submit" align="bottom" value="Done" id="mysubmit"/>
Now, NewTickets is my action class.This class provided newIssues arraylist to iterate on it..I want the same list to work with when i press submit..how do i do it?
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 ?