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

Using html:radio with indexed attribute

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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[1].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
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nigel,

Welcome to the JavaRanch.

You need to have the following method


More on Indexed Properties, Mapped Properties, and Indexed Tags

Sheldon Fernandes
[ September 29, 2004: Message edited by: Sheldon Fernandes ]
 
Nigel Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sheldon,

Thanks for the reply. I tried what you suggested, but to no avail...

this is what I put in the form:



I still get the same error message.

Nigel
 
Sheldon Fernandes
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are getting a NullPointerException, most probably because your designMilestoneList is null.

Are you trying to update your VO or insert data into a new VO?

Sheldon Fernandes
 
Nigel Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!

Nigel


 
Sheldon Fernandes
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What exactly does the code listMilestone[1].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[1].status", something similar happens. Only difference is that the braces "[1]" 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.

Sheldon Fernandes
 
If you want to look young and thin, hang around old, fat people. Or 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