You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by PC Leung <pc...@gmail.com> on 2004/10/11 16:17:10 UTC

Struts and Tiles

I am very new Tiles.
I just want the content layout to change
and keep header, footer and left menu unchanged.

Is it right to change the value programmatically and how?
or
do it in another way?

<tiles:insert definition="erp.mainLayout" flush="true">
  <put name="body" value="/xxx.jsp" />
</tiles:insert>

Thank you very much.

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


Re: Struts and Tiles

Posted by Susan Bradeen <sb...@gmail.com>.
On Tue, 12 Oct 2004 11:59:10 +0800, PC Leung <pc...@gmail.com> wrote:
> How can I incorporate the tiles definition into struts-config.xml?
> or How to define selectBodyTile.do in struts-config.xml?
> 
> <tiles:insert definition="erp.mainLayout" flush="true"
> controller="/selectBodyTile.do"/>
> 
>     <action    path="/login"
>                type="com.security.user.LoginAction"
>                name="loginForm"
>                    scope="request"
>                    validate="true"
>                input="/Login.jsp">
>       <forward name="success" path="/SecurityMaint.jsp"/>
>       <forward name="failure" path="/Login.jsp"/>
>       <forward name="cancel" path="/Welcome.jsp"/>
>     </action>
>

I am not exactly sure what your are asking, but usually using Tiles
your forwards will point to a tile definition you have listed in your
tiles-defs.xml file. For example, instead of

<forward name="success" path="/SecurityMaint.jsp"/>

you might have

<forward name="success" path=".securityMaint"/>

where .securityMaint is defined as:

<definition name=".securityMaint" extends=".base">
    	<put name="title" value="Some Title"/>
    	<put name="content" value="/pages/SecurityMaint.jsp"/>
    </definition>

and the Base layout tile is defined as:

<definition name=".base" path="/tiles/layout.jsp">
    	<put name="title" value="${title}"/>
    	<put name="menu" value="/tiles/menu.jsp"/>
	 <put name="content" value="${content}"/>
    </definition>

Hth,
Susan Bradeen

> ---------------------------------------------------------------------
> 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: Struts and Tiles

Posted by PC Leung <pc...@gmail.com>.
How can I incorporate the tiles definition into struts-config.xml?
or How to define selectBodyTile.do in struts-config.xml?

<tiles:insert definition="erp.mainLayout" flush="true"
controller="/selectBodyTile.do"/>

    <action    path="/login"
               type="com.security.user.LoginAction"
               name="loginForm"
	           scope="request" 
	           validate="true" 
               input="/Login.jsp">
      <forward name="success" path="/SecurityMaint.jsp"/>
      <forward name="failure" path="/Login.jsp"/>
      <forward name="cancel" path="/Welcome.jsp"/>
    </action>



On Mon, 11 Oct 2004 17:49:55 +0100, Nigel Barrett
<nb...@pacemetrics.com> wrote:
> You can also use a controller class/action to do it
> 
> <tiles:insert definition="erp.mainLayout" flush="true"
> controller="/selectBodyTile.do"/>
> 
> and then in the action class for /selectBodyTile.do you can access the
> ComponentContext which will allow you to change the attributes before tiles
> does the insert thus allowing you to programmatically set the inner tile to
> be a JSP,another tile, etc. of your choice.
> 
> class SelectBodyControllerAction extends Action {
>    public ActionForward execute( ActionMapping mapping,
>                                               ActionForm form,
>                                               HttpServletRequest request,
>                                               HttpServletResponse response)
>     throws Exception {
> 
>        ComponentContext temp =
>            ComponentContext.getContext(request);
> 
>        if(isFullMoon(request)) {
>            temp.putAttribute("body", "fullmoon.jsp");
>        } else {
>            temp.putAttribute("body", "justanotherday.jsp");
>        }
> 
>        return super.execute(mapping, form, request, response);
>    }
> }
> 
> Controllers can also be a Derivative of TilesController which gives you the
> Context as a param
> 
> "Bj" <bj...@free.fr> wrote in message news:416AA1C7.6070802@free.fr...
> 
> 
> > you can use java to do this. For exemple, if you pass the boby url in
> > request parameter.
> >
> > <%
> > String contentUrl = request.getParameter("contentUrl");
> > if (contentUrl == null ) contentUrl = "/defaultContentUrl.jsp"
> > %>
> >
> > <tiles:insert definition="erp.mainLayout" flush="true">
> > <put name="body" value="<%=contentUrl%>" />
> > </tiles:insert>
> >
> > I hope there's a better way to do this (maybe through external tile xml
> > configuration files ) but I've never tried.
> >
> > Bj
> >
> > PC Leung a écrit :
> >
> > > I am very new Tiles.
> > > I just want the content layout to change
> > > and keep header, footer and left menu unchanged.
> > >
> > > Is it right to change the value programmatically and how?
> > > or
> > > do it in another way?
> > >
> > > <tiles:insert definition="erp.mainLayout" flush="true">
> > >   <put name="body" value="/xxx.jsp" />
> > > </tiles:insert>
> > >
> > > Thank you very much.
> > >
> > > ---------------------------------------------------------------------
> > > 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


Re: Struts and Tiles

Posted by Nigel Barrett <nb...@pacemetrics.com>.
You can also use a controller class/action to do it

<tiles:insert definition="erp.mainLayout" flush="true"
controller="/selectBodyTile.do"/>

and then in the action class for /selectBodyTile.do you can access the
ComponentContext which will allow you to change the attributes before tiles
does the insert thus allowing you to programmatically set the inner tile to
be a JSP,another tile, etc. of your choice.

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

        ComponentContext temp =
            ComponentContext.getContext(request);

        if(isFullMoon(request)) {
            temp.putAttribute("body", "fullmoon.jsp");
        } else {
            temp.putAttribute("body", "justanotherday.jsp");
        }

        return super.execute(mapping, form, request, response);
    }
}

Controllers can also be a Derivative of TilesController which gives you the
Context as a param



"Bj" <bj...@free.fr> wrote in message news:416AA1C7.6070802@free.fr...
> you can use java to do this. For exemple, if you pass the boby url in
> request parameter.
>
> <%
> String contentUrl = request.getParameter("contentUrl");
> if (contentUrl == null ) contentUrl = "/defaultContentUrl.jsp"
> %>
>
> <tiles:insert definition="erp.mainLayout" flush="true">
> <put name="body" value="<%=contentUrl%>" />
> </tiles:insert>
>
> I hope there's a better way to do this (maybe through external tile xml
> configuration files ) but I've never tried.
>
> Bj
>
> PC Leung a �crit :
>
> > I am very new Tiles.
> > I just want the content layout to change
> > and keep header, footer and left menu unchanged.
> >
> > Is it right to change the value programmatically and how?
> > or
> > do it in another way?
> >
> > <tiles:insert definition="erp.mainLayout" flush="true">
> >   <put name="body" value="/xxx.jsp" />
> > </tiles:insert>
> >
> > Thank you very much.
> >
> > ---------------------------------------------------------------------
> > 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: Struts and Tiles

Posted by Bj <bj...@free.fr>.
you can use java to do this. For exemple, if you pass the boby url in 
request parameter.

<%
	String contentUrl = request.getParameter("contentUrl");
	if (contentUrl == null ) contentUrl = "/defaultContentUrl.jsp"
%>

<tiles:insert definition="erp.mainLayout" flush="true">
	<put name="body" value="<%=contentUrl%>" />
</tiles:insert>

I hope there's a better way to do this (maybe through external tile xml 
configuration files ) but I've never tried.

Bj

PC Leung a écrit :

> I am very new Tiles.
> I just want the content layout to change
> and keep header, footer and left menu unchanged.
> 
> Is it right to change the value programmatically and how?
> or
> do it in another way?
> 
> <tiles:insert definition="erp.mainLayout" flush="true">
>   <put name="body" value="/xxx.jsp" />
> </tiles:insert>
> 
> Thank you very much.
> 
> ---------------------------------------------------------------------
> 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