Hello I am a young Software developer,
and I struggled the last 5 days with my code.
Here is my code in JSP:
<s:iterator value="getListeDanach()" status="stat">
<li>
<s:url id="URL_ListeDanach" action="uebersicht_umblaettern">
<s:param name="angeklickteSeitenzahl" value="getListeDanach()[#stat.index]" />
<s:bean name="org.apache.struts2.util.Counter" var="counter">
<s:param name="last" value="3" />
</s:bean>
<s:iterator value="#counter" status="stat1">
<s:property value="#stat1.index" />
<s:param name="%{optionaleParamName4}" value="#optionaleParamValue4" />
</s:iterator>
</s:url>
<s:a href="%{URL_ListeDanach}" cssClass="naviTab">
<s:property value="getListeDanach()[#stat.index]" />
</s:a>
</li>
</s:iterator>
My problem is, the first Iteration works great but the 2nd Iteration works half. In the 2nd case the property works, but the param doesn´t work! Al Variables are available. If i take the param Tag of the 2nd Iteration and place it in the first, it works great! But that isn´t what I want.
This is not an answer.
Here's the JSP, cleaned up, and using more S2 functionality. It was impossible to read the original.
<s:iterator value="listeDanach" status="stat" var="outerItem">
<li>
<s:url id="URL_ListeDanach" action="child">
<s:param name="angeklickteSeitenzahl" value="outerItem" />
<%-- What are you trying to do here? --%>
<s:bean name="org.apache.struts2.util.Counter" var="counter">
<s:param name="last" value="3" />
</s:bean>
<%-- What are you trying to do here? There's nothing to iterate over. --%>
<s:iterator value="#counter" status="stat1">
<s:property value="#stat1.index" />
<s:param name="%{optionaleParamName4}" value="#optionaleParamValue4" />
</s:iterator>
</s:url>
<s:a href="%{URL_ListeDanach}">
<s:property value="outerItem" />
</s:a>
</li>
</s:iterator>
In the bean i have a loop with 3 "rounds", in the 2nd iterator i use the var=counter to iterate three times over the property and over the dynamic parameter.
The property shows in HTMl in every loop of the first iterator this result : 0 1 2;
This is how it should work(the property is just there, to test the functionality of the 2nd itarator.)
But in the 2nd case, the parameter-Tag is fully ignored or something like that. For those who want to know the logic behind the code. It is a side navigation bar. listeDav or = list behind the actual number, and listeDanach= list after the actual number. 1 2 3 4 [5] 6 7 8 9.... When the param Tag in the 2nd itarator functions well, I would make the param tag dynamically with the iterated index.
SO in short, what I want is: Every time the first Iterator has his loop, I want to create dynamic parameters. This parameters are defined in the JSP before and are fully supported! I want to use the index "#stat1.index" to make it work.
Something like this :
s:param name="%{optionaleParamName[#stat1.index]}" value="#optionaleParamValue[#stat1.index]" />.....
i have already defined the String behind "#optionaleParamValue[0], behind #optionaleParamValue[1] and behind #optionaleParamValue[2] and soo on... ... and all this is for reusing the actual JSP.
As you can mention, a side navigation bar, can be used in many other cases in the programm.
Greetings
Related
First things first, I'm not a seasoned Struts user. Here is my struts code:
<s:set var="foo" value="BAR">
<s:text name="key.for.foo">
<s:param><s:property value="foo" /></s:param>
</s:text>
Here is the properties file containing the key.for.foo text value:
key.for.foo=blah blah {0}
I expect the text below:
blah blah BAR
but I get
blah blah
What am I missing ?
You can try the below code
<s:text name="key.for.foo"><s:param value="#foo"/></s:text>
The usage of <s:set /> vars is covered in the tag documentation's example:
<s:set var="personName" value="person.name"/>
Hello, <s:property value="#personName"/>
Nutshell is that the Value Stack has multiple ways of looking things up: stuff pushed onto the stack (e.g., the action itself, <s:push /> properties), stuff in the servlet context (e.g., session and request attributes/properties), and named objects (e.g., <s:set /> objects, <s:iterator /> status value).
I know how to use <s:iterator> to make a list of hyperlinks with the following code:
<s:iterator value="imagesList">
<s:url var="linkReport" action="view" namespace="/">
<s:param name="documentId" value="%{documentId}"></s:param>
</s:url>
<s:a href="%{linkReport}" target="_blank"><s:property value="%{documentName}"/></s:a><br>
</s:iterator>
I know how to use <s:iterator> with the <s:radio> tag to make a vertical list of radio buttons as follows:
<s:iterator value="imagesList">
<s:radio name="mainId" listValue="documentName" list="{myObject}" listKey="documentId" ></s:radio><br>
</s:iterator>
What I would like to do is combine the two pieces of code and make the listValue in the <s:radio> tab into the hyperlinks in the first piece of code. The following doesn't work but it shows what I want to do.
<s:iterator value="imagesList">
<s:radio name="mainId" listValue="<s:a href="%{linkReport}" target="_blank"><s:property value="%{documentName}"/></s:a>" list="{myObject}" listKey="documentId" ></s:radio><br>
</s:iterator>
<c:set var="xmlDocumentId" value="${id}" scope="request" />
<s:set var="xmlDocumentId" value="%{id}" scope="request" />
are formatting id based on locale, setting xmlDocumentId to "12,345" while:
<c:out value="${id}" />
<s:property value="%{id}" />
are outputting "12345".
Any ideas how to break this behavior?
Because you are getting value with getText or <s:text> tag your long value gets formatted according to locale. To prevent this from happening convert your long to string.
With <s:set> tag you can call toString() method directly in value attribute.
<s:set var="xmlDocumentId" value="id.toString()" scope="request" />
For the concrete formatting algorithm take a look at java.text.MessageFormat class and its subformat method.
Once you know how to format numbers in Java, in Struts2 <s:property/> tag you can use getText() to format your number in the desired way, for example :
<s:property value="getText('{0,number,#,##0}',{id})"/>
Try this
<s:text name="id" > <s:param name="value" value="id"/> </s:text>
<s:iterator value="podTemplate.subTypeTemplates" status="subTemplate">
<s:textfield id='subType_type_#subTemplate.index' key="subType" label="Name"/>
</s:iterator>
#subTemplate.index is not getting replaced by index. However if I am doing
<s:property value="#subTemplate.index"> is working
That's because id attribute of textfield is of string type and string-type attributes are not interpreted as OGNL by default. As Steven said you have to force the interpretation by using %{} in your case subType_type_%{#subTemplate.index}.
My iterator looks like this:
<s:iterator id="list" value="optionList" status="rowStatus" >
I tried:
<td>
<input class="textInput required"type="text" name="optionList[${rowStatus.index}].option_id"/>
</td>
and it's the only one that worked.
All the following ones failed:
name="optionList[%{#rowStatus.index}].option_id"
name="%{optionList[#rowStatus.index].option_id}"
even
name="%{#rowStatus.index}"
I have an iterate and i want to calculate sum of the values like this :
<s:iterator value="myValues" status="myStatus">
<s:property value="value" />
</s:iterator>
<s:property value="total.here" />
I want to show the sum of "value" in "total.here".
Sorry for my bad english.
Thank you very much.
Assuming myValues is an array or a list of integral values accessible from your action:
<s:set var="total" value="%{0}" />
<s:iterator value="myValues">
<s:set var="total" value="%{top + #attr.total}" />
</s:iterator>
<s:property value="%{'' + #attr.total}" />
Samuel_xL's answer is right. But, in general, if you can edit your action class, I'd advice to make the calculation there instead of doing it in jsp.