Thanks dusty. =)

On Thu, 2007-06-28 at 20:59 -0700, dusty wrote:
> You have a common interceptor problem when using relationships.  The net net
> is that you need to modify your inteceptor stack so that near the top you
> have an order like
> ....
> params
> prepare
> params
> 
> That is the first part of the solution.    The second part is you need to
> implement Preparable on your action with the save() method.  Finally you
> need to include:
>   if(study != null){
>      study = (Study)studyDao.getObject(Study.class,study.getId())  
>      //or something like that to load the study based on the id of the
> current study object.
>   }
> 
> What this does is load all of the values from the database for the object
> and then applies what ever values have been posted in your form to your
> object.  
> 
> What is happening is that your form only has values like study.name,
> study.description, etc for the textfields that you fill out there.  When you
> post that to the server and your interceptors are just:
> 
> prepare
> params
> 
> or just 
> 
> params
> 
> You are telling the server to create a new study object and then apply all
> the values from the posted form.  There is no imageId field in the posted
> form so that field is left null, the default value for a new study object. 
> The object gets saved and poof! your relationship is gone.  A similar
> scenario is when you have a very long object and you want to just edit a
> subset of the fields for the object with a smaller form.  If you don't load
> the previous values before applying the updated values from the posted form
> you will lose all the databse values.  Another way to look at it is think
> what would happen if you did not have a hidden study.id field on your form?   
> 
> So:
> params -> apply the web parameters initially to get the id
> prepare -> use the id from above to load all the db values, including
> relationship ids
> params -> overwrite the db values with the updated values from the web
> 
> 
> 
> 
> 
> 
> vacant_eyes wrote:
> > 
> > I forgot to say the version. I am using appfuse 1.9.4 and Wwbwork. This
> > is my save() method in StudyAction:
> > 
> > public String save() throws Exception {
> >         if (cancel != null) {
> >             return "cancel";
> >         }
> > 
> >         if (delete != null) {
> >             return delete();
> >         }
> > 
> >         boolean isNew = (study.getId() == null);
> > 
> >         Date now = new Date();
> >         study.setModified(now);
> >         studyManager.saveStudy(study);
> > 
> >         String key = (isNew) ? "study.added" : "study.updated";
> >         saveMessage(getText(key));
> > 
> >         if (!isNew) {
> >             return INPUT;
> >         } else {
> >             return SUCCESS;
> >         }
> >     }
> > 
> > 
> > 
> > Thanks again
> > 
> > 
> > Adriel
> > 
> > On Thu, 2007-06-28 at 12:35 +0100, Michael Horwitz wrote:
> >> Which version of Appfuse are you using and with which web framework?
> >>  
> >> Thanks
> >>  
> >> Mike.
> >> 
> >>  
> >> On 6/28/07, adriel manalansan <[EMAIL PROTECTED]> wrote: 
> >>         Hello to everyone,
> >>         
> >>         I have 2 pojos, study and image. I did the relationship
> >>         between the 2
> >>         tables and it is successful. Here it goes, from
> >>         editStudy.html, i
> >>         uploaded an image(redirected to editImage.html) that uses
> >>         imageAction
> >>         and saved the imageId to my study then redirect to
> >>         editStudy.html again,
> >>         the imageId is saved to study table so I can say that saving
> >>         imageId to 
> >>         my study is successful. the problem is when I click the save
> >>         button to
> >>         my editStudy that calls the method save(), the imageId was
> >>         deleted. I
> >>         dont know where is the problem so please help me about this...
> >>         
> >>         Thanks and God bless you.
> >>         
> >>         Adriel
> >>         
> >>        
> >> ---------------------------------------------------------------------
> >>         To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>         For additional commands, e-mail:
> >>         [EMAIL PROTECTED]
> >>         
> >> 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> > 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to