我一直在使用 JSF2.0 TomEE 1.7.3 开发一个网站。 在我问的最后一个问题中:
What are the recommended JSF dependencies with TomEE1.7.x?
我得到了建议并决定从 GlassFish(Mojarra) Faces 迁移到 myFaces,因为 myFaces 是 TomEE 的标准 JSF 实现。
然后我意识到,如果我使用 TomEE 的默认 myFaces,“OmniFaces v1.8.3 Form”不会使用“style”或“styleClass”渲染 css 类属性。它在 Mojarra 中工作得很好,但现在我的 HTML 布局被破坏了,我必须修复它。
我使用“OmniFaces Form”的原因是,我真的很想使用 includeRequestParams="true"
功能,并且这适用于 Mojarra 和 myFaces。
我的 xhtml 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:o="http://omnifaces.org/ui"
>
<h:body>
<ui:composition template="templates/common.xhtml">
<ui:define name="content">
<o:form prependId="false" styleClass="form-horizontal" includeRequestParams="true">
<!-- some inputText, labels, and buttons here -->
</o:form>
</ui:define>
</ui:composition>
</h:body>
</html>
我在 HTML 中得到的是:
<form id="j_id_1k" name="j_id_1k" method="post" action="/foo.xhtml">
class="form-horizontal"
未呈现。
我错过了什么吗? xmlns 是否错误或已弃用?
或者这只是模块之间的不一致,我对此无能为力?
或者是否有相当于 includeRequestParams
的东西?
我尝试过类似的方法,用 javascript 将 css 类附加到表单标签(我知道这不是一个好方法):
(function() {
var forms = document.forms;
for (var i = 0; i < forms.length; i++){
if (forms[i].id !== "headerForm"){
forms[i].class = "form-horizontal";
}
}
})();
但它没有修复布局,可能是因为 css 样式附加到表单内的对象,而不是表单本身(我正在使用 css bootstrap)。
请帮帮我!谢谢。
最佳答案
这是 <o:form>
中的一个错误。它initially扩展自 UIForm
类,但它没有定义所有非公共(public)属性。我fixed它从 HtmlForm
延伸相反,现在它在 MyFaces 中也适用于我。今天可使用 2.3-SNAPSHOT .
关于css - <o :form styleClass> not rendered when using MyFaces instead of Mojarra,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34471378/