Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
kannan ind
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic