Hi David,

I think the fundamental problem here is that global-forwards are not
available to be called from outside the server. If one considers the URL one
might use to call global-forwards, e.g.:

        http://myHost/myApp/myForward

... then this will not be passed-to struts - and will instead look for a
servlet mapping matching the "myForward" pattern - and probably won't find
one.

If you look at the result of a global-forwards/forward generated by say:

        <html:link forward="myForward">Forward Me!</html:link>

... e.g. where the following configures the forward in struts-config to
forward to the "myAction" action:

        ...
        <global-forwards>
                ...
                <forward name="myForward" path="/do/myAction" />
                ...
        </global-forwards>
        ...

... then it will likely be of the form when rendered to HTML:

        <a href="/do/myAction">Forward Me!</a>

... then this _will_ go through the struts servlet and be correctly mapped
to an action.

If you wanted a way of configuring a method of calling any tiles def from a
jsp then one option would be to have a generic action than can fwd to the
tiles def, e.g. define a bean and action in struts-config:

        ...
        <form-beans>
                ...
                <form-bean name="tilesDef" 
type="org.apache.struts.action.DynaActionForm">
                        <form-property name="tilesDef" type="java.lang.String" />
                </form-bean>
                ...
        </form-beans>
        ...

        ...
        <action-mappings>
                ...
                <action path="/tilesDefFwd"
                        type="tld.domain.actions.TilesDefFwdAction"
                        name="tilesDef"
                        scope="request">
                        <forward
                                name="tiles-def-not-passed"
                                path="/error-tiles-def-not-passed.jsp" />
                </action>
                ...
        </action-mappings>
        ...

The action code would look like this (ok, error handling could be a bit
tighter(!)) but this gives the idea:

package tld.domain.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletContext;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import org.apache.struts.action.DynaActionForm;

public final class TilesDefFwdAction extends Action {

    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
                                 throws Exception {
        String tilesDef = "";
        // Get our parameter(s) from the form
        DynaActionForm dynaForm = (DynaActionForm) form;
        try {
            tilesDef = dynaForm.get("tilesDef").toString();
        } catch (Exception ex) {
            // Something went wrong - send to error page
            return ( mapping.findForward("tiles-def-not-passed") );
        }
        // Forward to tiles def
        return ( new ActionForward(tilesDef,false) );
    }
}

This would then allow a URL of the following format, e.g:

        http://www.domain.tld/myApp/do/tilesDefFwd?tilesDef=myDef

... that would then forward to the tiles def "myDef", e.g.

        <html:link page="/do/tilesDefFwd?tilesDef=myDef">Forward Me To Tiles
Def!</html:link>

Alternatively, there may already be a mechanism to do this natively in
struts - but have attached the above code as this is what I wrote when I was
getting to grips with forwards/actions/tiles-defs etc - and hopefully it
will be of some help!

Hue.

> -----Original Message-----
> From: David Holtzhouser [mailto:[EMAIL PROTECTED]
> Sent: 15 August 2003 14:57
> To: [EMAIL PROTECTED]
> Subject: Global Forwards and Tiles
>
>
> I've attached a discussion with a fellow developer
> regarding Global Forwards and Tiles.  The tiles-defs
> are in xml if that makes any difference.
>
>      *****************************************
>  Here's the delima. I can configure a Global Forward
> that maps to my tiles definition. If I refer to this
> global forward from an Action then it finds my tile
> def. But, If I call this global forward from a jsp,
> then it craps out. But normally you can call a global
> forward from a JSP and it will work fine, as long as
> you are not using tiles defs. So, it seems like if I
> want to get from one JSP to another tiles def, then I
> have to go through a Action, which could be a
> ForwardAction. My Actions can use my global forwards,
> but my pages cannot. It's kind of weird, but I at
> least I understand what I can and can't do now.
>       *****************************************
>
> So are thought is that Global ActionForwards defined
> in the <global-forwards> section of the
> struts-config.xml really don't go through the
> ActionServlet at all, or somehow skip allowing the
> ActionServlet's, RequestProcessor delegate:
>
> <controller
> processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
>
> to handle it.
>
> Can anyone provide clarification on this?
>
> Thanks
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003


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

Reply via email to