我正在尝试制作模板,所以我不需要为 xhtml 页面编写相同的代码 2 次,但是我有 ui:include 的问题,当我有页面的某些部分需要更改时,取决于我请求的操作。明确的问题是当我需要在包含的页面上进行一些操作时。这是我的代码,所以你可以看到我在做什么。这是我使用包含的模板,需要不同的部分取决于用户想要做什么。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/sheard/template.xhtml">
<ui:define name="body">
<rich:message/>
<ui:include src="/sheard/admin/admin_header.xhtml" />
<a4j:outputPanel id="tabela">
<h:form>
<rich:panel>
<f:facet name="header">
<h:outputText value="#{ title}" />
</f:facet>
<rich:dataTable value="#{ data}" var="model" iterationStatusVar="it">
<rich:column style="width:50px">
<f:facet name="header">Red br.</f:facet>
<h:outputText value="#{it.index+1}" />
</rich:column>
<ui:insert name="table_body"/>
</rich:dataTable>
</rich:panel>
</h:form>
</a4j:outputPanel>
<h:form prependId="false">
<rich:popupPanel id="popup" modal="true"
width="500" moveable="true"
resizeable="false" domElementAttachment="form">
<f:facet name="header">
<h:outputText value="Pregled Korisnika" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#"
onclick="#{rich:component('popup')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
<a4j:outputPanel id="popup_internal">
<ui:include src="#{ includeOption}" />
</a4j:outputPanel>
</rich:popupPanel>
</h:form>
</ui:define>
<ui:define name="footer">
<h:outputLink value="rentacar.xhtml">Glavni meni</h:outputLink>
<br />
<h:form>
<ui:insert name="footer_menu"/>
<br />
<h:commandLink value="Logout" action="#{ LogInControler.LogOut()}" />
</h:form>
</ui:define>
</ui:composition>
所以你可以看到我在一些弹出面板中包含,你可以看到包含取决于一些参数。这是用户看到的页面的定义,我从中设置了包含参数。
<ui:composition template="/sheard/admin/pregled_template.xhtml">
<ui:param name="title" value="Pregled musterija" />
<ui:param name="data" value="#{ DataFetcher.fetchUsers()}" />
<ui:define name="table_body">
<rich:column style="width:150px">
<f:facet name="header">JMBG</f:facet>
<h:outputText value="#{model.JMBG}" />
</rich:column>
<rich:column style="width:150px">
<f:facet name="header">Ime</f:facet>
<h:outputText value="#{model.ime}" />
</rich:column>
<rich:column style="width:150px">
<f:facet name="header">Prezime</f:facet>
<h:outputText value="#{model.prezime}" />
</rich:column>
<rich:column style="width:250px">
<f:facet name="header">Adresa</f:facet>
<h:outputText value="#{model.adresa}" />
</rich:column>
<rich:column style="width:150px">
<a4j:commandButton value="View" render="popup_internal"
action="#{ UserController.viewCustomer(model.username)}"
oncomplete="#{rich:component('popup')}.show()">
<a4j:param value="/sheard/admin/customer/view.xhtml" assignTo="#{ includeOption}"/>
</a4j:commandButton>
<a4j:commandButton value="Edit" render="popup_internal"
action="#{ UserController.edit(model)}"
oncomplete="#{rich:component('popup')}.show()">
<a4j:param value="/sheard/admin/customer/edit.xhtml" assignTo="#{ includeOption}"/>
</a4j:commandButton>
<a4j:commandButton value="Delete" render="tabela"
action="#{ UserController.delete(model)}" >
</a4j:commandButton>
</rich:column>
</ui:define>
<ui:define name="footer_menu">
<h:commandLink action="#{UserController.newCustomer()}" value="Unost musterija" />
</ui:define>
</ui:composition>
这是我在包含它时遇到问题的页面。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
template="/sheard/admin/popup_panel_template.xhtml">
<ui:param name="columnCount" value="3" />
<ui:define name="popup_panel_body">
<rich:validator>
<h:outputText value="Username:" />
<h:inputText id="username" value="#{ UserController.user.username}" />
<rich:message for="username"/>
<h:outputText value="Ime:" />
<h:inputText id="ime" value="#{ UserController.user.ime}" />
<rich:message for="ime"/>
<h:outputText value="Prezime:" />
<h:inputText id="prezime" value="#{ UserController.user.prezime}" />
<rich:message for="prezime"/>
<h:outputText value="Adresa:" />
<h:inputText id="adresa" value="#{ UserController.user.adresa}" />
<rich:message for="adresa"/>
<h:outputText value="E-mail:" />
<h:inputText id="email" value="#{ UserController.user.email}" />
<rich:message for="email"/>
<h:outputText value="Kategorije:" />
<h:selectManyCheckbox id = "kategorija" value="#{UserController.user.kategorijaList}" >
<f:selectItem itemValue='A' />
<f:selectItem itemValue='B'/>
<f:selectItem itemValue='C'/>
<f:selectItem itemValue='D'/>
</h:selectManyCheckbox>
<rich:message for="kategorija"/>
<a4j:commandButton value="Save" render="tabela"
action="#{ UserController.save(true)}"
oncomplete="#{rich:component('popup')}.hide()">
<a4j:param value="/sheard/admin/customer/view.xhtml" assignTo="#{ includeOption}"/>
</a4j:commandButton>
<h:commandButton value="Save" type="submit" action="#{UserController.save(true)}"/>
<h:commandButton value="Reset" type="reset"/>
</rich:validator>
</ui:define>
在上面的代码中,我的代码中实际上对一个 ajax 按钮进行了注释,但我在这里删除了注释,因为如果我把它留在这里,它将不会显示有问题的那部分代码。
现在,当我给你所有你需要的代码时,我会告诉你什么是问题。如果我使用这个我真正需要的 ajax 按钮,你会看到问题出在包含页面上的这个按钮,它很简单,不起作用。如果我只使用简单按钮它在我包含页面而不是点击时触发动作。
我希望我很清楚,你明白我的要求。:)