> if u have overridden validate method in the actionForm then ActionServlet
> automatically take u to the mapping.getInput() ( i.e  ur input jsp file )
> where u can show the errors using <html:errors> tag . Basicallly
> ActionErrors are kept in the request scope which are retrieved in the
> <html:errors> tag

I know that.

> Else if u want to do validation even in ur action class , then create a
> instance of ActionErrors in the action class and add errors to it . save
the
> errors using saveErrors(request , actionErrros) method available in the
> Struts- Action class . So errors will be kept in the request scope and
again
> use same <html:errors> tag to display them

I know this too... but it's not the problem what I'm having.

Here is the work flow:

1. select user from list
    - executes SelectUserAction that places UserBean in request scope.
    - forwards to edituser.jsp.
2. Populate form that is in edituser.jsp from UserBean
    - that form has action mapping to UpdateUserAction.
3. Submit form (Update)
    - UserForm gets populated and then it's validated by struts by calling
       validate method.
    - If validation fails then  go back to edituser.jsp and the problem
arises:
      there is not anymore UserBean in request scope, because
      SelectUserAction is responsible of that and it does not get executed,
      so I get error: No xxx bean in scope null.

So how do I write that form so I can populate it automatically? I mean
that what code I should put in SelectUserAction so I can use tag like this:

<html:text property="userName" size="14" maxlength="14"/>

to automatically pre-populate that form, instead of writing code like this:

<html:text name="userBean" property="userName" size="14" maxlength="14"/>.

Is there some way to put pre-populated form in some scope so that struts
automatically finds it and populates the form (I bet there is, but don't
know
how to do it).

I also included my first mail in this so you can get more specific detail on
this problem.

> > I know that this have been asked several times, but I did
> > not find answer for this little problem.
> >
> > I have list of lets say users. Each user has a link that maps
> > to edituser action. That action then gets executed and it
> > places userbean to request scope. Then struts forwards
> > action to edituser.jsp. Edituser.jsp has form that has
> > action mapping set to updateuser. When user submits
> > that form which binds to userform action form the
> > validate method of that actionform gets executed. If
> > validation errors occurred then we get back to input
> > form (which is edituser.jsp or edituser.do <-- which
> > to use?). And this is the point when I do not really
> > understand what I should do, because when user gets
> > back to edituser.jsp or edituser.do then there is not
> > anymore that userbean is request scope. And because
> > edituser.do does not have any forms associated with
> > it then I should instead use edituser.jsp as input for
> > updateuser action. But how I then write that form
> > (jsp-page)?
> >
> > I have several options:
> >
> > 1. put userbean in session scope (might be problem in
> > multiserver environment also the modifications that user
> > entered are not visible).
> >
> > 2. Have another jsp-page that does not populate the form
> > from userbean. Not good option because almost the same
> > form needs to be written second time.
> >
> > 3. Use logic tags to check the existence of userbean and if
> > it does not exist then do not populate and let the form
> > populate itself from posted form. Same problems as in 2.
> >
> > 4. Somehow prepopulate the form with no manual
> > population, but automatically. So do I pre-populate the
> > form. What code I need to put in edituser action that
> > previously placed userbean in request scope. I want to
> > place the form object in that same scope, but don't
> > know how. This is the best option and has no problems
> > or at least I have not found a one.
> >
> > Thanks again!
> >
> > Aapo Laakkonen

Reply via email to