想在jsf中使用ajax技术,于是前几天在论坛上高人的指导下使用了ajax4jsf包
并实现了一个功能,即——在页面上点一下按钮就可以增加一个inputtext
问题是现在如果使用自带的HtmlInputText组件就可以,使用我自己定义的组件HtmlMyInput就不行。。
是不是我的组件有问题?还是怎么回事?下面是我的组件的实现:组件的代码
package comp;import java.io.IOException;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;/**
 *
 * @author Administrator
 */
public class HtmlMyInput extends UIInput {    public HtmlMyInput() {
        setRendererType(null);
    }    public void encodeEnd(FacesContext context) throws IOException {        String clientId = getClientId(context);
        encodeInputField(context, clientId + ":inputfield1","test1:");
        encodeInputField(context, clientId + ":inputfield2","test2:");
        encodeInputField(context, clientId + ":inputfield3","test3:");
    }    public void encodeInputField(FacesContext context, String clientId,String s) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.writeText(s,null);
        writer.startElement("input", this);
        writer.writeAttribute("type", "text", null);
        writer.writeAttribute("name", clientId, "clientId");
        Object value = getValue();
        if (value != null) {
            writer.writeAttribute("value", value.toString(), "value");
        }
        writer.endElement("input");
    }}
下面是组件标签处理代码
package comp;import javax.faces.webapp.UIComponentTag;/**
 *
 * @author Administrator
 */
public class HtmlMyInputTag extends UIComponentTag {    public String getComponentType() {
        return "HtmlMyInput";
    }    public String getRendererType() {        return null;
    }
}tld code
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
    <tlib-version>1.0</tlib-version>
    <short-name>comp</short-name>
    <uri>http://jsfcompref.com/demo/comp</uri>
    <tag>
        <name>myinput</name>
        <tag-class>comp.HtmlMyInputTag</tag-class>
        <attribute>
            <name>id</name>
        </attribute>
        <attribute>
            <name>binding</name>
        </attribute>
        <attribute>
            <name>rendered</name>
        </attribute>
    </tag>
</taglib>