I am using strut2 in my project in which in jsp pages i have to show list of items greater than 500. I have used following tags.
<s:iterator value="list" status="status" >
<s:property value="%{val1}" />
<s:property value="%{val2}" />
<s:property value="%{val3}" />
<s:property value="%{map[val]}" />
</s:iterator>
when the list size is large, it iterates very slowly. while iterating, i am also retrieving values from maps.
I am not able to find what is exactly happening . what should i do to iterate fast or improve performance of iterator.
Thanks
you are using very old version of Struts2(2.0.1) and in that case might be using old version of OGNL which was having really some bad performance issues.
Suggest you to first go through some performance tips.
performance-tuning
next step is to manually update the version of ognl you're using in your own
app in that case you might have to add javassist jar.
Go through the Struts2 mailing list discussion thread for similar issue.
Slow-performance-with-Struts2
Related
I am trying to iterate over the textfield's value, for eg. 5. Is there a way to get the value?
I have a textfield with value 5:
<s:textfield
theme="simple"
cssClass="form-control"
name="instCount"
value="5"
style="width:25%;"
onkeyup="javascript:isNumber(this);"
/>
I need to iterate the value 5:
<s:if test='<s:property value="%{instCount}"/> > 0'>
<s:iterator value='<s:property value="%{instCount}"/>' var="count" status="countStatus">
</s:iterator>
</s:if>
You cannot nest JSP tags like that, and it appears that you haven't wrapped your head around OGNL or ELs in general, even though you use it correctly in the <s:property> tag.
Let's take a step back: what is this doing?
<s:property value="%{instCount}" />
It's referring to an action property named instCount.
How? Via the OGNL expression %{instCount}.
How does the <s:if> tag work? By evaluating an OGNL expression in the test property. Ah, OGNL expression, which we've already seen.
<s:if test='instCount > 0'>
How does the <s:iterator> tag work? By evaluating an OGNL expression in the value tag.
<s:iterator value='%{instCount}' etc...>
I would highly recommend taking some time to figure out the framework you're working in, even a minor reading of the documentation (and a basic understanding of how JSP works) will be highly beneficial, and avoid questions like this.
I'm am still pretty new to struts and am having trouble trying to compare two struts params in a struts if statement. I am trying find if the current year param is equal to the checkYear param
If they are equal I want to execute some code. If they are not equal then I would like to execute some other code..
Sample code:
<s:param name="currentYear">
<s:date name="%{new java.util.Date()}" format="yyyy" />
</s:param>
<s:param name="checkYear">
<s:date format="yyyy" name="#year"/>
</s:param>
<s:if test="${checkYear == legendYear}">
code executed
</s:if>
I don't really understand the purpose of the '$','%', or '{}' in the test part of the if statement if or how I need to apply it to have it check the params.
Thank you in advance!
Inside Struts2 tags, you use OGNL. Refer to the small language guide to see how it works.
In OGNL, %{} means you want to force the evaluation of an expression; it is needed somewhere, while it is superfluos somewhere else. In the <s:if/>, it is not needed, because test="" will evaluate its content by default.
${} does not exists in OGNL, it is JSP EL. Search on StackOverflow for some nice answer on that if you are curious.
{} alone in OGNL is List Projection... you probably don't need it now.
I have a list named projectList. I have dealt with the first 3 elements in the list in a different way, then I want to iterate the projectList from index=3 to the end.
How should I achieve this?
Either the solution with pure struts tags or a solution mixed with Javascript would be good.
I think this is what you need:
<s:iterator value="projectList" status="itstatus">
<s:if test="#itstatus.index > 3">
<!-- YOUR CODE -->
</s:if>
<s:else>
<!-- YOUR CODE -->
</s:else>
</s:iterator>
I can't test it right now, so maybe it has some errors. Good Luck!
What I would like to achieve is to be able to address some JSF components from within other naming container.
Usecase: composite component which encapsulates some features using - for a field which is defined out of the composite component.
Some code:
<form id="foo">
...
<label for="nameTxt">Name:</label>
<component:customError forField="nameTxt" />
<h:inputText id="nameTxt" />
...
</form>
and the component:
<composite:implementation>
<h:panelGroup id="errorComponent">
...
<h:message for="#{cc.attrs.forField}" id="errorMsg" style="display:none;" />
...
</h:panelGroup>
</composite:implementation>
The problem is that on rendering the message I get:
Could not render Message. Unable to find component 'nameTxt' (calling findComponent on component 'j_id963445801_469fc056:errorMsg')
I think I understand that the problem lies in the fact the the field "nameTxt" and the message "errorMsg" lie in other naming-containers. So what I would have and like to do is to specify the path/id of "nameTxt" in relation to some common ancestor.
After studying shortly the algorithm UIComponentBase:findComponent I do not actually see any other way of adressing cross naming-containers than by specyfing whole (absolute) id-path from the root (i.e. ":foo:...:nameTxt"). And this is both clumsy and prone for errors after changing the page structure.
So - how to address properly the field "nameTxt" from within the message in the composite component?
I can reproduce your problem on MyFaces 2.1.3, but not on Mojarra 2.1.4 (and also not on older Mojarra 2.0.2). This is likely a bug in MyFaces, you'd need to report it to the MyFaces guys. In the meanwhile, I don't see any other option than (temporarily) replacing the JSF implementation by Mojarra. It has however its own share of issues as well, mainly with its broken <ui:repeat> and partial state saving implementations.
Update: I found a workaround, it's however a bit clumsy:
<component:customError forField=":#{nameTxt.clientId}" />
<h:inputText id="nameTxt" binding="#{nameTxt}" />
This will lookup using the absolute client ID instead of relative client ID. You'd only need to remove style="display:none" from your <h:message> to solve a different matter.
Is there a way to update UI elements asynchronously in JSF 2?
For example a person is looking on the screen and some pieces on the screen get updated, when say a batch job changes some value.
There are a couple of solutions. One is e.g. a4j:push, which is further described here.
IceFaces is also known for this. Note that some of the components essentially do polling via AJAX, while others actually use reverse ajax/comet.
You can also use the <p:poll> provided by PrimeFaces.
Here is a working example:
<h:form>
<h:outputText id="txt_count" value="#{counterView.number}" />
<p:poll interval="3" listener="#{counterView.increment}" update="txt_count" />
</h:form>