You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Friedman <hu...@ix.netcom.com> on 2006/06/09 08:21:02 UTC

RE: tiles and forwards

Where do you define the tiles? (Filename)
How did you specify the filename to the tiles request processor/struts
config?

-DAvid

-----Original Message-----
From: rula2005 [mailto:rudolf_lang@gmx.de]
Sent: Friday, June 09, 2006 3:06 AM
To: user@struts.apache.org
Subject: tiles and forwards


Hi,

I use struts 1.2 with tiles.

There are a template layout.jsp, a tile locale.jsp and 2 tileDefinitions
a.page and b.page.
With the org.apache.struts.actions.LocaleAction there are problems.

In the locale.jsp: (language switch)

  <html:select property="language" size="1">
   <html:option key="label.de" value="de"/>
   <html:option key="label.en" value="en"/>
  </html:select>
  <html:hidden property="page" value="a.page"/>

If the page attribute is set to a tilesDefintions it works, but if not
occurs a exception:

In the struts-config-xml:

<action path="/processLanguage"
    name="languageForm"
    type="org.apache.struts.actions.LocaleAction">
    <forward name="success" path="b.page"/>
</action>

java.lang.IllegalArgumentException: Path does not start with a "/" character
at
org.apache.catalina.core.ApplicationContext.getRequestDispatcher(Application
Context.java:377)

at
org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(Appli
cationContextFacade.java:198)

at
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:10
56)

at
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcesso
r.java:263)

at
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProces
sor.java:386)

at
org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequ
estProcessor.java:318)

at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)

1.What is wrong? Why is the forward to the tilesDefinition b.page not valid
?
I test it with it with a action and jsp as pathAttribute (witch starts with
a "/") but the same Exception occurs.

2.How can I get the actual tilesDefintion in the jsp (local.jsp) (Perhaps
with jstl-core and EL)
or in the action (LocaleAction.java) to set the pageAttribute to forward to.

Best Regards rula


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by rula2005 <ru...@gmx.de>.
What expect you with the returned ActionForward?

Is the pageAttribute correct set in the jsp like:

  <html:select property="language" size="1">
   <html:option key="label.de" value="de"/>
   <html:option key="label.en" value="en"/>
  </html:select>
  <html:hidden property="page" value="a.page"/>

the forward works well with the tilesDefinition, but if not,
the forward in struts-config do not work well with the tileDefinition.

----- Original Message ----- 
From: "Antonio Petrelli" <br...@tariffenet.it>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, June 09, 2006 12:45 PM
Subject: Re: tiles and forwards


> Can you post the code of your action? At least the part when you return 
> the forward in the "execute" method? I have a suspect.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by rula2005 <ru...@gmx.de>.
Correct, i used the internal strutsAction:
org.apache.struts.actions.LocaleAction and the source could something like this,
which i found in the validator struts-example:

    public ActionForward execute(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
    throws Exception {

    // Extract attributes we will need
    HttpSession session = request.getSession();
    Locale locale = getLocale(request);

    String language = null;
    String country = null;
    String page = null;

    try {
            language = (String)
              PropertyUtils.getSimpleProperty(form, "language");
            country = (String)
              PropertyUtils.getSimpleProperty(form, "country");
            page = (String)
              PropertyUtils.getSimpleProperty(form, "page");
        } catch (Exception e) {
           log.error(e.getMessage(), e);
        }

        if ((language != null && language.length() > 0) &&
            (country != null && country.length() > 0)) {
           locale = new java.util.Locale(language, country);
        } else if (language != null && language.length() > 0) {
           locale = new java.util.Locale(language, "");
    }

        session.setAttribute(Globals.LOCALE_KEY, locale);

        if (null==page) return mapping.findForward("success");
        else return new ActionForward(page);

    }

}
----- Original Message ----- 
From: "Antonio Petrelli" <br...@tariffenet.it>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, June 09, 2006 1:00 PM
Subject: Re: tiles and forwards


> Antonio Petrelli ha scritto:
>> Can you post the code of your action? At least the part when you 
>> return the forward in the "execute" method? I have a suspect.
> 
> Uh sorry, I didn't notice that you used an internal Struts action!
> Anyway let me think about it
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Getting the definition a tile is in (WAS: tiles and forwards)

Posted by Antonio Petrelli <br...@tariffenet.it>.
I am starting a new thread to rephrase a question from Rudolph Lang, so 
that other users can see this question, because I don't know the answer.
Rudolph Lang (and I am pretty curious about the answer :-) ) wants to 
know if there is a way to get the Tiles definition that contains the 
current JSP page from the JSP page itself.
For instance given the definition:

<!--snip -->
<definition name="main.layout" path="/pages/layout.jsp">

<put name="title" value="baseTitle"/>
<put name="locale" value="/pages/locale.jsp"/>
<!-- some other stuff -->
</definition>
<!--snap -->

Can the "locale.jsp" page know that it is the "main.layout" definition 
from the inside the JSP page itself?

I hope that someone else can answer his question.
Ciao
Antonio


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Getting the definition a tile is in (WAS: tiles and forwards)

Posted by Antonio Petrelli <br...@tariffenet.it>.
Sorry, for a mistake I hijacked my own thread! Ugh

I am starting a new thread to rephrase a question from Rudolph Lang, so
that other users can see this question, because I don't know the answer.
Rudolph Lang (and I am pretty curious about the answer :-) ) wants to
know if there is a way to get the Tiles definition that contains the
current JSP page from the JSP page itself.
For instance given the definition:

<!--snip -->
<definition name="main.layout" path="/pages/layout.jsp">

<put name="title" value="baseTitle"/>
<put name="locale" value="/pages/locale.jsp"/>
<!-- some other stuff -->
</definition>
<!--snap -->

Can the "locale.jsp" page know that it is the "main.layout" definition
from the inside the JSP page itself?

I hope that someone else can answer his question.
Ciao
Antonio


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by Rudolf Lang <ru...@gmx.de>.
> Do you mean that you want to get the definition the file "locale.jsp" is 
> in? If yes I think it is better to start a new thread, because I don't 
> know the answer and I would like someone else to see this question.
> Otherwise, please explain what you mean.

That's exactly what i mean, thanks.

Rudolf


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by Antonio Petrelli <br...@tariffenet.it>.
Rudolf Lang ha scritto:
> The next is, how can I get the actual tilesDefintion in the locale.jsp 
> (perhaps by jstl and EL)
> or in the LocaleAction.java ?

Do you mean that you want to get the definition the file "locale.jsp" is 
in? If yes I think it is better to start a new thread, because I don't 
know the answer and I would like someone else to see this question.
Otherwise, please explain what you mean.

Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by Rudolf Lang <ru...@gmx.de>.
> Antonio Petrelli ha scritto:
> Can you post the code of your action? At least the part when you 
> return the forward in the "execute" method? I have a suspect.

Now I use my own LocaleAction (extends Action !) with the following returns :

    if (page != null && page.length() > 0)
     return new ActionForward(page);
    else return mapping.findForward("success");

and this works and no exception occurs, if the pageAttribute not exist.

The next is, how can I get the actual tilesDefintion in the locale.jsp (perhaps by jstl and EL)
or in the LocaleAction.java ?

This is important, because the tile locale.jsp do the languageSwitch and is part of every page.
So, after the languageSwitch I have to forward to the actual tilesDefinition (to stay in the page).

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by Antonio Petrelli <br...@tariffenet.it>.
Antonio Petrelli ha scritto:
> Can you post the code of your action? At least the part when you 
> return the forward in the "execute" method? I have a suspect.

Uh sorry, I didn't notice that you used an internal Struts action!
Anyway let me think about it

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by Antonio Petrelli <br...@tariffenet.it>.
rula2005 ha scritto:
> Hi, sorry, i misunderstood the meaning of "specified filename",
> i have already used the tiles-plugin with the tiles-def.xml in the 
> struts-config.xml like this:
>
>    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
>
>      <!-- Path to XML definition file -->
>      <set-property property="definitions-config"
>          value="/WEB-INF/tiles-defs.xml" />
>      <!-- Set Module-awareness to true -->
>      <set-property property="moduleAware" value="true" />
>    </plug-in>
>

Mmm... this is strange...
Can you post the code of your action? At least the part when you return 
the forward in the "execute" method? I have a suspect.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by rula2005 <ru...@gmx.de>.
Hi, 
sorry, i misunderstood the meaning of "specified filename",
i have already used the tiles-plugin with the tiles-def.xml in the struts-config.xml like this:

    <plug-in className="org.apache.struts.tiles.TilesPlugin" >

      <!-- Path to XML definition file -->
      <set-property property="definitions-config"
          value="/WEB-INF/tiles-defs.xml" />
      <!-- Set Module-awareness to true -->
      <set-property property="moduleAware" value="true" />
    </plug-in>

Tiles works well with the ForwardAction like:

<action path="/viewA"
    type="org.apache.struts.actions.ForwardAction"
parameter="a.page"/>

but not with the LocaleAction like:

   <action path="/processLanguage"
    name="languageForm"
    type="org.apache.struts.actions.LocaleAction">
    <forward name="success" path="b.page"/>
   </action>   

when the pageAttribute in the jsp is not set and the forward in the struts-config is used.
Then occurs the following exception:

java.lang.IllegalArgumentException: Path does not start with a "/" character

I am confused, because I use tiles an so I can take the tilesDefinition as pathAttribute.

But the requestProcessor( not the TilesRequestProcessor ) has a Problem with this.

at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:377)
at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:198)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)

regards rula

----- Original Message ----- 
From: "Antonio Petrelli" <br...@tariffenet.it>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, June 09, 2006 8:08 AM
Subject: Re: tiles and forwards


> rula2005 ha scritto:
>> I specified no filenames in struts-config.xml
> 
> That's funny, how do you think that Tiles knows what definition file to use?
> 
> http://struts.apache.org/struts-action/struts-tiles/installation.html
> 
> As you can see it states:
> 
>    * *Using Tiles With Struts Action* - You will also need to configure
>      the Tiles Plugin and the Tiles Request Processor to allow the
>      framework to respond to Tiles-based Action Forwards. Below is a
>      sample Tiles Plugin configuration.
> 
>          <plug-in className="org.apache.struts.tiles.TilesPlugin">
>          <set-property
>              property="definitions-config"
>                 value="/WEB-INF/tiles-defs.xml"/>
>          </plug-in>
>          
> 
> 
> HTH
> Antonio
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by Antonio Petrelli <br...@tariffenet.it>.
rula2005 ha scritto:
> I specified no filenames in struts-config.xml

That's funny, how do you think that Tiles knows what definition file to use?

http://struts.apache.org/struts-action/struts-tiles/installation.html

As you can see it states:

    * *Using Tiles With Struts Action* - You will also need to configure
      the Tiles Plugin and the Tiles Request Processor to allow the
      framework to respond to Tiles-based Action Forwards. Below is a
      sample Tiles Plugin configuration.

          <plug-in className="org.apache.struts.tiles.TilesPlugin">
          <set-property
              property="definitions-config"
                 value="/WEB-INF/tiles-defs.xml"/>
          </plug-in>
          


HTH
Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: tiles and forwards

Posted by rula2005 <ru...@gmx.de>.
Hi David,

I defined the tiles in a tiles-def.xml:
<definition name="main.layout" path="/pages/layout.jsp">

<put name="title" value="baseTitle"/> 

<put name="header" value="/pages/header.jsp"/>

<put name="locale" value="/pages/locale.jsp"/> 

<put name="menu" value="/pages/menu.jsp"/> 

<put name="body" value=""/> 

<put name="footer" value="/pages/footer.jsp"/>

<put name="copywrite" value="copyWriteBy"/> 

</definition>

<definition name="a.page" extends="main.layout">

<put name="title" value="aTitle"/> 

<put name="body" value="/pages/bodyA.jsp"/> 

</definition>

<definition name="b.page" extends="main.layout">

<put name="title" value="bTitle"/> 

<put name="body" value="/pages/bodyB.jsp"/> 

</definition>

I specified no filenames in struts-config.xml only the forward:

<action path="/processLanguage"

name="languageForm"

type="org.apache.struts.actions.LocaleAction">

<forward name="success" path="b.page"/>

</action> 

regards rula

----- Original Message ----- 
From: "David Friedman" <hu...@ix.netcom.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, June 09, 2006 7:21 AM
Subject: RE: tiles and forwards


> Where do you define the tiles? (Filename)
> How did you specify the filename to the tiles request processor/struts
> config?
> 
> -DAvid
> 
> -----Original Message-----
> From: rula2005 [mailto:rudolf_lang@gmx.de]
> Sent: Friday, June 09, 2006 3:06 AM
> To: user@struts.apache.org
> Subject: tiles and forwards
> 
> 
> Hi,
> 
> I use struts 1.2 with tiles.
> 
> There are a template layout.jsp, a tile locale.jsp and 2 tileDefinitions
> a.page and b.page.
> With the org.apache.struts.actions.LocaleAction there are problems.
> 
> In the locale.jsp: (language switch)
> 
>  <html:select property="language" size="1">
>   <html:option key="label.de" value="de"/>
>   <html:option key="label.en" value="en"/>
>  </html:select>
>  <html:hidden property="page" value="a.page"/>
> 
> If the page attribute is set to a tilesDefintions it works, but if not
> occurs a exception:
> 
> In the struts-config-xml:
> 
> <action path="/processLanguage"
>    name="languageForm"
>    type="org.apache.struts.actions.LocaleAction">
>    <forward name="success" path="b.page"/>
> </action>
> 
> java.lang.IllegalArgumentException: Path does not start with a "/" character
> at
> org.apache.catalina.core.ApplicationContext.getRequestDispatcher(Application
> Context.java:377)
> 
> at
> org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(Appli
> cationContextFacade.java:198)
> 
> at
> org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:10
> 56)
> 
> at
> org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcesso
> r.java:263)
> 
> at
> org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProces
> sor.java:386)
> 
> at
> org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequ
> estProcessor.java:318)
> 
> at
> org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
> 
> at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
> 
> at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
> 
> 1.What is wrong? Why is the forward to the tilesDefinition b.page not valid
> ?
> I test it with it with a action and jsp as pathAttribute (witch starts with
> a "/") but the same Exception occurs.
> 
> 2.How can I get the actual tilesDefintion in the jsp (local.jsp) (Perhaps
> with jstl-core and EL)
> or in the action (LocaleAction.java) to set the pageAttribute to forward to.
> 
> Best Regards rula
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org