Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 自定义UIComponent的验证程序_Jsf_Jsf 2 - Fatal编程技术网

Jsf 自定义UIComponent的验证程序

Jsf 自定义UIComponent的验证程序,jsf,jsf-2,Jsf,Jsf 2,我正在编写自己的自定义组件扩展UIInput以及自定义渲染器。我希望我的组件在validator属性中应用方法表达式。但验证器属性不会呈现到html标记中。因此,writeAttribute(“validator”,validator,null)在这种情况下无效。我怎么能做到 我为UIInput编写了渲染器 @FacesRenderer(componentFamily = "javax.faces.Input", rendererType = "text") public class TextF

我正在编写自己的自定义组件扩展
UIInput
以及自定义渲染器。我希望我的组件在
validator
属性中应用方法表达式。但验证器属性不会呈现到html标记中。因此,
writeAttribute(“validator”,validator,null)
在这种情况下无效。我怎么能做到

我为
UIInput
编写了渲染器

@FacesRenderer(componentFamily = "javax.faces.Input", rendererType = "text")
public class TextFieldRenderer extends Renderer{
    @Override
    public void encodeBegin(FacesContext context, UIComponent component) throws IOException{
        String ClientId= component.getClientId(context);
        String hint= (String) component.getAttributes().get("placeholder");
        String styleClass= (String) component.getAttributes().get("styleClass");
        String value =(String) component.getAttributes().get("value");
        ResponseWriter writer= context.getResponseWriter();
        writer.startElement("input", component);
        writer.writeAttribute("type", "text", null);
        writer.writeAttribute("name", ClientId, null);
        writer.writeAttribute("placeholder", hint, "hint");
        writer.endElement("input");
    }
}
text.taglib.xml

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib>
    <namespace>http://text.com</namespace>
    <tag>
        <tag-name>hintText</tag-name>
        <component>
            <component-type>javax.faces.Input</component-type>
            <renderer-type>text</renderer-type>
        </component>
    </tag>
</facelet-taglib>
现在我编写
index.xhtml

<?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:lpform="http://xmlns.jcp.org/jsf/composite/lpform"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:text="http://text.com">
    <h:head></h:head>
    <h:body>
        <h:form>
            <text:hintText id="ht" placeholder="hint" validator="#{LBean.validateLoginField}">
                <f:validateLength minimum="4"/>
            </text:hintText>
            <h:commandButton value="sub"/>
            <h:message for="ht"/>
        </h:form>
    </h:body>
</html>


我想用
validator
属性验证
hintText
的值,就像它在
上执行一样。但是无论是
还是
验证程序=“#{LBean.validateLoginField}”
都不能验证我的
hintText

您能提供完整的代码吗?似乎无法通过提供的信息查看问题。@Xtreme Biker已更新。
<?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:lpform="http://xmlns.jcp.org/jsf/composite/lpform"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:text="http://text.com">
    <h:head></h:head>
    <h:body>
        <h:form>
            <text:hintText id="ht" placeholder="hint" validator="#{LBean.validateLoginField}">
                <f:validateLength minimum="4"/>
            </text:hintText>
            <h:commandButton value="sub"/>
            <h:message for="ht"/>
        </h:form>
    </h:body>
</html>