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>
</Html>
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 newInputBean
Instance.
*
/
Public inputbean (){
}
Private logger getlogger (){
Return logger. getlogger (getclass (). getname ());
}
Public void print (actionevent event ){
Getlogger (). Info ("Enter print method ");
}
/*
* GetValue
Value.
*
* @ ReturnString
Value
/
Public final string getvalue (){
Getlogger (). Info ("Enter getvalue:" + value );
Return value;
}
/*
* SetValue
Value.
*
* @ 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.