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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/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 渲染器的编码方法_Jsf_Jsf 2 - Fatal编程技术网

Jsf 渲染器的编码方法

Jsf 渲染器的编码方法,jsf,jsf-2,Jsf,Jsf 2,我为UIInput提供了自定义渲染器的编码方法 public void encodeBegin(FacesContext context, UIComponent component) throws IOException { String ClientId = component.getClientId(context); String hint = (String) component.getAttributes().get("placeholder"); Strin

我为
UIInput
提供了自定义渲染器的编码方法

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.writeAttribute("name", ClientId, null);
    writer.writeAttribute("placeholder", hint, "hint");
    writer.startElement("input", component);
    writer.writeAttribute("class", styleClass, "styleClass");
    writer.writeAttribute("value", ((UIInput) component).getValue(), "value");
    writer.endElement("input");
}

在我写了两个属性之后,我正在写
startElement
,但它可以工作。即
startElement
方法如何工作?我们能在先前的
元素
endElement
之前和
endElement
之后的任何地方
startElement
吗?这很令人惊讶<代码>writer.writeAttribute(“name”,ClientId,null)
应该抛出一个
非法状态异常
。关于
startElement
endElement
,请参阅:

startElement…
调用此方法后,客户端可以调用
writeAttribute()
writeriattribute()
方法来添加属性和相应的值。任何后续调用
startElement()
writeComment()
writeText()
endElement()
endDocument()
endDocument()
close()
flush()
,或
write()
,都将关闭起始元素(即添加了尾随字符)


writeAttribute(“name”,ClientId,null)应该抛出一个非法状态异常为什么?这个例子来自核心JavaSerever Faces第三版。调用此方法后,客户端可以调用writeAttribute()或WriteUriaAttribute()方法来添加属性和相应的值。也就是说,我们可以在startElement调用之前写入属性?@St.Antario-javadoc表明这是一个非法操作。在调用任何
startElement
之前调用
writeAttribute
应引发
IllegalStateException
,因为所写入的属性没有上下文。这将导致无效的HTML。编写器如何知道属性要写入到哪个元素?我不推荐。没有理由这么做anyway@St.Antario您可以检查答案中的javadoc链接以确认
writeAttribute
的行为这是
UIInput
的自定义渲染示例:首先我们写入附加属性,然后调用who contains
startElement
方法,然后
illegalStateException