<s:property value="results" />where s is an alias for struts-tags tag library and results is a Collection (can be anything) that we've populated in execute method. Note here that it must be a variable/property in you action handler class with both of its getter and setter methods available. The property tag will call the getResults() getter method.
This is clean. But it should be noted that results is not available in the pageContext of the page being processed currently. So, for example, if you want to use the results collection inside a jsp scriptlet by doing something like
pageContext.getAttribute("results")this will not work. You cannot even say something like
request.getAttribute("results")Anyways, it's possible and pretty clean too :) All you've to do is to set the pageContext attribute by using another struts tag,
<s:set name="pageResults" value="%{results}" />This is equivalent to
pageContext.setAttribute("pageResults",results)but the later won't work. The name is what you want to name the results in the pageContext, like a variable name; and the value is its value. So here, Set tag will call getResults() and assign the returned value to a pageContext variable called pageResults.
That's it :)
6 comments:
Sure Andrew, thanks!
Excellent blog. Got clear answer
nice blog good article ...
awesome....thanks for the tip...neatly explained..:-)
Hi..am trying same thing...till it is not working for me...any suggestion????
Would you be inquisitive about exchanging links? play casino
Post a Comment