JSF

Application的常用方法:

  Application app = facesContext.getApplication();

  public Iterator getSupportedLocales();

  public String getMessageBundle();

   String bundleName = application.getMessageBundle();
  ResourceBundle bundle =ResourceBundle.getBundle(bundleName, locale);

  public String getDefaultRenderKitId();
  public void setDefaultRenderKitId(String renderKitId);

  ---This value is configured in a JSF configuration file, and the default is “HTML_
BASIC” (which is represented by the RenderKitFactory.HTML_BASIC_RENDER_KIT
constant). You normally won’t need to reference this property, but it can be useful
in cases where you’re not sure what the default render kit is.

  public ValueBinding createValueBinding(String ref)
         throws ReferenceSyntaxException;
  public MethodBinding createMethodBinding(String ref, Class[] params)
         throws ReferenceSyntaxException;

----动态创建应用程序组件

  The Application class also has factory methods for creating several other
         types of objects, including UI components:
    public UIComponent createComponent(String componentType)
                    throws FacesException;
    public UIComponent createComponent(
            ValueBinding componentBinding,FacesContext context,String onentType)
                    throws FacesException;

----创建验证器

  public Validator createValidator(String validatorId)
             throws FacesException;
        A validator class’s identifier is made available through the VALIDATOR_ID constant.
         You may want to create a new Validator instance if you’re initializing a UI component
         in code. Validators can only be registered on components that implement
        the EditableValueHolder interface;

----创建转换器

  The following two methods can be used to create new Converter instances:
      public Converter createConverter(String converterId);
      public Converter createConverter(Class targetClass);
  You may remember from chapter 6 that converters can be registered by identifier
   or by type (Integer, Date, boolean, and so on). The first method creates a new Converter
based on its identifier, and the latter creates a new instance based on its
type. More often than not, you’ll use the first method because JSF handles the second
case for you automatically. Converter classes usually have a CONVERTER_ID constant
that equals their identifier. They can only be used with UI components that
implement the ValueHolder interface; see

  summery:

                    Whenever you need to create a new instance of these classes, you should use
    these methods rather than create the objects manually.

-------------值绑定对象

public String getExpressionString();
public Object getValue(FacesContext facesContext)
throws PropertyNotFoundException;
public void setValue(FacesContext facesContext,
Object object)
throws PropertyNotFoundException;



public boolean isReadOnly(FacesContext facesContext)
throws PropertyNotFoundException;
public Class getType(FacesContext facesContext)
throws PropertyNotFoundException;

Usually, you’ll just use getValue to retrieve the referenced object:
 User user = (User)app.createValueBinding("#{sessionScope.user}").
  getValue(facesContext);
  or setValue to set it:
  app.createValueBinding("#{sessionScope.user}").
  setValue(facesContext, user);
  PropertyNotFoundException is a runtime exception; you’re not forced to catch it.

-----方法绑定对象

public String getExpressionString();
public Object invoke(FacesContext context,
Object[] params)
throws EvaluationException,
MethodNotFoundException;
public Class getType(FacesContext context)
throws MethodNotFoundException;

public String getExpressionString();
public Object invoke(FacesContext context,
Object[] params)
throws EvaluationException,
MethodNotFoundException;
public Class getType(FacesContext context)
throws MethodNotFoundException;


        The getType method returns the class of the method’s return type.
When you’re developing applications, your use of MethodBinding will be somewhat
limited. You may, however, use it to set an action listener method, valuechange
listener method, or validator method on a specific UI component that
you are manipulating in code:

  ---动态添加

  MethodBinding mBinding =
        app.createMethodBinding("#{myBean.myActionListener}",new Class[] { ActionEvent.class } );
  myUICommand.setActionListener(mBinding);

----------context

     Context is a popular term in modern APIs. It’s all over the place in Java—EJBContext,
ServletContext, NamingContext, and so on. If you go to Dictionary.com and
look up context, you’ll find this definition: “The circumstances in which an event
occurs; a setting.” In the world of JavaServer Faces, that event is something the
user does with the UI like clicking on a hyperlink or expanding a node in a tree
control. Once event processing has begun, you have access to the application’s
setting, or state. This state is encapsulated in the FacesContext class, from which
you can access messages and the external context (which is provided by the servlet
or portlet container). This state is fleeting; it exists only while events are being
processed.




你可能感兴趣的:(UI,servlet,JSF,Access,Go)