aspose file tools*
The moose likes Struts and the fly likes Struts 2 : passing collection(list,map..) in s:param tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 : passing collection(list,map..) in s:param tag" Watch "Struts 2 : passing collection(list,map..) in s:param tag" New topic
Author

Struts 2 : passing collection(list,map..) in s:param tag

kannan ind
Greenhorn

Joined: Apr 05, 2010
Posts: 5
Hi,

i need to pass map/list as param along with s:action tag so that i can dynamically change the content of resulting jsp page
some thing like this

main.jsp
--------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 5.0//EN">
<%@ page language="java" isELIgnored="false" %>
<%@ taglib uri="/WEB-INF/struts-tags.tld" prefix="s" %>
<!-- Include Header -->
<s:include value = "/pages/reports/partials/header.jsp"/>
<!--End of Include Header -->
<s:action name="Pk1Action" namespace="/Pk1" executeResult="true" >
<s:param name="selectedValues" value="%{#{'1':'Jan','2':'Feb','3':'Mar'}}"/>
</s:action>
<s:action name="Pk2Action" namespace="/Pk1" executeResult="true" >
<s:param name="selectedValues" value="%{{'1','2'}}"/>
</s:action>
<s:action name="Pk1Action" namespace="/Pk1" executeResult="true" >
<s:param name="selectedValues" value="%{#{'1':'Jan1','2':'Feb1'}}"/>
</s:action>
<!-- Include Footer -->
<s:include value = "/pages/reports/partials/footer.jsp"/>
<!--End of Include Footer -->

The resulting page of s:action will generate s:select tag according to the value(map) set by action


Please,Can anyone help ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

You can edit your post by using the button.

Also, please see the JavaRanch naming policy. Please change your display name to conform with this policy. Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd recommend *not* doing this the way you're trying to do: the action tag can introduce some subtle issues that are not worth trying to figure out.

If the values are known in the action itself, just expose them as action properties and access them in the included actions/JSPs.
kannan ind
Greenhorn

Joined: Apr 05, 2010
Posts: 5
Thanks for the reply...

The problem is , i have around 60 such pages (jsp),that includes common pages with different values.

i will try the way you suggested,but the problem is ,i will have to write 60 conditions in the action for loading different values .

thanks once again
kannan ind
Greenhorn

Joined: Apr 05, 2010
Posts: 5
hi

This might be useful to someone lookin to pass collections(ArrayList,Map) to model class (Struts 2).

Not sure whether any other solution is out there ....and i don't believe this is a proper solution

In following sample i need to pass ArrayList<String> called sampleDetailsList to model class.
so,in jsp add a s:select tag like

set the multiple attribute to true and also set the value and list attribute with the arraylist "sampleDetailsList' .
setting both list and value with the same araylist will auto select all the values in select tag(please refer http://struts.apache.org/2.1.6/docs/select.html)

in model class


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 : passing collection(list,map..) in s:param tag
 
Similar Threads
struts 2 design problem
Tiles problem in rendering
Struts2 questions
Struts bug? <s:if> string comparison fail
Errr: requested resource xxxx.action is not available