gpt4 book ai didi

jsf - 从 4.0 升级到 Primefaces 5.1 后未呈现主体属性(onkeydown、onkeyup...)

转载 作者:行者123 更新时间:2023-12-05 00:24:12 25 4
gpt4 key购买 nike

我已经建立了一个具有以下依赖项的简单 maven 项目:

<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.1-b04</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.6.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.2.Final</version>
</dependency>

<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>

</dependencies>

而这个页面:
<?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:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:body onkeydown="alert('You pressed some key!')">
<h:outputLabel value="Hello, young fellows!"/>
</h:body>
</html>

这是生成的 html,注意没有方法的 body 标签:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body><label>Hello, young fellows!</label></body>
</html>

我尝试通过更改 pom.xml 中的依赖项版本将 primefaces 版本回滚到 4.0,如下所示:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>

然后它按预期工作:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><body onkeydown="alert('You pressed some key!')"><label>Hello, young fellows!</label></body>
</html>

问题是什么?它是 PF 5.1 上的错误还是其他什么?

最佳答案

从 5.0 开始 h:body有一个 renderer在 PrimeFaces 中, BodyRenderer .

encodeBegin该渲染器的数组 attributes正在通过, HTML.BODY_ATTRS .

public static final String[] BODY_ATTRS = {
"dir",
"lang",
"style",
"onload",
"onunload"
};

正如你所看到的,这个数组由于某种原因没有涵盖 h:body 的所有实际属性。标签,因此一些属性被忽略。

为了避免这个问题,您可以简单地将该渲染器扩展为接受所有实际属性的渲染器。
public class CustomBodyRenderer extends BodyRenderer{

//our array with all the attributes of h:body tag
public static final String[] BODY_ATTRS = {
"dir",
"lang",
"onclick",
"ondblclick",
"onkeydown",
"onkeypress",
"onkeyup",
"onmousedown",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"style",
"title",
"onload",
"onunload"
};

@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
String clientId = component.getClientId(context);
writer.startElement("body", component);

if (shouldWriteId(component)) {
writer.writeAttribute("id", clientId, "id");
}

String styleClass = (String) component.getAttributes().get("styleClass");
if (styleClass != null && styleClass.length() != 0) {
writer.writeAttribute("class", styleClass, "styleClass");
}
//the only changed line from the original renderer
renderPassThruAttributes(context, component, BODY_ATTRS);
}

}

然后在 注册面孔配置

<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>javax.faces.Body</renderer-type>
<renderer-class>com.hatemalimam.CustomBodyRenderer</renderer-class>
</renderer>
</render-kit>

这样,您将在“最小”更改中获得预期结果。

我已提交 issue在跟踪器上。

更新:
这已在 PF 5.2 中修复。

关于jsf - 从 4.0 升级到 Primefaces 5.1 后未呈现主体属性(onkeydown、onkeyup...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26721555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com