struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conrad CRAMPTON PSE 52704" <conrad.cramp...@kent.pnn.police.uk>
Subject Re: Pre populate form missing values from nested object
Date Thu, 20 Jan 2005 15:21:28 GMT
 
 

Conrad Crampton
Software Solutions Manager
Force Headquarters
11 Edinburgh Square
Sutton Road
Maidstone
ME15 9BZ
01622 653283 (ext)
19-3283 (internal)
07814 011752 (mobile)

>>> hrabago@gmail.com 19/01/05 16:07:49 >>>

> So the question is this - how do I retain values of nested properties
that
> aren't required to be (or cannot be) represented in the jsp? 

>>The only values that you'll get when the form is submitted are the
>>values that the form has.
>>If you have values that you want to submit with the form, but don't
>>want them displayed to the user, look at hidden fields
<html:hidden/>.

So this essentially means that nested objects are worthless as you
can't keep reference to child objects that you populate in the middle
tier for the trip around to the UI and back again. I am using Hibernate
for persistence so have the object graph that am providing the UI for
updates that has child collections etc. Populating the form bean with
the parent class I would have thought could be 'round-tripped' back to
the middle tier with the child objects still attached to the object.


> It appears that
> the value of premises is always null and not using what is in the
request
> scope when the jsp is submitted. 

>>Roughly, a "request" begins when the browser asks for information
from
>>the server, and ends when the server has supplied that information. 
>>After you've created your Premises object and displayed it on your
>>JSP's form, the request is done.  When the user submits the form,
that
>>counts as another request, a new, empty, fresh one, with nothing yet
>>in its scope, except for the data that comes with the form being
>>submitted.
 
yes, I realise how the http protocol work for requests but the struts
documentation appears to bat on about if there is a form bean already in
the current scope (and it is for the current request), then this should
be used - this is obviously being done for the properties that are
visible HTML elements as I can see the data. What I find frustrating
that the form bean that is in scope that populated the editable fields,
doesn't just get those values repopulated with any changes but leaves
the rest of the form bean as it was on initial population.

>>If you want your form to persist between requests, put your form in
>>session scope.  Take a look at
>>http://java.sun.com/developer/EJTechTips/2003/tt1209.html#2 for a
>>better explanation of the differences between scopes.

I understand what scopes are and this is why I was using request. I
didn't want the overhead of having to keep removing transient data from
session scope. IMHO it is lazy and potentially conducive to bugs to
throw everything into session scope. If you fail to clear up properly
then it can lead to problems. My team are currently working on a large
Struts app that puts everything into session and is having numerous
problems with what appears to be session data being lost.

>>Here's another link that might help you manage your form data,
>>particularly collections that you may place in <select> controls:
>>http://www.reumann.net/struts/articles/request_lists.jsp

>>hth,
>>Hubert
 
Thanks for the response though
Conrad


On Wed, 19 Jan 2005 13:02:20 +0000, Conrad CRAMPTON PSE 52704
<conrad.crampton@kent.pnn.police.uk> wrote:
>  
> Hi, 
> The list archive search doesn't appear to work to forgive me if this
is a
> simple and already answered topic. 
>   
> I have an actionform that has an object as a property - Premises
premises,
> and a jsp that uses <html:text name="Premises"
property="premises.name" />. 
> When I use createPremises.jsp all is ok and the values for premises
get
> through to my action no problem. 
>   
> The problem I have though is when I want to edit premises. The
action
> (extending Dispatchaction) viz... 
>   
> public ActionForward edit(ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response) throws
> IOException, ServletException {
>   PremisesForm premForm = (PremisesForm) form;
>   String returnMapping = "edit";
>   Long id = null;
>   if (request.getParameter("id") != null)
>    id = new Long(request.getParameter("id"));
>   if (id == null)
>    id = (Long) request.getAttribute("id");
>   try {
>    PremisesDAO pdao = new PremisesDAO();
>    Premises prem = pdao.getPremises(id);
>    premForm.setPremises(prem);
>    premForm.setOwner(prem.getOwner());
>    request.setAttribute("Premises", premForm);
>   } catch (DataAccessException e) {
>    e.printStackTrace();
>    returnMapping = "error";
>    request.setAttribute("error", e.getMessage());
>   }
>   return mapping.findForward(returnMapping);
>  }
>  
> which is fine and sets the PremisesForm premises attribute
correctly.
> However when this gets submitted ultimately from the jsp, the
properties of
> premises that aren't html:text elements in my jsp aren't being
retained.
> e.g. id (primary key of premises from db, and other things like
collections
> of other pojo's in premises. 
>   
> So the question is this - how do I retain values of nested properties
that
> aren't required to be (or cannot be) represented in the jsp? It
appears that
> the value of premises is always null and not using what is in the
request
> scope when the jsp is submitted. 
>   
> I am sure this is simple answer but I just can't get it! 
>   
> TIA 
> Conrad 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



Mime
View raw message