Java 如何在JSF2中指定body id属性?
我需要为selenium测试设置html body标记的id属性。但是JSF2 body标记没有id属性 那么,我如何在JSF2中为html主体指定id属性呢?当然,也让我感到惊讶的是,它确实不支持id属性;它在HTML中完全有效。我已经向JSF人员报告了 同时,假设您正在使用Mojarra,您可以通过扩展Mojarra的BodyRenderer来解决此问题,如下所示:Java 如何在JSF2中指定body id属性?,java,jsf,jsf-2,Java,Jsf,Jsf 2,我需要为selenium测试设置html body标记的id属性。但是JSF2 body标记没有id属性 那么,我如何在JSF2中为html主体指定id属性呢?当然,也让我感到惊讶的是,它确实不支持id属性;它在HTML中完全有效。我已经向JSF人员报告了 同时,假设您正在使用Mojarra,您可以通过扩展Mojarra的BodyRenderer来解决此问题,如下所示: package com.example; import java.io.IOException; import javax
package com.example;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import com.sun.faces.renderkit.html_basic.BodyRenderer;
public class BodyWithIdRenderer extends BodyRenderer {
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
super.encodeBegin(context, component);
if (component.getId() != null) {
context.getResponseWriter().writeAttribute("id", component.getClientId(context), "id");
}
}
}
要使其运行,请按如下所示在faces-config.xml中注册它不,@facesrender注释魔术无法覆盖标准渲染器
javax.faces.Output
javax.faces.Body
com.example.BodyWithIdRenderer
诚然,我也感到惊讶的是,政府确实不支持它;它在HTML中完全有效。我已经向JSF人员报告了
同时,假设您正在使用Mojarra,您可以通过扩展Mojarra的BodyRenderer来解决此问题,如下所示:
package com.example;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import com.sun.faces.renderkit.html_basic.BodyRenderer;
public class BodyWithIdRenderer extends BodyRenderer {
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
super.encodeBegin(context, component);
if (component.getId() != null) {
context.getResponseWriter().writeAttribute("id", component.getClientId(context), "id");
}
}
}
要使其运行,请按如下所示在faces-config.xml中注册它不,@facesrender注释魔术无法覆盖标准渲染器
javax.faces.Output
javax.faces.Body
com.example.BodyWithIdRenderer
您好,它看起来很有魅力,但是当我尝试在eclipse之外安装mvn时,我得到了以下错误:包com.sun.faces.renderkit.html_basic不存在。有什么想法吗?@Alex:对不起,Maven超出了我的理解范围,这与所问的具体问题无关。按“询问问题”按钮询问新问题。@Alex:噢,请注意,自Mojarra 2.1.8以来,已根据链接的票证修复了2409号问题。您也可以升级它以便使用:您好,它看起来很有魅力,但是当我尝试在eclipse之外安装mvn时,会出现以下错误:包com.sun.faces.renderkit.html_basic不存在。有什么想法吗?@Alex:对不起,Maven超出了我的理解范围,这与所问的具体问题无关。按“询问问题”按钮询问新问题。@Alex:噢,请注意,自Mojarra 2.1.8以来,已根据链接的票证修复了2409号问题。您不妨升级它,以便使用: