Internationalization

The bpm4struts cartridge has been designed with internationalization (i18n) in mind, a few resource bundles, dictionaries if you will, exist by default; you have the option of translating them to any number of languages of your choice.

These resource bundles are listed below, they are output in the messages outlet, which should normally point to /WEB-INF/classes

A very interesting feature exists that might make it considerably easier for you if you have lots of similar messages in the resource bundle. Set the normalizeMessages namespace property to true. This will make sure elements with the same name will use the same message, when translating such a resource bundle you will never need to do the same work twice. This feature is disabled by default, enabling you to customize each possible message. In most cases it's better to enable it though.

The proper way to create resource bundles for additional languages is to create a file with the same name but suffix it with locale specific codes, this is explained in more detail here: http://java.sun.com/j2se/1.5.0/docs/api/java/util/ResourceBundle.html. Put these files in the same directory as the original one.

application-resources.properties

This bundle contains labels generated from names in the UML model. These labels are used for input field labels, tooltips, online help text, etc...

In order to render labels from this bundle you will need to write something like this (replace label.key by the actual properties' key):

    <bean:message key="label.key"/>

displaytag.properties

The displaytag library is used for the displaying of tables, the paging and sorting features use words that might need internationalization. A default properties file is generated, containing all possible messages.

You won't need to call the messages in this bundle directly, use the custom bundle instead.

Custom Resources

If you have generated your AndroMDA project using andromdapp:generate then the following will have already been configured, you may skip this section.

In order to make use of custom message properties you will need to create your own resource bundle with your custom set of messages and put it somewhere in your source tree, for example in /web/src/main/properties/custom.properties.

Next, tell AndroMDA to merge this file into the generated resource bundle, it is sufficient to add the following to /mda/src/main/config/mappings/WebMergeMappings.xml:

That's it, now you can start using your own resource messages. It is even possible to override the default generated ones by simply repeating them in your custom resource bundle. If you want you can specify multiple <path> elements, that way all of them will be merged.

This feature is particularly interesting when you want to have messages displayed in a more dynamic fashion: you can decide in the controller what message to show, save them (using saveMessages(..)), and have them picked up from the bundle.

Date Formats

It is also possible to have input fields representing dates automatically formatted. Two ways to do this exist: on a global level you can use the defaultDateFormat namespace property which defaults to dd/MM/yyyy (go here to learn more about possible date formats) , it sets the format for all dates in the modeled application; on a field level it is possible to use the andromda_struts_view_field_format tagged value, just make sure the parameter is a date type and it will override the global setting.

Use the strict keyword in front of the date format, that way the application will strictly check the format, without being lenient.

Use dates in combination with the andromda_presentation_web_view_field_calendar=true tagged value to have a popup calendar trigger rendered next to the input field, the selected date will immediately be converted into the correct format. A screenshot is shown here: Activity Graphs (bottom of the page)

Nice to know

Action Forms

Using dates for action parameters will yield a specific date formatter to be generated in the corresponding action form, this in addition to other convenience methods. The following code is showing this in more details, this example has been taken from the online store sample, you're looking at a fragment from the my.onlinestore.purchase.EnterUserDetailsPurchaseForm class.

    private final static java.text.DateFormat deliveryDateDateFormatter = new java.text.SimpleDateFormat("dd-MM-yyyy");

    /**
     * Resets the given <code>deliveryDate</code>.
     */
    public void resetDeliveryDate()
    {
        this.deliveryDate = null;
    }

    public void setDeliveryDateAsDate(java.util.Date deliveryDate)
    {
        this.deliveryDate = deliveryDate;
    }

    /**
     * Returns the Date instance representing the <code>deliveryDate</code> field.
     *
     * @see my.onlinestore.purchase.EnterUserDetailsPurchaseForm#getDeliveryDate
     * @see my.onlinestore.purchase.EnterUserDetailsPurchaseForm#getDeliveryDateDateFormatter
     */
    public java.util.Date getDeliveryDateAsDate()
    {
        return this.deliveryDate;
    }

    public void setDeliveryDate(java.lang.String deliveryDate)
    {
        if (deliveryDate == null || deliveryDate.trim().length()==0)
        {
            this.deliveryDate = null;
        }
        else
        {
            try
            {
                this.deliveryDate = deliveryDateDateFormatter.parse(deliveryDate);
            }
            catch(java.text.ParseException e)
            {
                throw new RuntimeException(e);
            }
        }
    }

    /**
     * <p>
     *  This date specifies the date you would like the items
     *  delivered.
     * </p>
     *
     * This method returns a <code>java.lang.String</code> instance, in order to get the
     * <code>java.util.Date</code> instance see the <code>getDeliveryDateAsDate()</code>
     * method.
     * <p>
     * The conversion from Date to String (and vice-versa) is done by means of a date formatter, which
     * can be accessed here: <code>getDeliveryDateDateFormatter()</code>.
     *
     * @see my.onlinestore.purchase.EnterUserDetailsPurchaseForm#getDeliveryDateAsDate
     * @see my.onlinestore.purchase.EnterUserDetailsPurchaseForm#getDeliveryDateDateFormatter
     */
    public java.lang.String getDeliveryDate()
    {
        return (deliveryDate == null) ? null : deliveryDateDateFormatter.format(deliveryDate);
    }

    /**
     * Returns the date formatter used for the <code>deliveryDate</code> property.
     *
     * @see my.onlinestore.purchase.EnterUserDetailsPurchaseForm#getDeliveryDate
     * @see my.onlinestore.purchase.EnterUserDetailsPurchaseForm#getDeliveryDateAsDate
     */
    public final static java.text.DateFormat getDeliveryDateDateFormatter()
    {
        return EnterUserDetailsPurchaseForm.deliveryDateDateFormatter;
    }