Not sure if this will help, but here goes.  I have Form based JSPs that can
be used across multiple actions.  Therefore these JSPs have dynamic form
action attributes.  I didn't want to set the form action in the Action
class.  Instead I define it in struts-config.xml on a per action mapping
basis.

To accomplish this I could've used the parameter attribute of the action
mapping and then in my JSP do something like this:

<bean:define id="mapping" name="<%= org.apache.struts.Globals.MAPPING_KEY
%>"/>
<html:form action="<%= mapping.getParameter() %>" ...>

And in struts-config.xml have something like this:

<action path="/actionA" type="com.blah.FirstAction" name="myForm"
parameter="/actionX">
 <forward name="success" path="/myReusableFormPage.jsp"/>
</action>

<action path="/actionB" type="com.blah.SecondAction" name="myForm"
parameter="/actionY">
 <forward name="success" path="/myReusableFormPage.jsp"/>
</action>

However I also wanted the ability to apply other properties to action
mappings so the JSP could be generic.  Therefore instead of using the
parameter attribute I defined my own ActionMapping subclass and make use of
the set-property element of the action mapping.  My subclass has a single
Map property called "property".

public class PropertiesActionMapping extends ActionMapping {
    private Map property = new Hashtable();

    public PropertiesActionMapping() {
    }

    public Map getProperty() {
        return property;
    }

    public void setProperty(Map value) {
        property = value;
    }
}

Now in struts-config.xml I can do this:

<action path="/actionA" type="com.blah.FirstAction" name="myForm"
className="com.blah.PropertiesActionMapping">
 <set-property property="property(titleKey)" value="actionX.title"/>
 <set-property property="property(formAction)" value="/actionX"/>
 <forward name="success" path="/myReusableFormPage.jsp"/>
</action>

<action path="/actionB" type="com.blah.SecondAction" name="myForm"
className="com.blah.PropertiesActionMapping">
 <set-property property="property(titleKey)" value="actionY.title"/>
 <set-property property="property(formAction)" value="/actionY"/>
 <forward name="success" path="/myReusableFormPage.jsp"/>
</action>

And now the JSP looks like this:

<bean:define id="mapping" name="<%= org.apache.struts.Globals.MAPPING_KEY
%>"/>

<title><bean:message name="mapping" property="property(titleKey)"/></title>
...
<html:form action='<%= mapping.getProperty("formAction") %>' ...>

The code I've shown above isn't actually how I do it since I'm using the
JSTL-EL.

HTH
Jerome

> -----Original Message-----
> From: PILGRIM, Peter, FM [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 24, 2003 10:44 AM
> To: 'Struts Users Mailing List'
> Subject: RE: [TILES] Foxy Tiles Problem
>
>
> > -----Original Message-----
> > From: Vic Cekvenich [mailto:[EMAIL PROTECTED]
> >
> > One thing that might help you is this, Tiles 201, that basicaly has a
> > controler for each tile, with it's own setup, it should give you good
> > ideas, else repost.
> > http://blogs.browsermedia.com/patrick/index.do?date=20030211#130200
> >
>
> --////--
>
> Actually I do not see how Tiles Controller can help me here.
>
> I think what I need to is pass an JSP request parameter to the
> <html:form> in some form or the other.
>
> If this is my tiles layout file, which I reference from Tile
> definitions or <tiles:insert page="..." /, then I want the
> action attribute to be set dynamically.
>
> // file: /tiles/layout.jsp
> <html:form action=<%= pageContext.findAttribute("actionToLaunch") %>" >
>       <tiles:insert attribute="form-header" />
>       <tiles:insert attribute="tab-navigation" />
>       ...
> </html:form>
>
> In a JSP I can refer to Tiles Layout
>
> <tiles:insert page="/tiles/layout.jsp" >
>     <tiles:put name="form-header"  value="form-header.jsp" />
>     <tiles:put name="tab-navigation"  value="navbar.jsp" />
>
>       <%-- // Some how set the request parameter `actionToLaunch' here
> --%>
>
>       ...
> </tiles:insert>
>
> I think a Tiles Controller is a overkill for such a simple request.
>
> >
> > PILGRIM, Peter, FM wrote:
> > > Hi
> > >
> > > I got a Tiles template design question. I have a web site
> > like Amazon.com
> > > that
> > > using Tabs to navigate around a set of HTML Form elements.
> > Each Page has a
> > > HTML Form that contain lots of HTML Input elements. I have
> > written the JSP
> > > in the first phase to be monolithic and now I want to break down the
> > > layout to use Tiles.
> > >
> > > I want to take advantage of the fact, that certain areas of
> > the layout
> > > design are shared. Unfortunately I have run in to
> > difficulty because
> > > they want a specific design that forces me to run an
> > <html:form> outside
> > > all the shareable and non-shareable tiles.
> > >
> > > Ideally, I would like to dynamically set the name of the
> > `action' tag
> > > of <html:form> below. I would like to say action="/Main.do"
> > and then
> > > action="/Shipping.do" for a single template layout. How can
> > I do this,
> > > using TILES? Otherwise I will have to create template layouts
> > > for each tab page. (Yuck)
> > >
> > > Also is it good practice to have template layout within
> > templates layout?
> > >
> > >
> > > // This is a template layout.jsp
> > >
> > > <!-- Search form -->
> > > <tiles:insert attribute="customer-search-form" />
> > >   <%-- e.g. ``customerSearchPrompt.jsp'' grabs a CRM record
> > >           from database. This tile is common to all
> > >           tabbed pages
> > >   --%>
> > >
> > > <html:form action="..." />
> > >
> > >      <!-- Order Type and Id -->
> > >      <tiles:insert attribute="form-header" />
> > >   <%-- e.g. `sectionHeaderType.jsp' common to all tabs --%>
> > >
> > >      <!-- Core Tab Navigation -->
> > >      <tiles:insert attribute="tab-navigation" />
> > >   <%-- e.g. `tabNavigation.jsp' common to all tabs -->
> > >
> > >      <!-- Form area -->
> > >      <tiles:insert attribute="form-content" />
> > >   <%-- e.g.``MainTab.jsp'', ``ShippingTab.jsp''
> > >           this is the heart of the form entry area.
> > >           This tile will change from tab page to tab page.
> > >   --%>
> > >
> > >      <!-- Form action -->
> > >      <tiles:insert attribute="form-action" />
> > >   <%-- e.g. `MainActions.jsp'', ``ShippingActions.jsp''
> > >           Each tab page shares a set of common buttons,
> > >           but has it possible for a tab page to have its
> > >           own custom buttons.
> > >           This tile will change from tab page to tab page.
> > >   --%>
> > >
> > > </html:form>
> > >
> > > Any ideas appreciated, MTIA
>
> --////--
>
> --
> Peter Pilgrim,
> Struts/J2EE Consultant, RBoS FM, Risk IT
> Tel: +44 (0)207-375-4923
>
>
> ********************************************************************
>       Visit our Internet site at http://www.rbsmarkets.com
>
> This e-mail is intended only for the addressee named above.
> As this e-mail may contain confidential or privileged information,
> if you are not the named addressee, you are not authorised to
> retain, read, copy or disseminate this message or any part of it.
> The Royal Bank of Scotland plc is registered in Scotland No 90312
> Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
> Regulated by the Financial Services Authority
> ********************************************************************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


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

Reply via email to