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
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.
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.
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad: