• 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

Autopupulate of the jsp page using values from th FormBean

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem with autopolulate function of Struts forms.
For example, I have in my jsp page the following constructs:

In my DynaActionForm I have a property:

When I access jsp page for the first time, everything is OK.
I can see my drop-down list, choose a value and send it to the Action.
Struts populates correct value in the producer_name property of the FormBean,
but the problem happens when I try to get back to this jsp page from my action.
What I get is a mess of various characters, i.e. I don't get my jsp page filled
correctly with old values contained in my FormBean. This means that autopopulate
of the jsp page using values from the FormBean doesn't work in this case.
It relates to previos use of the for loop.
How can I overcome this problem?
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not quite clear what your problem is, Where do you see the wrong values? What is the flow? Is it jsp1 -> action -> jsp1?

What value is stored in the arraylist? Dump the values stored in the list_of_producers at the JSP or in System out stream and check the values. Is the forward from action a redirect?
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the flow is: jsp1 -> action -> jsp1

Forward is like: return new ActinForward(mapping.getInput())
But, the same path is for success.

ArrayList is OK.

The problem lies in the fact that when the flow returns to the jsp1 again, it should set the already choosen value in the combo-box (property "producer_name"); that is autopupulating of the jsp1 with values contained in the associated ActionForm. But that doesn't happen.

I have tried to enter static values into combo-box, e.g.:

<html:select property="producer_name">
<html ption value="ford">Ford</html ption>
<html ption value="peugeot">Peugeot</html ption>
<html ption value="fiat">Fiat</html ption>
</html:select>

and in this case, autopopulating works as expected. If I e.g. choose Fiat, when the flow returns me to the jsp1, Fiat will be preselected in the combo-box, and that's OK. But this doesn't work if I dinamically create combo-box values. Why, and what is the solution?
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of using a scriptlet to display your options, use html:optionsCollection.
[ February 12, 2007: Message edited by: Dom Lassy ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, don't forget that since "list_of_producers" is in request scope, you must rebuild that list in your Action class. Otherwise, it's out of scope when the JSP is called the second time.
 
Velika Srbija
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that was the problem. I put it into the session, and my jsp1 page displayed correctly. But, that is only the part of the problem. I don't get messy jsp1 page anymore, but there is no preselected value in the combo-box. Instead, combo-box is rendered as is, i.e. like at the very first visit of the jsp1 page.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your method of populating the options is a little strange, and I'm guessing that may be the problem.

The easiest way to do this is to use the Struts LabelValue bean. Instantiate a bean for each valid option, with the value property being the value of the option and the label property being the label you want displayed. Then put each bean instance into a List stored in session scope.

Then (as Dom already suggested) use the <html:optionsCollection> tag to populate the options. Your JSP code would look something like this:


See the heading "optionsCollection" in this link for more information on this tag.
[ February 12, 2007: Message edited by: Merrill Higginson ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic