cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hunsberger, Peter" <>
Subject RE: Accessing public static final constants from JXTemplate
Date Fri, 08 Aug 2003 18:56:39 GMT
Jeremy Quinn <> asks:

> I have a class called Constants, that is like this:
> public final class Constants {
> 	public static final String FAILURE = "Failed";
> 	public static final String CANCEL_ACTION = "Cancelled";
> 	// etc.
> }
> I wish to share this between my Java 'biz logic', my FlowScripts and 
> the View Layer.
>   I have the first two working as expected, the third I 
> cannot work out 
> .....
> Is it possible to pass the Constants class to the JXTemplate 
> view layer 
> in such a way that I can extract their values?
> I have tried several ways of sending the Constants class to the view 
> layer, and using #{CANCEL_ACTION} (etc.) in my template, without 
> success.
> Any suggestions?
Yes, but you may not like it...  We build our static constants from an
XML file using an XSLT transform to create the Java code:

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl=""

<xsl:output encoding="utf-8" method="text" indent="yes"/>

    This template takes in a set of object definitions and spits out a
Java file defining user interface constants

<xsl:template match="package">package <xsl:value-of select="@name"/>;

 * Static constant values used in the UI layer
 * ***** Do not alter this file *****
 * This file was produced from the source UIConstants.xml
 * See the comments in that file for information on how to
 * update and produce this file

public abstract class UIConstants {
<xsl:apply-templates select="//field"><xsl:sort select="concat(@value !=
<xsl:apply-templates select="//field[@display !='']"
mode="display"><xsl:sort select="@name"/></xsl:apply-templates>

<xsl:template match="field[@display !='']" mode="display">   public
static final String <xsl:value-of select="concat('FRIENDLY_',@name)"/> =
"<xsl:value-of select="normalize-space(@display)"/>";

<xsl:template match="field">   public static final String <xsl:value-of
select="@name"/> = "<xsl:value-of
select="normalize-space(text())"/>";<xsl:call-template name="comment"/>

<xsl:template match="field[@value !='']">   public static final int
<xsl:value-of select="@name"/> = <xsl:value-of
select="@value"/>;<xsl:call-template name="comment"/>   public static
final String <xsl:value-of select="@name"/>_STR = "<xsl:value-of
select="normalize-space(text())"/>";<xsl:call-template name="comment"/>

<xsl:template name="comment">
<xsl:choose><xsl:when test="@comment != ''"><xsl:value-of


View raw message