Class LocalizedTag

  • All Implemented Interfaces:
    ConditionalTag, org.apache.commons.jelly.Tag

    public class LocalizedTag
    extends FormBaseTag

    A specialized tag handler class for loading localized texts and passing them to tags implementing the ValueSupport interface.

    There are a couple of tag handler classes that are able to assign values to beans that have been created. This includes tags from the dependency injection framework (e.g. SetPropertyTag) and tags from the component builder framework (e.g. PropertyTag) as well. Per default, the values to be assigned are hard-coded in builder scripts. This can be a problem if string properties are involved whose values should be translated (and thus be read from resource files).

    This tag handler class provides a solution for this problem. It reads a text resource defined by its attributes and passes its current localized value to the parent tag. The parent tag must implement the ValueSupport interface which allows nested tags to hook into the mechanism of defining values. The following example fragment shows how this could look in practice:

     <di:bean name="listLocalized"
       beanClassName="net.sf.jguiraffe.di.ReflectionTestClass">
       <di:setProperty property="data">
         <f:localized resid="myMessage"/>
       </di:setProperty>
     </di:bean>
     
    Here a bean is created using the dependency injection framework, and the data property of the bean is assigned a value that is obtained from the application's resources. So instead of hard-coding the property value, the <localized> tag is placed in the body of the <setProperty> tag.

    The following table lists all attributes supported by this tag:

    Attribute Description Optional
    resid The resource ID. This resource will be resolved in the current locale to obtain the value of the property to set. no
    resgrp Defines the resource group, to which the resource ID belongs. yes

    Version:
    $Id: LocalizedTag.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • LocalizedTag

        public LocalizedTag()
    • Method Detail

      • getResgrp

        public String getResgrp()
        Returns the resource group to use when resolving the resID.
        Returns:
        the resource group
      • setResgrp

        public void setResgrp​(String resgrp)
        Setter method for the resgrp attribute.
        Parameters:
        resgrp - the attribute value
      • getResid

        public String getResid()
        Returns the resID to be resolved.
        Returns:
        the resID
      • setResid

        public void setResid​(String resid)
        Setter method for the resid attribute.
        Parameters:
        resid - the attribute value
      • fetchResourceValue

        protected Object fetchResourceValue()
                                     throws org.apache.commons.jelly.JellyTagException
        Returns the resource value specified for this tag. If a resource ID is specified, it is resolved using the current resource manager, and the result is returned. Otherwise an exception will be thrown.
        Returns:
        the value of the property
        Throws:
        org.apache.commons.jelly.JellyTagException - if an error occurs
      • process

        protected void process()
                        throws org.apache.commons.jelly.JellyTagException,
                               FormBuilderException
        Executes this tag. This implementation checks whether the parent tag implements the ValueSupport interface. If this is the case, fetchResourceValue() is called to obtain the resource value. The result of this method is passed to the parent tag.
        Specified by:
        process in class FormBaseTag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is used incorrectly
        FormBuilderException - if an error occurs