You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Charles McClain <CM...@ATTBI.Com> on 2002/09/20 14:18:28 UTC

Re-using JSP pages

All:
 
I recently learned Struts and converted a banking app that I originally
wrote, using a much simpler MVC design pattern, to use the Struts
framework.
 
I could see the obvious benefits of Struts, in spite of the steep
learning curve and somewhat lean documentation.  After the initial
conversion, I scoured the net for Struts tips and religiously applied
them to improve the app.  At some point in the process I got Struts beta
1.12b and upgraded to it -- primarily to make use of the validator and
declarative exception handling.
 
Among the tips I applied were those (mostly from Ted Husted) about
re-using Actions and ActionForms.  I modified my Actions to extend
DispatchAction instead of Action, allowing me to put all the actions for
one object (create, edit, delete, commit, select) into the same
DispatchAction easily.  It was a beautiful thing.
 
Similarly, I reworked my ActionForms so that I could use one ActionForm
per object, externalizing my form validation to validation.xml.
 
Finally, I combined most of the actual JSPs by using logic tags to
display different messages and buttons based on the value of the
dispatch property that DispatchAction uses, and that is also a property
of the ActionForm.
 
HOWEVER, I got stuck in trying to re-use the same JSP for select
criteria that I use for other operations (create, edit, delete).
Obviously, if you are entering select criteria to the form, the fields
that are required for object creation or editing are NOT required.  So
the validation criteria must be different.
 
According to one of Ted Husted's tips, no problem; you can give a
different form-bean name to the same ActionForm and reference that
form-bean name in validation.xml.  And it works.  However, some of the
tags on the actual JSP (for example, "logic:equal", which I use to vary
the screen messages by operation, plus "log:debug" and "bean:write")
require you to specify the bean name, rather than defaulting to the bean
passed in, as other tags seem to do.  I could not for the life of me
figure out how to parameterize the bean name and re-use the same JSP,
and its tags, for ALL operations on an object.
 
This is probably something simple and stupid -- I'm still fairly new at
this -- but I would certainly appreciate any guidance.  I suspect that I
have to revert to some form of jsp:usebean, using a request parameter to
vary the name of the form -- or something kind of icky like that.
 
Thanks in advance,

Charles McClain
Phone:  603.659.2046
email:    cmcclain01@attbi.com


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


RE: Re-using JSP pages

Posted by Charles McClain <CM...@ATTBI.Com>.
Thank you, Will.

I haven't even glanced at the new nested taglib yet -- I had too much
else to learn -- but I understand what you're saying and will look into
it as a solution.

I recently adapted my app to use Struts templates, which mandates two
JSPs (a template/header and another JSP with the actual content) for
each form I create, so the proliferation of JSPs is something I'm
already concerned about.  If the nested taglib allows me to re-use a
single (pair of) JSP(s) for all actions against a given object, it will
be a big help.

-----Original Message-----
From: Will Jaynes [mailto:jaynes@umich.edu] 
Sent: Friday, September 20, 2002 8:58 AM
To: Struts Users Mailing List
Subject: Re: Re-using JSP pages




Charles McClain wrote:
>  <snip />
>  
> According to one of Ted Husted's tips, no problem; you can give a 
> different form-bean name to the same ActionForm and reference that 
> form-bean name in validation.xml.  And it works.  However, some of the

> tags on the actual JSP (for example, "logic:equal", which I use to 
> vary the screen messages by operation, plus "log:debug" and 
> "bean:write") require you to specify the bean name, rather than 
> defaulting to the bean passed in, as other tags seem to do.  I could 
> not for the life of me figure out how to parameterize the bean name 
> and re-use the same JSP, and its tags, for ALL operations on an 
> object.

I think the nested taglib can help with this. They inherit the "name" 
attribute from the <nested:form> tag. So you don't need to specify it. 
There are nested versions of the tags you mention, except "log:debug".


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


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


Re: Re-using JSP pages

Posted by Will Jaynes <ja...@umich.edu>.

Charles McClain wrote:
>  <snip />
>  
> According to one of Ted Husted's tips, no problem; you can give a
> different form-bean name to the same ActionForm and reference that
> form-bean name in validation.xml.  And it works.  However, some of the
> tags on the actual JSP (for example, "logic:equal", which I use to vary
> the screen messages by operation, plus "log:debug" and "bean:write")
> require you to specify the bean name, rather than defaulting to the bean
> passed in, as other tags seem to do.  I could not for the life of me
> figure out how to parameterize the bean name and re-use the same JSP,
> and its tags, for ALL operations on an object.

I think the nested taglib can help with this. They inherit the "name" 
attribute from the <nested:form> tag. So you don't need to specify it. 
There are nested versions of the tags you mention, except "log:debug".


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