my dog learned polymorphism*
The moose likes Struts and the fly likes Form Params not passed properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form Params not passed properly" Watch "Form Params not passed properly" New topic
Author

Form Params not passed properly

Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
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

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 12, 2008
Posts: 229
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 12, 2008
Posts: 229
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

Joined: May 12, 2008
Posts: 229
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 12, 2008
Posts: 229
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?

 
Don't get me started about those stupid light bulbs.
 
subject: Form Params not passed properly
 
Similar Threads
Ajax, Struts, and a few pesky event based issues
Need help selected text fields visible for particular option from drop down list in JSP(struts)
Using JSTL Data Displayed In Browser Is Getting Fixed To 24576 Bytes(24 KB)
text field validation
Struts Validation Empty alert Box