Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Pass a JavaBean from jsp to Struts Action, is it possibile?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Struts i've an action that initializes an Arraylist of JavaBeans


The bean Category includes atrributes such id, name, data and sign.



Once i'm in the jsp, i generate a combobox throught the <s:select> tag giving as list the catList array.


We can imagine the various option of the select box as different beans/objects, each with own attributes (id, name, data and sign). Once the user submits the form into the struts action, can i retrieve the entire Category bean that has been selected?

Actually i only pass the id as value, but i'm in doubt about this fact...
 
Bartender
Posts: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Luca Coraggio wrote:Once the user submits the form into the struts action, can i retrieve the entire Category bean that has been selected?



You get in the action what you send from the JSP, so in the case of the code above, you would get the Category ID. That's probably what you want because you will use the ID, not the entire category, to create a relationship in a database (i.e. add a line item to an invoice). Presumably you would then forward to an action that would display the newly created relationship (i.e. display the invoice with line items) but that should be a separate action, along the lines of what we discussed in your previous post
 
Luk Cora
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, and if i use the entire javabean into the jsp, instead the key/value pair only? Is it possibile?
 
Luk Cora
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, i explain better my situation.
Into the action i generate an ArrayList that contains javabeans.
I iterate it into the jsp in this mode



Once i submit the form, i can't retrieve the values of the ArrayList that i've previously generated... It's like if the persistence is broken
The action that i call when the form is submitted, correctly have declared an ArrayList called listaArticoliCarrello, now i need to know how to pass it from jsp to the action
 
Joe Ess
Bartender
Posts: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Luca Coraggio wrote:Ok, and if i use the entire javabean into the jsp, instead the key/value pair only? Is it possibile?



Yes. You will need to put each of the values above into a form tag, otherwise it is not submitted with the request (your code above just writes the values to the page).
Since you are using a collection, you will need to use indexed properties so Struts knows how to rebuild the collection.
 
And inside of my fortune cookie was this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic