Translators

A Translator converts between a value on the server-side and its string representation on the client side.
This example demonstrates TextField's use of Tapestry's built-in translators. TextField, PasswordField, and TextArea all use them.

The built-in translators bubble up events toClient and parseClient, which we do not use in this example. See the Augmenting Translators example.

The String translator does not do any conversion. It exists only to bubble up the toClient and parseClient events.

References: Translator, translator package, TextField, PasswordField, TextArea.

Home


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- We need a doctype to allow us to use special characters like &nbsp; 
     We use a "strict" DTD to make IE follow the alignment rules. -->
     
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<body class="container">
    <h3>Translators</h3>
    A Translator converts between a value on the server-side and its string representation on the client side.<br/>
    This example demonstrates TextField's use of Tapestry's built-in translators. 
    TextField, PasswordField, and TextArea all use them.
    
    <div class="eg">
        <t:form class="form-horizontal" t:id="inputs">
            <div class="form-group">
                <t:label for="byteValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="byteValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${byteValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="shortValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="shortValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${shortValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="integerValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="integerValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${integerValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="longValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="longValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${longValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="floatValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="floatValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${floatValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="doubleValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="doubleValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${doubleValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="bigIntegerValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="bigIntegerValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${bigIntegerValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="bigDecimalValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="bigDecimalValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${bigDecimalValue}</p>
                </div>
            </div>
            <div class="form-group">
                <t:label for="stringValue" class="col-sm-2"/>
                <div class="col-sm-2">
                    <t:textfield t:id="stringValue"/>
                </div>
                <div class="col-sm-2">
                    <p class="form-control-static">${stringValue}</p>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-2 col-sm-offset-2">
                    <t:submit/>
                </div>
            </div>
             
        </t:form>
    </div>
    
    The built-in translators bubble up events <em>toClient</em> and <em>parseClient</em>, which we do not use in this example. 
    See the Augmenting Translators example.<br/><br/>
    
    The String translator does not do any conversion. 
    It exists only to bubble up the <em>toClient</em> and <em>parseClient</em> events.<br/><br/>
    
    References: 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/Translator.html">Translator</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/translator/package-summary.html">translator package</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/TextField.html">TextField</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/PasswordField.html">PasswordField</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/TextArea.html">TextArea</a>.
    <br/><br/>

    <t:pagelink page="Index">Home</t:pagelink><br/><br/>
        
    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/input/Translators.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/input/Translators.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/plain.css"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.input;

import java.math.BigDecimal;
import java.math.BigInteger;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

@Import(stylesheet="css/examples/plain.css")
public class Translators {

    // Screen fields

    @Property
    @Persist(PersistenceConstants.FLASH)
    private Byte byteValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private Short shortValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private Integer integerValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private Long longValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private Float floatValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private Double doubleValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private BigInteger bigIntegerValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private BigDecimal bigDecimalValue;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private String stringValue;

}


.eg {
                margin: 20px 0;
                padding: 14px;
                border: 1px solid #ddd;
                border-radius: 6px;
                -webkit-border-radius: 6px;
                -mox-border-radius: 6px;
}