user1986296
user1986296

Reputation: 31

Dynamically Creating list in Struts2 using tags

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(2012);
list.add(2013);
list.add(2014);
list.add(2015);

can we do same as above using struts2 tags. may be by using

<s:set name="myList" value={somedynamic values} />

actually I want to create a list of number of 10 years on JSP page using Struts2 tags.

Upvotes: 3

Views: 5885

Answers (2)

Raki
Raki

Reputation: 361

Regarding to your question answer is yes,but that is not an good idea to create number of 10 years in jsp page.

However, this is using arrylist in dynamic way      

<s:select label="Years" headerKey="-1" headerValue="Select Years" list="list"   name="your desire name" />

in the place of list property you have to give arrayList variable in your case it is list means,

<s:select ---- list="your array list variable" --------- />

     and you have to define this action name in struts.xml    eg:

<action name="yourarrylistvariable" class="your class" method="your method">
           <result name="success">your jsp page</result>
</action>

          This is using arrylist in static way here you have to change the list value 

<s:select label="Years" headerKey="-1" headerValue="Select Years" 
list="#{'2000':'2000', '2013':'2013',.....}" name="your desire name" />

For More Info You can refer this link struts2 select

Upvotes: 3

Aleksandr M
Aleksandr M

Reputation: 24406

Sure you can, thanks to the OGNL you can create lists like so:

<s:set var="myList" value="{2012,2013,2014,2015}" />

See this link.

Upvotes: 1

Related Questions