• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

This has to be easy! Arraylist?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
}
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
}
 
Sheriff
Posts: 17652
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mike Blair
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic