ui:在h:form中定义

时间:2013-08-26 11:18:51

标签: jsf facelets

我有一个带有3 ui的模板:插入标签以显示在不同的地方。在我的创建用户页面上,我有这个:

<ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.CreateEmployeesTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form>
                <h:panelGrid columns="2">
                    <h:outputLabel value="#{bundle.CreateEmployeesLabel_businessUnitId}" for="businessUnitId" />
                    <h:selectOneMenu id="businessUnitId" value="#{employeesController.selected.businessUnitId}">
                        <f:selectItems value="#{businessUnitController.items}" var="a" itemLabel="#{a.description}" itemValue="#{a.id}" />
                    </h:selectOneMenu>
                    <h:outputLabel value="#{bundle.CreateEmployeesLabel_employeeTypesId}" for="employeeTypesId" />
                    <h:selectOneMenu id="employeeTypesId" value="#{employeesController.selected.employeeTypesId}">
                        <f:selectItems value="#{employeeTypesController.items}" var="b" itemLabel="#{b.description}" itemValue="#{b.id}" />
                    </h:selectOneMenu>
                    <h:outputLabel value="#{bundle.CreateEmployeesLabel_employeeManagersEmployeeNo}" for="employeeManagersEmployeeNo" />
                    <h:selectOneMenu id="employeeManagersEmployeeNo" value="#{employeesController.selected.employeeManagersEmployeeNo}">
                        <f:selectItems value="#{employeeManagersController.items}" var="c" itemLabel="#{c.name}" itemValue="#{c.employeeNo}" />
                    </h:selectOneMenu>
                </h:panelGrid>

                <ui:define name="li1">
                        <h:commandLink action="#{employeesController.create}" value="#{bundle.CreateEmployeesSaveLink}" styleClass="auto-style4" />
            </ui:define>
                <ui:define name="li2">
                        <h:commandLink action="#{employeesController.prepareList}" value="#{bundle.CreateEmployeesShowAllLink}" immediate="true" styleClass="auto-style4"/>
                </ui:define>

            </h:form>
        </ui:define>
    </ui:composition>

所以现在我的链接没有呈现,但是当我删除它底部的ui:define标签时,我之所以这样,是因为commandlinks将在右列上。什么可以替换ui:define以便我的命令链接仍在我的右栏中工作?

以下是我的模板示例:

<h:body>
        <div id="header-wrapper">
            <div class="container">
                <div class="row">
                    <div class="12u">
                        <header id="header">
                            <h1><a href="#" id="logo" ><img src="../resources/images/btttr.png" alt="logoo" class="left" /></a></h1>
                            <nav id="nav">
                                <ui:insert name="heads"></ui:insert>
                            </nav>
                        </header>
                    </div>
                </div>
            </div>
        </div>
        <div id="main">
            <div class="container">
                <div class="row main-row">
                    <div class="8u">
                        <section class="left-content">
                            <div>
                                <ui:insert name="pagetitle">Default Title</ui:insert>
                                <br/>
                                <br/>
                            </div>
                            <ui:insert name="body">Default Body</ui:insert>
                        </section>
                    </div>
                    <div class="4u">
                        <section>
                            <ul class="small-image-list">
                                <li>
                                    <li> 
                                        <ui:insert name="li1"></ui:insert></li>
                                    <li>
                                        <ui:insert name="li2"></ui:insert></li>
                                    <li>
                                        <ui:insert name="li3"></ui:insert></li>
                                    <li>
                                        <ui:insert name="li4"></ui:insert></li>
                                    <li>
                                        <ui:insert name="li5"></ui:insert></li>
                                </li>
                            </ul>
                        </section>
                    </div>
                </div>
            </div>
        </div>
    </h:body>

1 个答案:

答案 0 :(得分:0)

您无法在另一个<ui:define>内为同一模板嵌套<ui:define>。这没有任何意义。它不会神奇地改变模板组成。相反,必须修改模板本身,使得主体和链接以相同的形式结束。

一种方法是将<h:form>从模板客户端移至<div class="row main-row">。另一种方法是使用专门用于表单的另一个模板扩展模板。