This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes This has to be easy! Arraylist? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "This has to be easy! Arraylist?" Watch "This has to be easy! Arraylist?" New topic
Author

This has to be easy! Arraylist?

Mike Blair
Greenhorn

Joined: Sep 10, 2003
Posts: 19
Ok, I have a form bean that represents the jsp form. The jsp form has a table that is built using the iterate tag and iterating through an array list of a bean. So far so good, the data displays fine. Now, how do I reverse it? I want to be able to get at this "list" that is present on the jsp page IN my action class. Here is some of the code basics.
If this isnt clear enough, please ask questions and I will try to explain. In a nutshell I want to get the value of a table out of a jsp page and into my action
Mike
public class AwardMasResultsForm extends ActionForm {
// The search field
private ArrayList awards; //this is put into the jsp iterate loop
public void setAwards(ArrayList awdList) {
this.awards = awdList;
}

public ArrayList getAwards() {
return this.awards;
}
public ActionForward filter( ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
AwardSearchService service = new AwardSearchService();
ArrayList awards = service.getAwardMasView( awardCodeView.getAwdCode() );
//I put the list into the form
((AwardMasResultsForm)form).setAwards(awards);
}
now in an effort to get the value back out I have ...
public class CrudAwardsAction extends Action {
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
//I want to get the values from the jsp page here
ArrayList awards = ((AwardMasResultsForm)form).getAwards();
Iterator i = awards.iterator(); //
while (i.hasNext()) {
AwardMasView awardmas = (AwardMasView)i.next();
System.out.println(awardmas.getSafAwardCode());
}
Bernardus Irmanto
Greenhorn

Joined: Oct 03, 2003
Posts: 23
Mike,
U should have 2 additional methods in order to get the multi-lines data from your jsp.
In your form bean, you have awards Arraylist. Say that in the arraylist you have award object(bean).
You need to add the following method in your form bean
public void setAward(int index, award ob){
awards.set(index, ob)
}
public award getAward(int index){
awards.get(index)
}
this should work...

rgds
beN
Mike Blair
Greenhorn

Joined: Sep 10, 2003
Posts: 19
Thanks for the quick reply!
I took the lines you gave me and modified them as so to get it to compile clean.
public void setAward(int index, AwardMasView ob){
this.awards.set(index, ob);
}
public AwardMasView getAward(int index){
return (AwardMasView)this.awards.get(index);
}
Now in my action code I get the the list back using this code (which does not work) ... this code produces a NullPointerException
//I want to get the values from the jsp page here
ArrayList awards = ((AwardMasResultsForm)form).getAwards();
Iterator i = awards.iterator(); //
while (i.hasNext()) {
AwardMasView awardmas = (AwardMasView)i.next();
System.out.println(awardmas.getSafAwardCode());
}
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Mike, please post the logic:iterate block from your JSP.
What you need to do is to set up your JSP so that you are mapping each cell to an indexed or mapped property in your ActionForm.


Junilu - [How to Ask Questions] [How to Answer Questions]
Mike Blair
Greenhorn

Joined: Sep 10, 2003
Posts: 19
Thanks! Here is my logic:iterate tag beginning and a few rows within the tag. I will take a look at this link you posted!
<logic:iterate name="awardMasResultsForm" property="awards"
id="AwardMasView">
.
.
<TD VALIGN="MIDDLE" ALIGN="LEFT" class="cell">
<bean:write name="AwardMasView" property="safAwdNameShort"/>
</TD>
<TD VALIGN="MIDDLE" ALIGN="CENTER" class="cell">
<html:checkbox name="AwardMasView" property="deleteRecord"
value="delete" indexed="true"/>
</TD>
 
wood burning stoves
 
subject: This has to be easy! Arraylist?
 
Similar Threads
Retrieving Form Updates
Performance Issue
Error: DispatchMapping[/login] does not define a handler property
This has to be easy!!! Part II
how do you display the struts forward to jsp