• 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

html:text doesn't write the value to my object

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,

i am having some difficulties with the html:text field. I have a class called OrderLine which has an attribute called amount of type String.

in my jsp i have the following line :



When i go to the action which checks the different amount and when set to 0 deletes an orderline. It doesn't get the new amounts but the old ones.

Can anybody help me out on this one?

Thanks
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ricardo,

If this statement is not nested in a <logic:iterate> tag, you should eliminate the indexed="true" attribute.

If it is nested in a <logic:iterate> tag, your form must have and indexed getter and setter for this attribute as in:

public String getAmount(int index)

and

public void setAmount(int index, String amount)

Is your form bean set up this way?

Merrill
 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok to be complete :

It is within an iterate tag, i do not write to a form (perhaps that's the problem...)

I have a shoppingcart in my session -> in my page i get it from the session and iterate over the orderlines it contains. An orderline has an attribute amount which is of type String :



I hope this makes things clearer.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You ALWAYS write TO an ActionForm.

You are allowed to write from anything to the html,
but the html will always submit to the ActionForm.

What Merrill says is true, so I won't bother writing the methods.

I always try to keep editable data in the ActionForm, so that my jsp only needs to keep conversation with one location.
 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok so then comes up a different question. I have a collection of products i iterate over to display in my jsp. I want the user to be able to change the amount of a product. So i need to have an collection of String or integers in my form where i can write the different amounts to. How can i know in my action which amount belongs to a certain product?

Thanks for the help!!!
[ February 25, 2005: Message edited by: Ricardo Estafan ]
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what the indexed attribute is for that Merrill talked about.

Also, always use Strings in the ActionForm. Struts unfortunately does not validate a submitted value until after attempting to enter it in the ActionForm. So if the form expects an int and the user submits "abc", you end up with an exception.
 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok now i am going to explain what the exact problem is :

i have a shoppingcart which displays different orderlines if they are present.
This is a Set of Orderlines contained by class Order. The Order can be obtained from the session.

An orderline contains a product and the desired amount of this product.

So if like you said i would want to write the amounts of these products to String fields, my form has to contain a String[] exactly the same size as the collection of orderlines. And i would want to set the initial amount of products in the String[] so the correct amount will be displayed on the screen.

So in my GoToCatalogACtion i iterate over the orderlines, create an String[] of the appropriate size and fill the String[] with the amounts contained by the orderlines. This is the String[] i set in my form.

This works when i reach my page the form is filled with the correct amounts.

So if i fill one of the fields with a new value i go to an update action. In this action i receive the amount from the String[] and update the cart accordingly.

BUT however when i reach my action -> the String[] is null and all information is lost.

What can i do to get my filled String[] into the action??
[ February 27, 2005: Message edited by: Ricardo Estafan ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic