Discussion:
[Stripes-users] Multiple forms on one page
Philip Constantinou
2007-09-22 22:25:32 UTC
Permalink
Hi folks -

I'm wondering what the best solution is for supporting multiple forms on
one page. To make the requirements a little more complex, I'd like to
support the following:

* Forms operate independently and the design does not prohibit
action beans used in other places.
* Forms should be pre-populated when you enter the page based on the
default event handlers.
* Form validation should work so errors appear on the correct fields
but not on the form that was not submitted.
* The form that was not validated/was not submitted should continue
to be pre-populated with the defaults.

Can stripes do this somehow?

I always find myself hacking around my inability to do this elegantly.
Sometimes I just create one big ActionBean, sometimes I use el to plug
in values in non-stripes elements but I think the time has come for to
do defer to the experts to see how this is really done.

Thanks in advance -
Phil
Nick Stuart
2007-09-23 01:44:30 UTC
Permalink
I think we might be of more help if we had a use case of some kind. If your
forms contain multiple fields that have the same name then I'm not sure
there is going to be much of elegant solution possible. But maybe with a
little more background the collective wisdom might be able to come up with
something. :)

-Nick
Post by Philip Constantinou
Hi folks -
I'm wondering what the best solution is for supporting multiple forms on
one page. To make the requirements a little more complex, I'd like to
* Forms operate independently and the design does not prohibit
action beans used in other places.
* Forms should be pre-populated when you enter the page based on the
default event handlers.
* Form validation should work so errors appear on the correct fields
but not on the form that was not submitted.
* The form that was not validated/was not submitted should continue
to be pre-populated with the defaults.
Can stripes do this somehow?
I always find myself hacking around my inability to do this elegantly.
Sometimes I just create one big ActionBean, sometimes I use el to plug
in values in non-stripes elements but I think the time has come for to
do defer to the experts to see how this is really done.
Thanks in advance -
Phil
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
https://lists.sourceforge.net/lists/listinfo/stripes-users
Philip Constantinou
2007-09-23 18:55:35 UTC
Permalink
Thanks Nick -
Yea, the overlapping names has been one of the sources of my troubles.

An example which highlights the problem is: a log in and registration
form on the same web page. I want the user name to pre-populate on the
log in form if a cookie is set but not pre-populate on the registration
form even though both forms have an attribute of "username".

If the user mis-fills out the registration form, I still want both forms
to appear with a consistent behavior which includes the registration
form re-populating with the user's prior entry for user name and the log
in form pre-populating based on the cookie.

I can see how, with one ActionBean, multiple events and specifically
crafted attributes and validation rules I can code around the problem
and if that's the stripes way of doing things I can get by, I was just
wondering if there's a better way that I'd missed.

I've also ran into problems where I've wanted 2 or 3 separate forms each
with a single field and a "New" button. eg. New Folder, New Contact,
Find Contact. I want the person to be able to type into the text box and
hit enter to invoke the default action and have validation rules to
still check for invalid characters and display the appropriate error
message back in place. With one big form the default action is ambiguous
even if you're renamed the attributes.

We're trying to write up some guidelines for our team who is new to
stripes so I want to make sure we're heading everyone in the best direction.

It sounds like the rule is: there can be only one form that requires
validation per JSP page in stripes. Stripes prefers larger action beans
with the form spanning the who page.


Thanks -
Phil
Post by Nick Stuart
I think we might be of more help if we had a use case of some kind. If
your forms contain multiple fields that have the same name then I'm
not sure there is going to be much of elegant solution possible. But
maybe with a little more background the collective wisdom might be
able to come up with something. :)
-Nick
Hi folks -
I'm wondering what the best solution is for supporting multiple forms on
one page. To make the requirements a little more complex, I'd like to
* Forms operate independently and the design does not prohibit
action beans used in other places.
* Forms should be pre-populated when you enter the page based on the
default event handlers.
* Form validation should work so errors appear on the correct fields
but not on the form that was not submitted.
* The form that was not validated/was not submitted should continue
to be pre-populated with the defaults.
Can stripes do this somehow?
I always find myself hacking around my inability to do this elegantly.
Sometimes I just create one big ActionBean, sometimes I use el to plug
in values in non-stripes elements but I think the time has come for to
do defer to the experts to see how this is really done.
Thanks in advance -
Phil
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
------------------------------------------------------------------------
_______________________________________________
Stripes-users mailing list
https://lists.sourceforge.net/lists/listinfo/stripes-users
Will Hartung
2007-09-24 03:51:32 UTC
Permalink
Post by Philip Constantinou
Thanks Nick -
Yea, the overlapping names has been one of the sources of my troubles.
An example which highlights the problem is: a log in and registration
form on the same web page. I want the user name to pre-populate on the
log in form if a cookie is set but not pre-populate on the
registration
form even though both forms have an attribute of "username".
Actually, this is precisely what <s:useActionBean ... > is for.

<s:useActionBean beanclass="com.example.XActionBean"/>
<s:form beanclass="com.example.XActionBean">
<s:text name="username"/>
</s:form>

<s:useActionBean beanclass="com.example.YActionBean"/>
<s:form beanclass="com.example.YActionBean">
<s:text name="username"/>
</s:form>

This does exactly what it looks like it does.

Recall that useActionBean doesn't do anything if the bean is already
in the pageContext. So, if you call "YActionBean" and then forward to
the page, YActionBean will already be in the scope, and only
XActionBean will be created. And vice-a-versa.

So, seems to me you can simply preface each form in your page with a
useActionBean tag and odds are you're pretty close to where you want
to be with that alone.

This also leads well to componentization, wrap your forms and
useActionBeans in to JSP Tag Files, and you'll have a <tag:loginForm/
Post by Philip Constantinou
component that you can safely plop most anywhere on any page.
What you may want to do is write some utility code to capture the
entire url (including parameters), that way something like a login
component can redirect exactly where it came from (assuming you rely
on GET parameters to render your pages after the redirect).
_sourcePage only captures the page, not the actual request, and then
it's the JSP, not the action.

For example, say you were on page: /ViewStory.action?story.id=123

It would be nice to capture that URL, then have your "component"
capture it.

<s:useActionBean beanclass="com.example.LoginActionBean" var="ab"/>
<s:form beanclass="com.example.LoginActionBean">
<s:label name="userName">User Name</s:label>: <s:text
name="userName"/>
<s:label name="password">Password</s:label>: <s:password
name="password"/>
<s:hidden name="pageUrl" value="${ab.context.pageUrl}"/>
<s:submit name="login" value="Login"/>
</s:form>

Here, there's a "getPageUrl" method that's part of the context for
the Action Bean -- it can get the request and rebuild the url, yet
still look like a normal getter. So, in this case it would be "/
ViewStory.action?story.id=123".

And in your action bean:

public Resolution login() {
loginUser(userName, password);
return new RedirectResolution(pageUrl);
}

and your original page won't even know it's ever left and come back.

Season to taste, but I this should work and sounds like what you want.

Obviously you only do this on pages that need it. If you're going
redirect away, then there's no call for tracking the original URL.

Regards,

Will Hartung
Philip Constantinou
2007-09-24 04:35:40 UTC
Permalink
Thanks Will, you and the Stripes team rule!
Post by Will Hartung
Post by Philip Constantinou
Thanks Nick -
Yea, the overlapping names has been one of the sources of my troubles.
An example which highlights the problem is: a log in and registration
form on the same web page. I want the user name to pre-populate on the
log in form if a cookie is set but not pre-populate on the
registration
form even though both forms have an attribute of "username".
Actually, this is precisely what <s:useActionBean ... > is for.
<s:useActionBean beanclass="com.example.XActionBean"/>
<s:form beanclass="com.example.XActionBean">
<s:text name="username"/>
</s:form>
<s:useActionBean beanclass="com.example.YActionBean"/>
<s:form beanclass="com.example.YActionBean">
<s:text name="username"/>
</s:form>
This does exactly what it looks like it does.
Recall that useActionBean doesn't do anything if the bean is already
in the pageContext. So, if you call "YActionBean" and then forward to
the page, YActionBean will already be in the scope, and only
XActionBean will be created. And vice-a-versa.
So, seems to me you can simply preface each form in your page with a
useActionBean tag and odds are you're pretty close to where you want
to be with that alone.
This also leads well to componentization, wrap your forms and
useActionBeans in to JSP Tag Files, and you'll have a <tag:loginForm/
Post by Philip Constantinou
component that you can safely plop most anywhere on any page.
What you may want to do is write some utility code to capture the
entire url (including parameters), that way something like a login
component can redirect exactly where it came from (assuming you rely
on GET parameters to render your pages after the redirect).
_sourcePage only captures the page, not the actual request, and then
it's the JSP, not the action.
For example, say you were on page: /ViewStory.action?story.id=123
It would be nice to capture that URL, then have your "component"
capture it.
<s:useActionBean beanclass="com.example.LoginActionBean" var="ab"/>
<s:form beanclass="com.example.LoginActionBean">
<s:label name="userName">User Name</s:label>: <s:text
name="userName"/>
<s:label name="password">Password</s:label>: <s:password
name="password"/>
<s:hidden name="pageUrl" value="${ab.context.pageUrl}"/>
<s:submit name="login" value="Login"/>
</s:form>
Here, there's a "getPageUrl" method that's part of the context for
the Action Bean -- it can get the request and rebuild the url, yet
still look like a normal getter. So, in this case it would be "/
ViewStory.action?story.id=123".
public Resolution login() {
loginUser(userName, password);
return new RedirectResolution(pageUrl);
}
and your original page won't even know it's ever left and come back.
Season to taste, but I this should work and sounds like what you want.
Obviously you only do this on pages that need it. If you're going
redirect away, then there's no call for tracking the original URL.
Regards,
Will Hartung
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
https://lists.sourceforge.net/lists/listinfo/stripes-users
Kai Grabfelder
2007-09-24 16:51:22 UTC
Permalink
Post by Will Hartung
Here, there's a "getPageUrl" method that's part of the context for
the Action Bean -- it can get the request and rebuild the url, yet
still look like a normal getter.
hehe just the same way I'm doing it. Nice to see others do it the same way ;-)

--- Original Nachricht ---
Absender: Will Hartung
Datum: 24.09.2007 05:51
Post by Will Hartung
Post by Philip Constantinou
Thanks Nick -
Yea, the overlapping names has been one of the sources of my troubles.
An example which highlights the problem is: a log in and registration
form on the same web page. I want the user name to pre-populate on the
log in form if a cookie is set but not pre-populate on the
registration
form even though both forms have an attribute of "username".
Actually, this is precisely what <s:useActionBean ... > is for.
<s:useActionBean beanclass="com.example.XActionBean"/>
<s:form beanclass="com.example.XActionBean">
<s:text name="username"/>
</s:form>
<s:useActionBean beanclass="com.example.YActionBean"/>
<s:form beanclass="com.example.YActionBean">
<s:text name="username"/>
</s:form>
This does exactly what it looks like it does.
Recall that useActionBean doesn't do anything if the bean is already
in the pageContext. So, if you call "YActionBean" and then forward to
the page, YActionBean will already be in the scope, and only
XActionBean will be created. And vice-a-versa.
So, seems to me you can simply preface each form in your page with a
useActionBean tag and odds are you're pretty close to where you want
to be with that alone.
This also leads well to componentization, wrap your forms and
useActionBeans in to JSP Tag Files, and you'll have a <tag:loginForm/
Post by Philip Constantinou
component that you can safely plop most anywhere on any page.
What you may want to do is write some utility code to capture the
entire url (including parameters), that way something like a login
component can redirect exactly where it came from (assuming you rely
on GET parameters to render your pages after the redirect).
_sourcePage only captures the page, not the actual request, and then
it's the JSP, not the action.
For example, say you were on page: /ViewStory.action?story.id=123
It would be nice to capture that URL, then have your "component"
capture it.
<s:useActionBean beanclass="com.example.LoginActionBean" var="ab"/>
<s:form beanclass="com.example.LoginActionBean">
<s:label name="userName">User Name</s:label>: <s:text
name="userName"/>
<s:label name="password">Password</s:label>: <s:password
name="password"/>
<s:hidden name="pageUrl" value="${ab.context.pageUrl}"/>
<s:submit name="login" value="Login"/>
</s:form>
Here, there's a "getPageUrl" method that's part of the context for
the Action Bean -- it can get the request and rebuild the url, yet
still look like a normal getter. So, in this case it would be "/
ViewStory.action?story.id=123".
public Resolution login() {
loginUser(userName, password);
return new RedirectResolution(pageUrl);
}
and your original page won't even know it's ever left and come back.
Season to taste, but I this should work and sounds like what you want.
Obviously you only do this on pages that need it. If you're going
redirect away, then there's no call for tracking the original URL.
Regards,
Will Hartung
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
https://lists.sourceforge.net/lists/listinfo/stripes-users
Loading...