I'm trying to using the html:radio tag with the indexed property. I am able to display the radio buttons as I wish, but am confused as to how I should set up the form to receive the values. This is how I've coded the JSP:
which results in the generated html:
So what should I have in the associated form?
If I leave a variable with the name listMilestone out of the form completly, the I don't get any errors, but I also don't get the value of the radio button submitted.
If however, I have a String variable listMilestone, the I get errrors like:
The request has a paramter name "listMilestone.status", so how do I cater for that in the form???
How should I declare the variable, and what should the getter and setters look like?
I'm really pulling my hair out with this one!!! Nigel
Are you trying to update your VO or insert data into a new VO?
Joined: Sep 29, 2004
Hi Sheldon, Thanks again for the reply.
I guess I'm trying to update the VO.
This is what I'm trying to do: it's a a maintenance page with many detail lines, each of these lines has zero,one or many milestones associated with it.
I read the details from the DB and create a bean with a list of all the detail lines. Within ech detail line there is another list with the milestones. I retrieve and display the data OK. The problem comes when I try to get the updated information from the page.
What exactly does the code in the html mean? I see that you say I need a method, but what about the setter? How does the part work.
Sorry i'm being a bit vague here, but I'm reallyt confused!!
Joined: Aug 18, 2004
What exactly does the code listMilestone.status in the html mean?
When you submit an html form, the struts framework goes through each of the request parameters and tries to set data in the form bean associated with the action to which the submit was made.
Lets say you had a control named "person.address.street" which was submitted in a form. The framework will do the following: - call the method getPerson() on the form bean - call the method getAddress() on the object returned from the previous call (i.e. Person) - call the method setStreet() on the object returned from the previous call (i.e. Address) and set the value of the control "person.address.street".
If any of these methods does not exist, then the framework simply skips to the next request parameter trying to set it, till all request parameters are over.
The important thing to realize over here is that each "get" method call has to return an object otherwise a NullPointerException would be thrown (this is probably what's happening in your case).
For the control named "listMilestone.status", something similar happens. Only difference is that the braces "" indicate that the method "getListMilestone(int)" will get called. (Just check the link I provided in a previous reply, I remember seeing that the get(int) method returned a List, but I think even the way I suggested would work).
Another important thing to consider is the "scope" of your form bean. If the scope is session, the framework will try to first locate an existing form bean in session and will only create a new one if one does not exist. If the scope is request a new form bean will be created for you each time (I suspect your form bean has scope "request").
Since you want to update information I would suggest keeping the form bean scope as session. If the scope is request, then the form bean constructor would be responsible for ensuring that empty objects are created in the form, thus keeping it ready to be populated. So for the first example, the constructor should create an empty Person object, which has an empty Address object. This gets increasingly complex when you have collections as form attributes. It is much easier to make the form bean scope "session".
Armed with this knowledge, I hope you will be able to debug and fix your problem.