• 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

JavaBean vs Post from a JSP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ranchers,
I need information about populating a bean in a JSP page just before submit the request to a servlet. There's a way to do it? or I must read all the params in the servlet and update the bean, before processing it?
Here is the big picture:
1- useBean to populate my FORM
2- Modify the data
3- set the new bean property to send to the servlet
4- processing
5- forward somewhere else the updated bean
thanks
Bobby Robinson
SCJP
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1- useBean to populate my FORM
use form to populate bean:you can do in servlet or jsp in jsp just use <jsp:usebean ID="myBeanInstance" CLASS="com.myPackage.myBeanClass" SCOPE="request">
<jsp:setProperty NAME="myBeanInstance" PROPERTY="myProperty"
PARAM="myFormElementName"/>
</jsp:usebean>
In servlet instantiate bean set properties with request.getParameter("name of param from form);
2- Modify the data
Not really sure what you want but you can put a reference to your bean in the session or request by using setAttribute method
this makes it available in session or request with getAttribute method
3- set the new bean property to send to the servlet
unclear here also but if you want to get a reference to the bean getAttribute method will do make sure you cast back to bean
if you are just talking about making the bean available to the servlet you would need to use setAttribute method of request or session in jsp form
4- processing
no clue what you mean
5- forward somewhere else the updated bean
the bean is available anywhere you have a reference to the request or session. So you are not forwarding but getting the bean from a particular scope cast and use if you still need it put it back in the request or session.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure if this is what you were looking for :
If you have the names of the request parameters that match the name of the Javabean property then there is a shortcut to set all the properties of a bean in a single action.
<jps:setProperty name ="XXXX" property ="*" />
where XXXX is the id of teh Javabean.
 
reply
    Bookmark Topic Watch Topic
  • New Topic