wood burning stoves 2.0*
The moose likes Struts and the fly likes Legal to put a bean:write inside tiles-defs.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Legal to put a bean:write inside tiles-defs.xml?" Watch "Legal to put a bean:write inside tiles-defs.xml?" New topic
Author

Legal to put a bean:write inside tiles-defs.xml?

Nadine McKenzie
Ranch Hand

Joined: Feb 15, 2002
Posts: 53
Is it legal to put a bean:write inside a tiles-defs.xml as follows:

<definition name="tiles.work.items" extends="tiles.mainlayout">
<put name="title">
<bean:write message="first.pageTitle" />
</put>
...

Thanks!


Nadine -SCJP, SCWCD, SCBCD
Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75
Hi

I never tried this but i'm pretty sure this is not legal.

If you need to insert dynamical values into tiles attributs, I would suggest you to deal with it right into the JSP using your tiles component.

BTW, why do you need this into the XML definition file ?


Franck<p>--------------------
Nadine McKenzie
Ranch Hand

Joined: Feb 15, 2002
Posts: 53
The idea of tile-defs was to provide a means of by-passing creating any jsp page (with the exception the xxxLayout.jsp). The validation framework supports talking with the applicationResources.properties so it would seem logical to me that the tile-defs should have similar support.

My question then is, how can I use tile-defs and not hard code text into the tile-def for things like page titles. If there is no way to do this, then I'll put this info in the xxxLayout.jsp page.
Nadine McKenzie
Ranch Hand

Joined: Feb 15, 2002
Posts: 53
OK I figured it out...

In the tiles-defs you put something like this

<definition name="tiles.work.items" extends="tiles.mainlayout">
<put name="title" value="label.work.items" />
<put name="body" value="/work/workItems.jsp" />
</definition>

In the layout jsp page, you make use of both the useAttribute and the bean:message as follows:

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<tiles:useAttribute name="title" scope="request"/>

<html:html>
<head>
<title><bean:message name="title"/></title>
</head>

...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Legal to put a bean:write inside tiles-defs.xml?
 
Similar Threads
tiles exception-2
Resource Bundle files by Modules setup
Struts - Tiles
How to use message resources in struts tiles-defs.xml file?
problem with tiles in netbeans