You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <st...@reumann.net> on 2005/01/24 23:18:01 UTC

Best practice for dynamic Title values using Tiles?

I'm switching back to using Tiles instead of Sitemesh and I remember one 
issue that I found annoying with Tiles and I'd be curious how you guys 
handle it. Say I have a form that is going to be reused for both "Edit" 
and "Add." I want the <title> attribute to read something like "Add 
Employee" or "Edit Employee," depending on what I'm doing. It seems 
silly to have to create multiple definitions in my tiles-definitions 
that are essentially the same exact definition except that the title has 
changed (potentially you might want a definition to be used for more 
than just the two that I mentioned). This also requires that my struts 
config has to be set up to forward to multiple tiles definitions when 
its really the same page layout but with a different title and could 
really just require one definition to use.

I've thought of different ways I might want to handle this (ie set a 
title in request scope before leaving action and have the header.jsp 
look for this, or maybe use a filter or over-ride RequestProcessor?) I'm 
curious if others have run into this. Maybe the latest Struts/Tiles has 
a solution that I have not looked into.

Thanks

-- 
Rick

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


Re: Best practice for dynamic Title values using Tiles?

Posted by Rick Reumann <st...@reumann.net>.
Phil Steitz wrote the following on 1/24/2005 7:25 PM:

> <tiles:put name='title' type="string">
>     <logic:equal name="bookForm" property="action"
>             scope="request" value="Create">
>         <bean:message key="book.title.create"/>
>     </logic:equal>
>     <logic:equal name="bookForm" property="action"
>             scope="request" value="Update">
>         <bean:message key="book.title.update"/>
>     </logic:equal>
> </tiles:put>
> 
> May not be the best, but keeps display stuff separate.

This would be way to combersome since the title will be displayed in a 
reusable header page. The result would be that you'd have to code one 
huge long logic construct to decide what to display for the title for 
every possible action.

I'm not totally opposed to using the request approach mentioned where I 
stuff a "title" attribute into the request in the Action and can then 
display it on the page...

<title>${title}</title>

however, I'm starting to lean towards adding redundant code in the tiles 
config. At least all the titles will be in one place. Unfortunately this 
also requires me to have unique action forward mappings so that the 
correct tiles definition will be called. So I can't just have the 
forward go to a default myForm.page for both edit and add. I have to use 
edit.form.page and add.form.page simply so that the tiles defintion can 
add the correct title even though I'm going to the same JSP.

I'm still torn on which approach to use:)


-- 
Rick

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


Re: Best practice for dynamic Title values using Tiles?

Posted by Igor Shabalov <ig...@exadel.com>.
You need to send some parameter to the page in order to determine what 
to display. The determination logic can be put into tile controller class.


Phil Steitz wrote:

> Rick Reumann wrote:
>
>> I'm switching back to using Tiles instead of Sitemesh and I remember 
>> one issue that I found annoying with Tiles and I'd be curious how you 
>> guys handle it. Say I have a form that is going to be reused for both 
>> "Edit" and "Add." I want the <title> attribute to read something like 
>> "Add Employee" or "Edit Employee," depending on what I'm doing. It 
>> seems silly to have to create multiple definitions in my 
>> tiles-definitions that are essentially the same exact definition 
>> except that the title has changed (potentially you might want a 
>> definition to be used for more than just the two that I mentioned). 
>> This also requires that my struts config has to be set up to forward 
>> to multiple tiles definitions when its really the same page layout 
>> but with a different title and could really just require one 
>> definition to use.
>>
>> I've thought of different ways I might want to handle this (ie set a 
>> title in request scope before leaving action and have the header.jsp 
>> look for this, or maybe use a filter or over-ride RequestProcessor?) 
>> I'm curious if others have run into this. Maybe the latest 
>> Struts/Tiles has a solution that I have not looked into.
>
>
> If you already have an "action" parameter or somesuch on the form, you 
> can just use that -- e.g.:
>
> <tiles:put name='title' type="string">
>     <logic:equal name="bookForm" property="action"
>             scope="request" value="Create">
>         <bean:message key="book.title.create"/>
>     </logic:equal>
>     <logic:equal name="bookForm" property="action"
>             scope="request" value="Update">
>         <bean:message key="book.title.update"/>
>     </logic:equal>
> </tiles:put>
>
> May not be the best, but keeps display stuff separate.
>
> Phil
>
>>
>> Thanks
>>
>
>
> ---------------------------------------------------------------------
> 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: Best practice for dynamic Title values using Tiles?

Posted by Phil Steitz <ph...@steitz.com>.
Rick Reumann wrote:
> I'm switching back to using Tiles instead of Sitemesh and I remember one 
> issue that I found annoying with Tiles and I'd be curious how you guys 
> handle it. Say I have a form that is going to be reused for both "Edit" 
> and "Add." I want the <title> attribute to read something like "Add 
> Employee" or "Edit Employee," depending on what I'm doing. It seems 
> silly to have to create multiple definitions in my tiles-definitions 
> that are essentially the same exact definition except that the title has 
> changed (potentially you might want a definition to be used for more 
> than just the two that I mentioned). This also requires that my struts 
> config has to be set up to forward to multiple tiles definitions when 
> its really the same page layout but with a different title and could 
> really just require one definition to use.
> 
> I've thought of different ways I might want to handle this (ie set a 
> title in request scope before leaving action and have the header.jsp 
> look for this, or maybe use a filter or over-ride RequestProcessor?) I'm 
> curious if others have run into this. Maybe the latest Struts/Tiles has 
> a solution that I have not looked into.

If you already have an "action" parameter or somesuch on the form, you 
can just use that -- e.g.:

<tiles:put name='title' type="string">
     <logic:equal name="bookForm" property="action"
             scope="request" value="Create">
         <bean:message key="book.title.create"/>
     </logic:equal>
     <logic:equal name="bookForm" property="action"
             scope="request" value="Update">
         <bean:message key="book.title.update"/>
     </logic:equal>
</tiles:put>

May not be the best, but keeps display stuff separate.

Phil

> 
> Thanks
> 


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


Re: Best practice for dynamic Title values using Tiles?

Posted by Vic <vi...@friendvu.com>.
What I would do is put in request context anything that I minght need. 
My action decided what to display and puts it in scope.

Then in jsp and tiles tag I would use el to display the named variables.


(90% of code for 1up.com (that is all tiles) is here: 
http://sourceforge.net/projects/infonoia (similar to my free training 
videos from struts wiki))

hth,
.V



Rick Reumann wrote:

> I'm switching back to using Tiles instead of Sitemesh and I remember 
> one issue that I found annoying with Tiles and I'd be curious how you 
> guys handle it. Say I have a form that is going to be reused for both 
> "Edit" and "Add." I want the <title> attribute to read something like 
> "Add Employee" or "Edit Employee," depending on what I'm doing. It 
> seems silly to have to create multiple definitions in my 
> tiles-definitions that are essentially the same exact definition 
> except that the title has changed (potentially you might want a 
> definition to be used for more than just the two that I mentioned). 
> This also requires that my struts config has to be set up to forward 
> to multiple tiles definitions when its really the same page layout but 
> with a different title and could really just require one definition to 
> use.
>
> I've thought of different ways I might want to handle this (ie set a 
> title in request scope before leaving action and have the header.jsp 
> look for this, or maybe use a filter or over-ride RequestProcessor?) 
> I'm curious if others have run into this. Maybe the latest 
> Struts/Tiles has a solution that I have not looked into.
>
> Thanks
>


-- 
Forums, Boards, Blogs and News in RiA <http://www.boardVU.com>


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


Re: Best practice for dynamic Title values using Tiles?

Posted by Rick Reumann <st...@reumann.net>.
Dakota Jack wrote the following on 1/25/2005 2:11 AM:
> I just have a <c:out value='state.title'/> and feed the appropriate
> value to the request.  State is a class as follows:
> 
> public class StateContainer
>     implements Map {
>   private Map map;

<snip>

The whole problem with these suggestions to use the Request for putting 
in a title in your Action (even if it's putting it in your State map) is 
that it seems a shame that your controller now has to worry about what 
to display. It's just one more annoyance to have to deal with. It's sort 
of funny also because we often work so diligently to use all 
tags/JSTL/EL on the page and no scriplets with the impetus for this 
movement often driven by the theory that web designers wouldn't have to 
deal with Java code (I know never works that way:). Now, though, with 
the 'title' problem I've brought up, a web designer has to actually dig 
into an Action class to make sure the correct title is being set - much 
more of a pain than even dealing with scriplets imo.

-- 
Rick

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


Re: Best practice for dynamic Title values using Tiles?

Posted by Dakota Jack <da...@gmail.com>.
I just have a <c:out value='state.title'/> and feed the appropriate
value to the request.  State is a class as follows:

public class StateContainer
    implements Map {
  private Map map;

  public StateContainer() {
    int size = 89;
    this.map = Collections.synchronizedMap(new HashMap(size));
  }

  public void   setStateContainerMap(Map map)                       {
this.map = map; }
  public void   setProperty(Object key, Object value) { map.put(key,value); }
  public Map    getStateContainerMap()                              {
return map; }
  public Object getProperty(Object key)               { return map.get(key); }

  public StateContainer putState(String key, Object value) {
    this.put(key,value);
    return this;
  }

  public void       clear()                       { map.clear(); }
  public boolean    containsKey(Object key)       { return
map.containsKey(key);}
  public boolean    containsValue(Object value)   { return
map.containsValue(value); }
  public Set        entrySet()                    { return map.entrySet(); }
  public boolean    equals(Object object)         { return map.equals(object); }
  public Object     get(Object key)               { return map.get(key); }
  public int        hashCode()                    { return map.hashCode(); }
  public boolean    isEmpty()                     { return map.isEmpty(); }
  public Set        keySet()                      { return map.keySet(); }
  public Object     put(Object key, Object value) { return map.put(key,value); }
  public void       putAll(Map map)               { map.putAll(map); }
  public Object     remove(Object key)            { return map.remove(key); }
  public int        size()                        { return map.size(); }
  public Collection values()                      { return map.values(); }
  public String     toString()                    { return
"StateContainer[map=" + map.toString() + "]"; }
}

Whatever values the page author wants to be dynamic can be assumed to
be in state.  Then, the Action author can make sure that the values
are there.

There is, by the way, good reason to use the composite pattern here. 
I have discussed that before so I won't repeat it.

Jack


On Mon, 24 Jan 2005 17:18:01 -0500, Rick Reumann <st...@reumann.net> wrote:
> I'm switching back to using Tiles instead of Sitemesh and I remember one
> issue that I found annoying with Tiles and I'd be curious how you guys
> handle it. Say I have a form that is going to be reused for both "Edit"
> and "Add." I want the <title> attribute to read something like "Add
> Employee" or "Edit Employee," depending on what I'm doing. It seems
> silly to have to create multiple definitions in my tiles-definitions
> that are essentially the same exact definition except that the title has
> changed (potentially you might want a definition to be used for more
> than just the two that I mentioned). This also requires that my struts
> config has to be set up to forward to multiple tiles definitions when
> its really the same page layout but with a different title and could
> really just require one definition to use.
> 
> I've thought of different ways I might want to handle this (ie set a
> title in request scope before leaving action and have the header.jsp
> look for this, or maybe use a filter or over-ride RequestProcessor?) I'm
> curious if others have run into this. Maybe the latest Struts/Tiles has
> a solution that I have not looked into.
> 
> Thanks
> 
> --
> Rick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
------------------------------

"You can lead a horse to water but you cannot make it float on its back."

~Dakota Jack~

"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

-----------------------------------------------

"This message may contain confidential and/or privileged information.
If you are not the addressee or authorized to receive this for the
addressee, you must not use, copy, disclose, or take any action based
on this message or any information herein. If you have received this
message in error, please advise the sender immediately by reply e-mail
and delete this message. Thank you for your cooperation."

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


Re: [OT] Re: Best practice for dynamic Title values using Tiles?

Posted by Rick Reumann <st...@reumann.net>.
Erik Weber wrote the following on 1/24/2005 10:47 PM:
> Hello Rick. Happy New Year to you. I'm just curious. Why are you 
> switching? I remember you advocating Sitemesh (I think it was on your 
> site) instead of Tiles at some point. I haven't tried either one yet, 
> but was going to try Sitemesh based largely on your recommendation, 

The reason I'm switching is that some of the pages we display can 
possibly be very very large in size (reporting information). SitemMesh 
has to store the entire response as a String in an object (I think 
backed as StringBuffer but not positive). So you can see the problem if 
you potentially have a huge page to display. Locally, I actually crashed 
my version of Tomcat when trying to render a page since it ran out of 
memory when trying to buffer such a large page. Tiles doesn't have this 
problem since it flushes the response out as it goes along. Tiles, 
although more work to configure, saves me from having to worry about 
these potential memory problems.

-- 
Rick

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


RE: [OT] Re: Best practice for dynamic Title values using Tiles?

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
+1 on Erik's request.

I sometimes go about things the wrong way.  I was thinking I should use
SiteMesh to figure out which HTML page to use as the final layout for each
virtual host (the SiteMesh decorator I'm going to write will figure that out
and make sure it exists) OR use tiles with div's plus a CSS to lay out the
locations of the divs.  The SiteMesh option will work with older browsers
who aren't handy with CSS but the tiles+div+CSS option would be much more
modern.  I could then use tiles to change the CSS if someone wanted a more
printable layout (i.e. hide ads or other un-printer friendly components).
This makes me curious about what shortcoming you found in SiteMesh related
to your particular project.

Regards,
David

-----Original Message-----
From: Erik Weber [mailto:erikweber@mindspring.com]
Sent: Monday, January 24, 2005 10:47 PM
To: Struts Users Mailing List
Subject: [OT] Re: Best practice for dynamic Title values using Tiles?


Hello Rick. Happy New Year to you. I'm just curious. Why are you
switching? I remember you advocating Sitemesh (I think it was on your
site) instead of Tiles at some point. I haven't tried either one yet,
but was going to try Sitemesh based largely on your recommendation, next
time I saw a good opportunity. So far I haven't needed a layout
framework, but I've gotta catch up with the times at some point . . .

Erik


Rick Reumann wrote:

> I'm switching back to using Tiles instead of Sitemesh and I remember
> one issue that I found annoying with Tiles and I'd be curious how you
> guys handle it. Say I have a form that is going to be reused for both
> "Edit" and "Add." I want the <title> attribute to read something like
> "Add Employee" or "Edit Employee," depending on what I'm doing. It
> seems silly to have to create multiple definitions in my
> tiles-definitions that are essentially the same exact definition
> except that the title has changed (potentially you might want a
> definition to be used for more than just the two that I mentioned).
> This also requires that my struts config has to be set up to forward
> to multiple tiles definitions when its really the same page layout but
> with a different title and could really just require one definition to
> use.
>
> I've thought of different ways I might want to handle this (ie set a
> title in request scope before leaving action and have the header.jsp
> look for this, or maybe use a filter or over-ride RequestProcessor?)
> I'm curious if others have run into this. Maybe the latest
> Struts/Tiles has a solution that I have not looked into.
>
> Thanks
>

---------------------------------------------------------------------
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


[OT] Re: Best practice for dynamic Title values using Tiles?

Posted by Erik Weber <er...@mindspring.com>.
Hello Rick. Happy New Year to you. I'm just curious. Why are you 
switching? I remember you advocating Sitemesh (I think it was on your 
site) instead of Tiles at some point. I haven't tried either one yet, 
but was going to try Sitemesh based largely on your recommendation, next 
time I saw a good opportunity. So far I haven't needed a layout 
framework, but I've gotta catch up with the times at some point . . .

Erik


Rick Reumann wrote:

> I'm switching back to using Tiles instead of Sitemesh and I remember 
> one issue that I found annoying with Tiles and I'd be curious how you 
> guys handle it. Say I have a form that is going to be reused for both 
> "Edit" and "Add." I want the <title> attribute to read something like 
> "Add Employee" or "Edit Employee," depending on what I'm doing. It 
> seems silly to have to create multiple definitions in my 
> tiles-definitions that are essentially the same exact definition 
> except that the title has changed (potentially you might want a 
> definition to be used for more than just the two that I mentioned). 
> This also requires that my struts config has to be set up to forward 
> to multiple tiles definitions when its really the same page layout but 
> with a different title and could really just require one definition to 
> use.
>
> I've thought of different ways I might want to handle this (ie set a 
> title in request scope before leaving action and have the header.jsp 
> look for this, or maybe use a filter or over-ride RequestProcessor?) 
> I'm curious if others have run into this. Maybe the latest 
> Struts/Tiles has a solution that I have not looked into.
>
> Thanks
>

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


Re: Redirecting to outside the webapp

Posted by "Jesus M. Rodriguez" <je...@redhat.com>.
Thanks Hubert,

Looks like the manual redirect works.  The path would work
but I really don't know the hostname the app will be installed
on.  Best to simply redirect manually.

Thanks
Jesus Rodriguez

Hubert Rabago wrote:
> If you create your own ActionForward, and you redirect with a string
> that starts with "/", the result will still be the same.  You can
> either do the redirect yourself as Wendy suggested or put the entire
> URL on the path you've configured:
> 
> <forward name="success" path="http://hostname/index.pxt" redirect="true"/>
> 
> Hubert 
> 
> 
> On Mon, 24 Jan 2005 16:37:03 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> 
>>From: "Jesus M. Rodriguez" <je...@redhat.com>
>>
>>>I want to be sent to http://hostname/index.pxt after the LoginSubmit
>>>action has been executed.  But we always get sent to
>>>http://hostname/webappname/index.pxt which causes a 404.
>>
>>IIRC, from execute you can either create your own ActionForward (rather than
>>looking it up from the ActionMapping) and return it, or just do the redirect
>>yourself and return null.
>>
>>--
>>Wendy Smoak
>>
> 
> 
> ---------------------------------------------------------------------
> 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: Redirecting to outside the webapp

Posted by Hubert Rabago <hr...@gmail.com>.
If you create your own ActionForward, and you redirect with a string
that starts with "/", the result will still be the same.  You can
either do the redirect yourself as Wendy suggested or put the entire
URL on the path you've configured:

<forward name="success" path="http://hostname/index.pxt" redirect="true"/>

Hubert 


On Mon, 24 Jan 2005 16:37:03 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> From: "Jesus M. Rodriguez" <je...@redhat.com>
> > I want to be sent to http://hostname/index.pxt after the LoginSubmit
> > action has been executed.  But we always get sent to
> > http://hostname/webappname/index.pxt which causes a 404.
> 
> IIRC, from execute you can either create your own ActionForward (rather than
> looking it up from the ActionMapping) and return it, or just do the redirect
> yourself and return null.
> 
> --
> Wendy Smoak
>

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


Re: Redirecting to outside the webapp

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Jesus M. Rodriguez" <je...@redhat.com>
> I want to be sent to http://hostname/index.pxt after the LoginSubmit
> action has been executed.  But we always get sent to
> http://hostname/webappname/index.pxt which causes a 404.

IIRC, from execute you can either create your own ActionForward (rather than
looking it up from the ActionMapping) and return it, or just do the redirect
yourself and return null.

-- 
Wendy Smoak


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


Redirecting to outside the webapp

Posted by "Jesus M. Rodriguez" <je...@redhat.com>.
Hello All,

Long time lurker, first time poster.  I'm trying integrate our Java
Struts webapplication with an existing web app.  After logging into
the Java site, I want to redirect to outside the webapp, but struts
keeps prepending the webapp name.

For example. in my struts-config.xml I have the following:

     <action path="/LoginSubmit"
         name="loginForm"
         scope="request"
         validate="false"
         input="/WEB-INF/pages/common/login.jsp"
         type="com.company.frontend.action.LoginAction">
       <forward name="success" path="/index.pxt"
                redirect="true"  />
       <forward name="failure" path="/WEB-INF/pages/common/login.jsp" />
     </action>

I want to be sent to http://hostname/index.pxt after the LoginSubmit 
action has been executed.  But we always get sent to
http://hostname/webappname/index.pxt which causes a 404.

Is there anyway to get out of the webapp either through configuration or
through customization?

Sincerely,
Jesus Rodriguez

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


R: Best practice for dynamic Title values using Tiles?

Posted by Amleto Di Salle <di...@di.univaq.it>.
Hi,
I solved the problem implementing a tiles controller and using the
"extend" definition attribute in tiles-defs.xml. 
This solution requires two tiles definition but the jsp body is the
same. I used two tiles in order to set the correct action, formName and
some other parameter. Maybe this solution can be improved. Any
suggestion is welcome.

Inside tiles-def.xml
<definition name="base" path="/layouts/standard.jsp">
   <put name="title" value="Web Application"/>
   <put name="header" value="/common/header.jsp"/>
   <put name="footer" value="/common/footer.jsp"/>
</definition>
<definition name="standard" extends="base"
controllerClass="it.amletodisalle.presentation.tiles.TilesControllerImpl
">
   <put name="left" value="menu.bar"/>
   <put name="action" value="default"/>
    <put name="formName" value="default"/>
    <put name="subtitle" value="default"/>
    <putList name="otherValues">
    </putList>
</definition>

For example: 
<definition name="viewproduct" extends="standard">
	<put name="title" value="Web Application - View Products"/>
      <put name="subtitle" value="View Products"/>
      <put name="body" value="/protect/viewProducts.jsp"/>
      <put name="action" value="ActivateAddProduct"/>
      <putList name="otherValues">
      	<bean
classtype="it.amletodisalle.common.presentation.tiles.ListItem">
            	<set-property property="nome" value="editProduct"/>
                <set-property property="valore"
value="ActivateEditProduct"/>
            </bean>
            <bean
classtype="it.amletodisalle.common.presentation.tiles.ListItem">
                <set-property property="nome" value="navigationAction"/>
                <set-property property="valore" value="viewProducts"/>
            </bean>
        </putList>
</definition>

<definition name="addproduct" extends="standard">
        <put name="title" value="Web Application - Add Product"/>
        <put name="subtitle" value="Add Product"/>
        <put name="body" value="/protect/formProduct.jsp"/>
        <put name="action" value="AddProduct"/>
        <put name="formName" value="FormbeanProduct"/>
        <putList name="otherValues">
            <bean
classtype="it.amletodisalle.common.presentation.tiles.ListItem">
                <set-property property="nome" value="updateURL"/>
                <set-property property="valore"
value="ActivateAddProduct"/>
            </bean>
        </putList>
</definition>

<definition name="editproduct" extends="standard">
        <put name="title" value="Web Application - Edit Product"/>
        <put name="subtitle" value="Edit Product"/>
        <put name="body" value="/protect/formProduct.jsp"/>
        <put name="action" value="editProduct"/>
        <put name="formName" value="FormbeanProduct"/>
        <putList name="otherValues">
            <bean
classtype="it.amletodisalle.common.presentation.tiles.ListItem">
                <set-property property="nome" value="updateURL"/>
                <set-property property="valore"
value="ActivateAddProduct"/>
            </bean>
        </putList>
</definition>

TilesControllerImpl:

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.Controller;

public class TilesControllerImpl implements Controller {

    public void perform( ComponentContext componentContext,
HttpServletRequest httpServletRequest, HttpServletResponse
httpServletResponse, ServletContext servletContext ) throws
ServletException, IOException {
        String subtitle = (String) componentContext.getAttribute(
Constants.SUB_TITLE);
        if (!subtitle.equals( Constants.DEFAULT )) {
            httpServletRequest.setAttribute( Constants.SUB_TITLE,
subtitle );
        }

        String action = (String) componentContext.getAttribute(
Constants.ACTION );
        if (!action.equals( Constants.DEFAULT )) {
            httpServletRequest.setAttribute( Constants.ACTION,  "/" +
action + ".do");
        }

        String formName = (String) componentContext.getAttribute(
Constants.FORM_NAME);
        if (!formName.equals( Constants.DEFAULT )) {
            httpServletRequest.setAttribute( Constants.FORM_NAME,
formName);
            char firstChar = formName.charAt( 0 );
            String onsubmitName = "validate" + Character.toUpperCase(
firstChar ) + formName.substring( 1, formName.length());
            String onsubmit = "return " + onsubmitName + "(this);";
            httpServletRequest.setAttribute( Constants.ON_SUBMIT,
onsubmit);
            httpServletRequest.setAttribute( Constants.ON_SUBMIT_NAME,
onsubmitName);            

        }

        List otherValues = (List) componentContext.getAttribute(
Constants.OTHER_VALUES );
        for ( Iterator iterator = otherValues.iterator();
iterator.hasNext(); ) {
            ListItem listItem = ( ListItem ) iterator.next();
            httpServletRequest.setAttribute( listItem.getNome(),
listItem.getValore() );
        }
    }
}

And inside the ".jsp" you can use the parameters defined inside tiles
For Example:

................
<html:javascript formName="${formName}"/>
<html:form action="${action}" onsubmit="${onsubmit}">
.............
</html:form>

BR
/Amleto


> -----Messaggio originale-----
> Da: Rick Reumann [mailto:struttin@reumann.net] 
> Inviato: lunedì 24 gennaio 2005 23.18
> A: Struts Users Mailing List
> Oggetto: Best practice for dynamic Title values using Tiles?
> 
> 
> I'm switching back to using Tiles instead of Sitemesh and I 
> remember one 
> issue that I found annoying with Tiles and I'd be curious how 
> you guys 
> handle it. Say I have a form that is going to be reused for 
> both "Edit" 
> and "Add." I want the <title> attribute to read something like "Add 
> Employee" or "Edit Employee," depending on what I'm doing. It seems 
> silly to have to create multiple definitions in my tiles-definitions 
> that are essentially the same exact definition except that 
> the title has 
> changed (potentially you might want a definition to be used for more 
> than just the two that I mentioned). This also requires that 
> my struts 
> config has to be set up to forward to multiple tiles definitions when 
> its really the same page layout but with a different title and could 
> really just require one definition to use.
> 
> I've thought of different ways I might want to handle this (ie set a 
> title in request scope before leaving action and have the header.jsp 
> look for this, or maybe use a filter or over-ride 
> RequestProcessor?) I'm 
> curious if others have run into this. Maybe the latest 
> Struts/Tiles has 
> a solution that I have not looked into.
> 
> Thanks
> 
> -- 
> Rick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 265.7.2 - Release Date: 21/01/2005
>  
> 

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.2 - Release Date: 21/01/2005
 


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


RE: Best practice for dynamic Title values using Tiles?

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Rick,

Did you consider making your Action a TilesAction so you can put the "title"
into the context however you want?  That way, if you do a CRUD methodology,
you could do a context.putAttribute("title",new String("Edit")); or "Add"
depending on your Action's CRUD method.

Heck, you could also do that to the "body" attribute and change a JSP
inserted into the middle of your template.  You could have a definition look
like this:

<definition name=".generic" path="/WEB-INF/pages/common.jsp">
	<put name="title" value="Default Value" />
	<put name="body" value="/WEB-INF/pages/default-center.jsp" />
</definition>

Then, in the extreme, all of your actions could se the title and their own
body choice. Viola! One template fits all!

Regards,
David

-----Original Message-----
From: Rick Reumann [mailto:struttin@reumann.net]
Sent: Monday, January 24, 2005 5:18 PM
To: Struts Users Mailing List
Subject: Best practice for dynamic Title values using Tiles?


I'm switching back to using Tiles instead of Sitemesh and I remember one
issue that I found annoying with Tiles and I'd be curious how you guys
handle it. Say I have a form that is going to be reused for both "Edit"
and "Add." I want the <title> attribute to read something like "Add
Employee" or "Edit Employee," depending on what I'm doing. It seems
silly to have to create multiple definitions in my tiles-definitions
that are essentially the same exact definition except that the title has
changed (potentially you might want a definition to be used for more
than just the two that I mentioned). This also requires that my struts
config has to be set up to forward to multiple tiles definitions when
its really the same page layout but with a different title and could
really just require one definition to use.

I've thought of different ways I might want to handle this (ie set a
title in request scope before leaving action and have the header.jsp
look for this, or maybe use a filter or over-ride RequestProcessor?) I'm
curious if others have run into this. Maybe the latest Struts/Tiles has
a solution that I have not looked into.

Thanks

--
Rick

---------------------------------------------------------------------
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