Jsf2 custom component programming series Part 6

Source: Internet
Author: User

In the previous example, I created a backing class: htmlinput2, which represents composite.
The class of the top-level object namingcontainer of component. This gives me the opportunity to overwrite the encode/decode method, so that I can use Java code to enhance
Composite compnent action.
In this example, create another managed bean to receive user input, intercept click button events, and display user input. Note that this new managed
Bean is in my jsfex project, so it is actually Composite
The internal implementation of compnent is not required by the user. This example is just to show that adding managed bean is no different from normal JSF development.
Now modify the htmlinput2.xhtml 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"/>
<H: commandbutton id = "clickbutton" value = "Click me! "Actionlistener =" # {inputbean. Print} "/>
<H: outputtext id = "out" value = "# {inputbean. Value}"/>
</Composite: Implementation>

Create an inputbean class under the com. freebird. Component package.
Package com. freebird. component;

Import javax. Faces. Bean. managedbean;
Import javax. Faces. Bean. requestscoped;
Import java. util. Logging. level;
Import java. util. Logging. Logger;
Import javax. Faces. event. actionevent;

* Describe class inputbean here.
* Created: Fri Jan 7 14:15:36 2011
* @ Author <a href = "mailto: chenshu @ csdesktop"> chenshu </a>
* @ Version 1.0
@ Managedbean (name = "inputbean ")
@ Requestscoped
Public class inputbean {

* Describe value here.
Private string value;

* Creates a newInputBeanInstance.
Public inputbean (){


Private logger getlogger (){
Return logger. getlogger (getclass (). getname ());

Public void print (actionevent event ){
Getlogger (). Info ("Enter print method ");

* GetValueValue.
* @ ReturnStringValue
Public final string getvalue (){
Getlogger (). Info ("Enter getvalue:" + value );
Return value;

* SetValueValue.
* @ Param newvalue the new value.
Public final void setvalue (final string newvalue ){
Getlogger (). Info ("Enter setvalue:" + newvalue );
This. value = newvalue;

In addition, remove the encodebegin code in htmlinput2.java. Note that the print method for blocking click events only prints a log. It is just to show that we can easily handle events internally.

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.