JSF2 custom component programming series Part 7

Source: Internet
Author: User

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/>.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.