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. This is template where I use include
for parts that need to be different depends on what user want to do.
<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.
<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"/>
--> --> -->
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.
I hope i was clear and you get it what I ask. :)
No comments:
Post a Comment