This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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: 9584
13
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: 9584
13
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.
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!