In general, I think a Composite compnent should have perfect behavior as much as possible. Avoid exposing too many interfaces to users. In this direction, I continue our htmlinput2 at night. This section adds a validator and displays a message when verification fails.
The following code:
<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml"
Xmlns: f = "http://java.sun.com/jsf/core"
Xmlns: h = "http://java.sun.com/jsf/html"
Xmlns: ui = "http://java.sun.com/jsf/facelets"
Xmlns: composite = "http://java.sun.com/jsf/composite">
<Composite: interface componentType = "HtmlInput2">
<! -EditableValueHolder is desigend for validator->
<Composite: editableValueHolder name = "inputField" target = "in"/>
<Composite: valueHolder name = "outputField" target = "out"/>
</Composite: interface>
<Composite: implementation>
<H: inputText id = "in" value = "# {inputBean. value}" required = "true">
<F: validateLength minimum = "1" maximum = "6"/>
</H: inputText>
<H: commandButton id = "clickButton" value = "Click Me! "ActionListener =" # {inputBean. print} "/>
<H: outputText id = "out" value = "# {inputBean. value}"/>
<H: message for = "in"/>
</Composite: implementation>
</Html>
F: validateLength and h: message are added. Very simple.
If the content in this section is missing, add other details. You can add some information to the glassfish log file through java standard logs, for example, my glassfish log file is/usr/local/glassfish-3.0.1/glassfish/domains/domain1/logs/server.
Adding logs is simple. Some packages are introduced, such:
Import java. util. logging. Level;
Import java. util. logging. Logger;
Then add a private function to the class.
Private Logger getLogger (){
Return Logger. getLogger (getClass (). getName ());
}
To add logs:
Public HtmlInput2 (){
GetLogger (). info ("HtmlInput2 constructor ");
}
At the same time, a useful tag copied from <Core JSF> 3rd is debug, which prints the request data sent by the page.
<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml"
Xmlns: composite = "http://java.sun.com/jsf/composite">
<Composite: interface/>
<Composite: implementation>
<Div style = "font-size: 1.2em; font-style: italic">
Request header:
</Div>
<P >#{ header} </p>
<Div style = "font-size: 1.2em; font-style: italic">
Request parameters:
</Div>
<P >#{ param} </p>
</Composite: implementation>
</Html>
The following is a simple reference on the page to be used:
<Cs: debug/>.