If you have Controller, you're not using Struts - you're using Spring MVC. ;-)

If you look at the latest code for UserFormController.java in
Subversion, we've changed the formBackingObject method so it
re-fetches the user from the database before populating it with
request parameters. If you change your code to match, it should solve
this problem for you:

   protected Object formBackingObject(HttpServletRequest request)
   throws Exception {

       if (!isFormSubmission(request)) {
           String userId = request.getParameter("id");

           // if user logged in with remember me, display a warning
that they can't change passwords
           log.debug("checking for remember me login...");

           AuthenticationTrustResolver resolver = new
AuthenticationTrustResolverImpl();
           SecurityContext ctx = SecurityContextHolder.getContext();

           if (ctx.getAuthentication() != null) {
               Authentication auth = ctx.getAuthentication();

               if (resolver.isRememberMe(auth)) {
                   request.getSession().setAttribute("cookieLogin", "true");

                   // add warning message
                   saveMessage(request,
getText("userProfile.cookieLogin", request.getLocale()));
               }
           }

           User user;
           if (userId == null && !isAdd(request)) {
               user =
getUserManager().getUserByUsername(request.getRemoteUser());
           } else if (!StringUtils.isBlank(userId) &&
!"".equals(request.getParameter("version"))) {
               user = getUserManager().getUser(userId);
           } else {
               user = new User();
               user.addRole(new Role(Constants.USER_ROLE));
           }

           user.setConfirmPassword(user.getPassword());

           return user;
       } else if (request.getParameter("id") != null &&
!"".equals(request.getParameter("id"))
               && request.getParameter("cancel") == null) {
           // populate user object from database, so all fields don't
need to be hidden fields in form
           return getUserManager().getUser(request.getParameter("id"));
       }

       return super.formBackingObject(request);
   }

Matt


On 2/14/07, 23455432 <[EMAIL PROTECTED]> wrote:

I think I must be missing something. I only have xdoclet tags in my User.java
and Person.java

My UserController and UserFormController don't have any tags - are those the
files you were referrign to?

They do use the request to get information. Should I change that to session?


Matt Raible-3 wrote:
>
> You could do this for your person list, but it'd be a pain because
> you'd have to use the <nested:*> tag and write out all your properties
> properly.  The easier thing to do is look in your XDoclet tags at the
> top of your UserAction.java and change request to session.
>
> Matt
>
> On 2/14/07, 23455432 <[EMAIL PROTECTED]> wrote:
>>
>> I am using STruts. In which case, I should put the form in session. What
>> does
>> that mean? I noticed that in the form there are some hidden inputs like
>>
>>  <form:hidden path="accountExpired"/>
>>
>> Should I do the same for my personList?
>>
>> thanks.
>>
>>
>>
>> Matt Raible-3 wrote:
>> >
>> > On 2/14/07, 23455432 <[EMAIL PROTECTED]> wrote:
>> >>
>> >> I have a user object that contains many persons in a one-to-many bag
>> >> relationship.
>> >>
>> >> The relationship is set up as follows:
>> >>
>> >> // USER class
>> >>  /**
>> >>      * @hibernate.bag name="persons" lazy="false"
>> cascade="save-update"
>> >>      * @hibernate.collection-key column="user_id"
>> >>      * @hibernate.collection-one-to-many
>> class="org.appfuse.model.Person"
>> >>      */
>> >> public List getPersons(){.....
>> >>
>> >>
>> >>         private Long userId;
>> >>
>> >>         /**
>> >>      * @hibernate.property column="user_id"
>> >>          */
>> >>         public Long getUserId(){
>> >>                 return userId;
>> >>
>> >>
>> >> So the person table has a user_id column that tells me what user the
>> >> person
>> >> belongs to.
>> >>
>> >> Whenever I edit the profile of the user, the persons disappear from
>> the
>> >> users person list because in the DB the user_id column for the person
>> >> gets
>> >> set to NULL. I am not sure why this is happening. I think it may be
>> the
>> >> cascade options.
>> >
>> > This happens likely because you're not holding the nested persons as
>> > hidden fields.  Since the form is in request scope, anything not in
>> > hidden fields gets set to null.  If you're not using Struts 1.x, other
>> > frameworks have ways of repopulating the object before setting its
>> > values from request parameters.  If you're are using Struts 1.x, you
>> > can put the form in the session, or programmatically refetch the
>> > object from your database and reset the persons on your user.
>> >
>> >>
>> >> Also, if I make changes to the user object, how can I get those
>> changes
>> >> in
>> >> the DAO, SERVICE and WEB layer without changing whats already there...
>> >> using
>> >> appgen.
>> >
>> > The DAO, Service and Web layers don't contain a whole lot of
>> > fine-grained details about your User object.  You should be able to
>> > add/remove properties and make changes in your JSP.  If you use a good
>> > IDE and its refactoring capabilities, it should let you know when
>> > changes need to be made in your Java code. If nothing else, the
>> > existing unit tests should tell you if you broke something.
>> >
>> > Hope this helps,
>> >
>> > Matt
>> >
>> >>
>> >> Any direction would be appreciated.
>> >>
>> >> Thanks.
>> >>
>> >> ~rk
>> >> --
>> >> View this message in context:
>> >>
>> 
http://www.nabble.com/Parent-object-updates-child-object-in-one-to-many-tf3229257s2369.html#a8972104
>> >> Sent from the AppFuse - User mailing list archive at Nabble.com.
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >> For additional commands, e-mail: [EMAIL PROTECTED]
>> >>
>> >>
>> >
>> >
>> > --
>> > http://raibledesigns.com
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> 
http://www.nabble.com/Parent-object-updates-child-object-in-one-to-many-tf3229257s2369.html#a8972237
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
> --
> http://raibledesigns.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>

--
View this message in context: 
http://www.nabble.com/Parent-object-updates-child-object-in-one-to-many-tf3229257s2369.html#a8972384
Sent from the AppFuse - User mailing list archive at Nabble.com.

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




--
http://raibledesigns.com

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

Reply via email to