JSF panelGroup - 1跨度为所有?

时间:2010-01-13 14:48:14

标签: java jsf layout

我想使用panelGroup对输入及其标签进行分组

e.g

<h:panelGroup styleClass="#{jsfServicesError.errorClass}" binding="#{jsfServicesError.myComponent}">
<h:outputLabel for="company" id="companyLabel" value="#{bundle.IDENTITY_COMPANY} * :"/>
<h:inputText id="company" label="#{bundle.IDENTITY_COMPANY}" value="#{manager.uiUser.attribute.company}" required="true" styleClass="text normal">
    <f:validateLength minimum="3"/>
</h:inputText>
</h:panelGroup>

如果我将一些其他的panelGroup放在一个后面,我得到的结果是1 span类,其中包括所有其他输入和标签。这是否按预期工作?

1 个答案:

答案 0 :(得分:4)

我在Tomcat 6.0.20上使用Mojarra 1.2_14创建了SSCCE

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<f:view>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>SO question 2057438</title>
        </head>
        <body>
            <h:form>
                <h:panelGroup styleClass="foo">
                    <h:outputLabel for="input1" value="label1" />
                    <h:inputText id="input1" />
                </h:panelGroup>
                <h:panelGroup styleClass="foo">
                    <h:outputLabel for="input2" value="label2" />
                    <h:inputText id="input2" />
                </h:panelGroup>
                <h:panelGroup styleClass="foo">
                    <h:outputLabel for="input3" value="label3" />
                    <h:inputText id="input3" />
                </h:panelGroup>
            </h:form>
        </body>
    </html>
</f:view>

输出与预期一致:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>So question 2057438</title>
    </head>
    <body>
        <form id="j_id_jsp_452028652_1" name="j_id_jsp_452028652_1" method="post"
            action="/playground/test.jsf" enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_id_jsp_452028652_1" value="j_id_jsp_452028652_1" />
            <span class="foo">
                <label for="j_id_jsp_452028652_1:input1"> label1</label>
                <input id="j_id_jsp_452028652_1:input1" type="text" name="j_id_jsp_452028652_1:input1" />
            </span>
            <span class="foo">
                <label for="j_id_jsp_452028652_1:input2"> label2</label>
                <input id="j_id_jsp_452028652_1:input2" type="text" name="j_id_jsp_452028652_1:input2" />
            </span>
            <span class="foo">
                <label for="j_id_jsp_452028652_1:input3"> label3</label>
                <input id="j_id_jsp_452028652_1:input3" type="text" name="j_id_jsp_452028652_1:input3" />
            </span>
            <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id1:j_id2" />
        </form>
    </body>
</html>

你的问题出在其他地方。也许您实际上没有查看生成的HTML输出,或者您希望多个面板组在彼此之下对齐。如果后者属实,那么您需要将layout="block"添加到h:panelGroup,以便它将呈现<div>。 HTML <div>元素默认为元素,而HTML <span>元素为内嵌元素。粗略地说,像<form><div><table><ul>等HTML块元素隐含地添加了一个换行符,以便任何下一个元素可视地从一个新行开始。< / p>

如果你仍然使用古老的JSF 1.1或更早版本h:panelGroup没有layout属性,那么你需要在课堂上添加CSS display: block<span>元素相关联。