HTML and CSS Reference
In-Depth Information
<h:outputText value="Second number:"/>
<h:inputText id="sNumber"
value="#{calculator.secondNumber}"
required="true">
</h:inputText>
</h:panelGrid>
<h:commandButton action="#{calculator.calculateSum}" value="Sum"/><br/>
<h:outputText value="Result: #{calculator.result}"/>
</h:form>
</h:body>
</html>
Both the
#{calculator.firstNumber}
and
#{calculator.secondNumber}
expressions are binded automatically
with the
firstNumber
and the
secondNumber
attributes of the
Calculator
managed bean after being converted to
Double
using the implicit
javax.faces.Double
converter. Like the
Double
type, implicit converters are applied also on
the
Boolean
,
Byte
,
Character
,
Short
,
Integer
,
Long
,
Float
,
BigDecimal
, and
BigInteger
Java types.
Explicit converters have to be attached to the components explicitly. Currently, the JSF core tag library provides
the following tags that represent JSF explicit converters:
•
<f:convertDateTime>
•
<f:convertNumber>
<f:converter>
<f:convertDateTime>
converter converts the input String to
java.util.Date
object with any specified format.
Listing 3-5 shows a sample managed bean that includes a
java.util.Date
attribute.
•
Listing 3-5.
Sample Managed Bean that Includes Date Attribute
import java.io.Serializable;
import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class TestBean implements Serializable {
// ...
private Date birthDate;
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
// ...
}