• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Struts2 nested iterators with listboxes

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am stumped with this problem that I have. Any pointers to the solution or related documentation would be greatly appreciated.

My JSP has nested iterators, and the deepest one has a listbox, like so:


The generated source code looks like this:



And it seems to look alright to me. But submit causes a problem because it is not able to find a setter. I am not exactly sure where or how I would write this setter. I have a setter/getter for ProductBOs in the action class. The ProductBO class has a setter for the attributeBOs. What else do I need?

Thanks !

[ December 21, 2008: Message edited by: Casey Cox ]
[ December 21, 2008: Message edited by: Casey Cox ]
 
Casey Cox
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it seems like I had to declare my object as an Arraylist in the Action, like so:
ArrayList productBOs;
instead of
ProductBO[] productBOs;

So, now I am able to submit the jsp without running into an exception, but I don't get the values in my action.

I can see the setter being called, but the argument is always non null and empty!!


This is how the jsp looks like:


Help, anyone!
[ December 25, 2008: Message edited by: Casey Cox ]
 
Casey Cox
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I found a way to get my stuff to work. I made my action implement ParameterAware and the jsp values are now available in the map. I am not sure if this is the correct way to do it, but it does seem to fulfil my needs, in a somewhat roundabout way.

I have been working on this for almost 2 days, and even though I have a possible solution in hand, I don't feel any relief, only a vague sense of anti-climax..
 
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Cox Help me dude....I got stuck with the same issue....please help....its urgent....
How did you used parameteraware interface...can you post the code please.
 
Nitin Surana
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I Got the Solution:

This is how the JSP code will look like:

<s:form action="saveaction" >
<s:iterator value="lstBean" id="lstBean" status="outerStat">
<s:textfield value="%{name}" name="lstBean[%{#outerStat.index}].name"/>
<s:textfield value="%{amt}" name="lstBean[%{#outerStat.index}].amt"/>
<s:textfield value="%{id}" name="lstBean[%{#outerStat.index}].id"/>
<s:iterator value="%{lstString}" status="myStat">
<s:textfield name="lstBean[%{#outerStat.index}].lstString[%{#myStat.index}]"/>
</s:iterator>
</s:iterator>
<s:submit value="Click me to submit lstBean"/>
</s:form>


Following is the bean(XBean) whose List is used in the JSP:

public class XBean
{
private ArrayList<String> lstString=new ArrayList<String>();
private String name;
private Double amt;
private Integer id;
//Getters and setters of fields
}

Now you can simply have a field lstBean with setters in your submitting action (saveaction) and hey you are done.
 
Nitin Surana
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how the JSP code will look like:



Following is the bean(XBean) whose List is used in the JSP:


Now you can simply have a field lstBean with setters in your submitting action (saveaction) and hey you are done.
 
Ranch Hand
Posts: 87
Hibernate Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nitin,

i have followed your code but still i am not getting value, here is what i wrote

<s:iterator value="activityList" id="myact" status="activityStatus">

<s:iterator value="%{favorites}" status="myStat">
<s:checkbox name="myact[%{#activityStatus.index}].favorites[%{#myStat.index}].accFavorities"/>
</s:iterator>

But check box is not getting displayed.

Is there any other way it could be done. I am using one-to=many relationship between activity and favorites.

thanks
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic