简体   繁体   English

ui:include在jsf中是如何工作的?

[英]How ui:include in jsf work?

I am trying to make templates so I don't need to write same code for xhtml page 2 times, but I have problem with ui:include when I have some parts of page that need to be change depends on what action I requested.To be clear problem is in when i need to have some actions on included page.Here is my code so you can see what I am doing. 我正在尝试制作模板,因此我不需要为xhtml页面编写2次相同的代码,但是当我需要更改页面的某些部分时,ui:include会出现问题,这取决于我要求的操作。明确的问题是当我需要在包含的页面上执行一些操作时,这是我的代码,因此您可以看到我在做什么。 This is template where I use include for parts that need to be different depends on what user want to do. 这是我在其中使用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>

so you can see that I am doing include inside some popup panel, and you can see that include depends on some parameter.Here is definition for page that user see and from which I set include parameter. 因此,您可以看到我正在某个弹出面板中执行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>

Here is page on which i have problem when I include it. 这是我将其包含在其中时遇到问题的页面。

<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>

In code above one ajax button is actually commented in my code but I deleted comments here because if I leave it here it will not show that part of code in question. 在上面的代码中,实际上在我的代码中添加了一个ajax按钮的注释,但是我在这里删除了注释,因为如果我将其保留在此处,它将不会显示该部分代码。

Now when I gave you all code you need I will tell you what is problem.You see problem is with this buttons on included page if i use this ajax button which I actually need it's simple don't work.And if I use just simple button it trigger action in moment I include page and not on click. 现在,当我给您所有代码时,您将需要告诉我什么问题。您看到问题出在包含页面上的此按钮上,如果我使用此ajax按钮,而我真正需要的是简单的,则行不通。按钮,它会在我包含页面而不是单击时触发操作。

I hope i was clear and you get it what I ask. 我希望我很清楚,你明白我的要求。 :) :)

Try adding execute="@this" to the command button: 尝试将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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM