You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Derek Clayton <de...@iceinc.com> on 2001/11/21 20:51:58 UTC

prepopulating, initializing and securing a form

I have a form which I want to prepopulate with some general data (eg. a list or provinces) from a database along with some user specific data again from a database (eg. user name).  The form is also secure so I want the user to be "logged in" to access it.

So I have set up:

Page.jsp - the view containing the form
PageForm.java - extends ActionForm
PageAction.java - extends Action and set in mapping as pageAction.do

In PageAction I check for a session attribute which tells me whether or not the user is logged in.  If the user is not logged in I forward them to a login sequence.

The problem is when I call pageAction.do the PageAction is never called.  The reset() and validate() methods on PageForm are called but then Page.jsp is displayed without ever having called PageAction's perform() and therefore never doing security authentication.

So no security validation occurs.  I have no opportunity to prepopulate the form.  I did cheat in a way by having reset() set the general data but I still need a way to prepulate the personal data that I want pre-filled on the form *once* when it's first displayed and then allow the user to change from then on.  So if they change their name on the form, for example, but make an error on the form then when the form is redisplayed it doesn't reset the name back to what's in the database but instead shows the changed name.

In my mapping I have the input attribute set to Page.jsp.  Perhaps I'm misusing this attribute.

Thanks for any and all help.

Derek
 

Re: prepopulating, initializing and securing a form

Posted by Myles <my...@ipudev.com>.
<struts-newbie>

This might be heretical, but why can't you just call the form bean's validate 
method from your action servlet.  It still does the "business logic" of 
validating the form and you'd still be able to validate your user.


ActionErrors errors = new ActionErrors();
MyForm myForm = (MyForm) form;
// validat user ...
// explicitly call the form's validate method
errors = myForm.validate();
// check to see if it returned errors
if ( !errors.empty() ) {
	// save the specified error messages into the request
	// so that you can use the <struts:errors> tag
	saveErrors(request, errors);
	// return to the original form
	return ( new ActionForward( mapping.getInput() ) );
	// or return ( mapping.findForward("failure") ) if you like
}


No?
</struts-newbie>

On Wednesday 21 November 2001 14:51, you wrote:

> > I have a form which I want to prepopulate with some general data (eg. a
> list or provinces) from a database along with some user specific data again
> from a database (eg. user name).  The form is also secure so I want the
> user to be "logged in" to access it.
>
> So I have set up:
>
> Page.jsp - the view containing the form
> PageForm.java - extends ActionForm
> PageAction.java - extends Action and set in mapping as pageAction.do
>
> In PageAction I check for a session attribute which tells me whether or not
> the user is logged in.  If the user is not logged in I forward them to a
> login sequence.
>
> The problem is when I call pageAction.do the PageAction is never called. 
> The reset() and validate() methods on PageForm are called but then Page.jsp
> is displayed without ever having called PageAction's perform() and
> therefore never doing security authentication.
>
> So no security validation occurs.  I have no opportunity to prepopulate the
> form.  I did cheat in a way by having reset() set the general data but I
> still need a way to prepulate the personal data that I want pre-filled on
> the form *once* when it's first displayed and then allow the user to change
> from then on.  So if they change their name on the form, for example, but
> make an error on the form then when the form is redisplayed it doesn't
> reset the name back to what's in the database but instead shows the changed
> name.
>
> In my mapping I have the input attribute set to Page.jsp.  Perhaps I'm
> misusing this attribute.
>
> Thanks for any and all help.
>
> Derek


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


AW: prepopulating, initializing and securing a form

Posted by Dirk Gabler <di...@kambrium.net>.
actually you talk about different things:

- IsLoggedIn-Check
Why don't you put this into a separat tag ?

- Prepopulation of forms
We had the same problem and our solution was to extend the
org.apache.struts.taglib.html.FormTag and overwrite its doStartTag()-method.
In this method we get the form out of the pageContext and if it's a Form
which implements our own PrepopInterface, we call its method "prepopulate()"

cheers,
dirk

-----Ursprüngliche Nachricht-----
Von: Derek Clayton [mailto:derekc@iceinc.com]
Gesendet: Mittwoch, 21. November 2001 20:52
An: Struts Users Mailing List
Betreff: prepopulating, initializing and securing a form


I have a form which I want to prepopulate with some general data (eg. a list
or provinces) from a database along with some user specific data again from
a database (eg. user name).  The form is also secure so I want the user to
be "logged in" to access it.

So I have set up:

Page.jsp - the view containing the form
PageForm.java - extends ActionForm
PageAction.java - extends Action and set in mapping as pageAction.do

In PageAction I check for a session attribute which tells me whether or not
the user is logged in.  If the user is not logged in I forward them to a
login sequence.

The problem is when I call pageAction.do the PageAction is never called.
The reset() and validate() methods on PageForm are called but then Page.jsp
is displayed without ever having called PageAction's perform() and therefore
never doing security authentication.

So no security validation occurs.  I have no opportunity to prepopulate the
form.  I did cheat in a way by having reset() set the general data but I
still need a way to prepulate the personal data that I want pre-filled on
the form *once* when it's first displayed and then allow the user to change
from then on.  So if they change their name on the form, for example, but
make an error on the form then when the form is redisplayed it doesn't reset
the name back to what's in the database but instead shows the changed name.

In my mapping I have the input attribute set to Page.jsp.  Perhaps I'm
misusing this attribute.

Thanks for any and all help.

Derek




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>