现在位置:首页->学习专题->JSF专题
元件标签
作者: 日期: 2007-4-5 14:25:20 访问次数:出处:
 显示选项:自动滚屏[左键停止]
 

  完成Component的自订,接下来要设定一个自订Tag与之对应,自订Tag的目的,在于设定 Component属性,取得Componenty型态,取得Renderer型态值等;属性的设定包括了设定静态值、设定绑定值、设定验证器等等。

  要自订与Component对应的Tag,您可以继承UIComponentTag,例如:

TextWithCmdTag.java

package onlyfun.caterpillar;

 

 import javax.faces.application.Application;

 import javax.faces.component.UIComponent;

 import javax.faces.context.FacesContext;

 import javax.faces.el.ValueBinding;

 import javax.faces.webapp.UIComponentTag;

 

 public class TextWithCmdTag extends UIComponentTag {

    private String size;

    private String value;

   

    public String getComponentType() {

        return "onlyfun.caterpillar.TextWithCmd";

    }

 

    public String getRendererType() {

        return null;

    }

 

    public void setProperties(UIComponent component) {

        super.setProperties(component);

       

        setStringProperty(component, "size", size);

        setStringProperty(component, "value", value);

    }

   

    private void setStringProperty(UIComponent component,

                       String attrName, String attrValue) {

        if(attrValue == null)

            return;

       

        if(isValueReference(attrValue)) {

            FacesContext context =

                         FacesContext.getCurrentInstance();

            Application application =

                         context.getApplication();

            ValueBinding binding =

                   application.createValueBinding(attrValue);

            component.setValueBinding(attrName, binding);

        }

        else {

            component.getAttributes().

                          put(attrName, attrValue);

        }

    }

   

    public void release() {

        super.release();

        size = null;

        value = null;

    }

   

    public String getSize() {

        return size;

    }

 

    public void setSize(String size) {

        this.size = size;

⊕相关文章
  • ·编码、解码
  • ·自订JSF元件
  • ·JSF生命周期
  • ·TableModel类别
  • ·表头、表尾
  • ·简单的表格