• 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

Form Params not passed properly

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I'm having an issue passing a form correctly to my action class. I'm afraid I've setup my form incorrectly. The form I am passing is a table of inputs from the user. There will be 2 select boxes and then 4 input text boxes. One row is equal to one LineItem java object with each input an attribute for the lineItem. So my form has an ArrayList of LineItems that I'm trying to pass.

The error I'm receiving is a null pointer when I try to get the list of LineItems off of the form when I submit the page.

First I call an action to initialize my lineItem array to 5 empty items and forward to my jsp to iterate over them for my input table.



The jsp below is the table for the lineItems. When I go to saveLineItems I pull the line items off the form and they are null and I get a NPE. For completeness the MainPageBean is a session bean that holds the list of options for the dropdown boxes. I have also included the html rendered on the page.


upon submitting the form I get a NPE in my saveLineItems Action. Included below is the struts config that is relevant

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Yule wrote:upon submitting the form I get a NPE in my saveLineItems Action. Included below is the struts config that is relevant


Sure be easier if you told us where, so we at least have a place to start looking.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:

Paul Yule wrote:upon submitting the form I get a NPE in my saveLineItems Action. Included below is the struts config that is relevant


Sure be easier if you told us where, so we at least have a place to start looking.



The error I'm receiving is a null pointer when I try to get the list of LineItems off of the form when I submit the page.





lineItems.size() throws NPE.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the names in the form seem to be "line", but the form itself seems to contain "lineItems". I don't remember how BeanUtils works, but right now it doesn't look like there's any real connection between the HTML form and the ActionForm.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm.. ok. Should I try to set the variable of the iterator to lineItems and replace the names inside as well? Would I need getters and setters for each property inside the LineItemsBean?
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what you are saying makes sense about the disconnect between the HTMl and the ActionForm. Replacing the name with lineItems gives me a BeanUtils.populate error which I'm assuming has to do with my lack of setter methods for the properties. For debugging purposes I tried with a name of asdasd and it threw the same NPE I was getting earlier. I read over the indexed properties section a time or two on Apache's site but I'm still confused. I'll attempt it and if I have concrete issues I'll reply.

Thanks David.


Edit: I think my link above was done correctly with the UBB tag. Maybe the changes for SEO I read about in the Ranch Office forums are related to it appearing incorrectly. Someone should verify it isn't user error though.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like there was a space between your "=" and the URL itself. I edited out the space and it renders correctly.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks.

So after changing the name to lineItems in the loop the html generated looks like:



When I submit the form I am throwing a BeanUtils.populate exception and I don't know what to try to change this too. I don't understand how it can retrieve the value off of the object but it won't set the value on the submit.

Any ideas?

 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic