[英]How ui:include in jsf work?
我正在尝试制作模板,因此我不需要为xhtml页面编写2次相同的代码,但是当我需要更改页面的某些部分时,ui:include会出现问题,这取决于我要求的操作。明确的问题是当我需要在包含的页面上执行一些操作时,这是我的代码,因此您可以看到我在做什么。 这是我在其中使用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>
因此,您可以看到我正在某个弹出面板中执行include,并且可以看到include取决于某些参数。这是用户看到的页面的定义,并从中设置include参数。
<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按钮,而我真正需要的是简单的,则行不通。按钮,它会在我包含页面而不是单击时触发操作。
我希望我很清楚,你明白我的要求。 :)
尝试将execute =“ @ this”添加到命令按钮:
<a4j:commandButton value="Save" render="tabela" **execute="@this"**
action="#{ UserController.save(true)}"
oncomplete="#{rich:component('popup')}.hide()">
<a4j:param value="/sheard/admin/customer/view.xhtml" assignTo="#{ includeOption}"/>
</a4j:commandButton>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.