<h:panelGroup layout ="block">不会向HTML呈现任何内容

MR.*_*OIS 1 jsf html-rendering

我试图在一个内部显示一些元素<h:panelGroup layout="block">.元素正在屏幕上显示,但HTML <div>根本没有呈现.

这是我的JSF代码:

<h:form id="editProfile">
    <div class="password-container">
        <h:outputText class="edit-header" value="Change Password &#8594;"></h:outputText>
        <br />
        <br />
        <!-- this div is not being displayed,
             THE ELEMENTS INSIDE THE PANELGROUP ARE BEING DISPLAYED -->
        <h:panelGroup layout="block">
            <h:inputText a:placeholder="Present Password" id="password" 
                value="#{editProfile.password}"
                class="cff-inputText"></h:inputText>
            <br />
            <h:inputText a:placeholder="New Password" id="change-password"
                class="cff-inputText"></h:inputText>
            <br />
            <button id="cancel-password" class="cff-button">Cancel</button>
            <button id="ok-password" class="cff-button">OK</button>
        </h:panelGroup>
    </div>
</h:form>
Run Code Online (Sandbox Code Playgroud)

这是生成的HTML输出:

 //This is not the panelGroup div
 <div class="password-container"><span class="edit-header">Change Password ?</span>
                       <br /><br />

   //These are the elements inside the div! but the panelGroup Div is not being rendered
   <input id="editProfile:password" type="text" name="editProfile:password" class="cff-inputText" placeholder="Present Password" />
       <br /><input id="editProfile:change-password" type="text" name="editProfile:change-password" class="cff-inputText" placeholder="New Password" />
       <br />
       <button id="cancel-password" class="cff-button">Cancel</button>
       <button id="ok-password" class="cff-button">OK</button>

 </div><input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="6732837357534288958:1301728140408675513" autocomplete="off" />
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我哪里出错了吗?

Emi*_*ęga 5

您需要添加id,stylestyleClass属性,可以肯定的,那<div>将被渲染.基本上,如果需要,它会添加一些东西.

文档:

适用于只能嵌套一个UIComponent子项的情况,例如facet.

在这种情况下,您可能应该使用plain <div>而不是h:panelGroup.

  • 我经常使用panelGroup根据`rendered`条件有条件地渲染<div>.或者,使用`<ui:fragment>` (2认同)