For those who care. The question I posed was how do people deal with the situation when using Tiles where they often need to create titles and or information for headers that is slightly dynamic. For example rather than simply have a Title or label that says...

"User Selection" you might want a Title/label that says..

"User Selection For Company Acme Inc."

Most of the suggestions revolved around putting the title in some sort of scope from within your Action which I didn't really like since what if the display requirement changed - you don't want to have to be digging into source code in order to change a label. For example with the above maybe the title later needs to read "Acme Inc. select user"

The following solution seems to be working nicely for me.

For custom stuff such as a company name you would put that into scope from within the Action (that's ok because it's not really the label only part of it). Since the struts resources file can take up to four params you can add the params from your action using any labeling convention you want but for the sake of example I'm using messageParamA, messageParamB, messageParamC, messageParamD.

A tag file is used to display this info, but before I show that. Here's a sample of usage, using the example above


1) resources file: label.select.user=Select User For Company {0}

2) In your action before you get to the page
request/session setAttribute("messageParamA", companyName )
//of course better to use a constant to represent your messageParam's ie ( Constants.MESSAGE_1, companyName )


3) In your tag defintion for the page
<put name="page.title.key" value="label.select.user" type="string"/>

4) In you reusable layout definition
<title>
    <tags:TilesDisplayMessage tilesDisplayKey="page.title.key"/>
</title>


The nice thing about the above is you can change around the title in your resources file, yet you still get the use of the dynamic attributes you want to add.


The above also works nice for headers on a page. Maybe you have a standard header tile that is not part of your content and you need to have somewhat dynamic header labels.

You could just do

header.jsp
<b><tags:TilesDisplayMessage tilesDisplayKey="header.label.key"/></b>

and your tiles defintion would have
<put name="header.label.key" value="some.resource.def" type="string"/>

The tag file is very simple....

//TilesDisplayMessage.tag

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
<%@ taglib prefix="tiles" uri="http://struts.apache.org/tags-tiles"; %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"; %>
<%@ attribute name="tilesDisplayKey" %>
<c:set var="params_display">
    <tiles:getAsString name="${tilesDisplayKey}"/>
</c:set>
<fmt:message key="${params_display}">
    <fmt:param value="${messageParamA}"/>
    <fmt:param value="${messageParamB}"/>
    <fmt:param value="${messageParamC}"/>
    <fmt:param value="${messageParamD}"/>
</fmt:message>


If someone has a better way to handle this, please let me know.

--
Rick

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



Reply via email to