I'm using PrimeFaces 3.4. I have p:layout with p:tree in left layout unit, and the list of panels in the central unit. After selecting/unselecting the nodes on tree I'm rendering/unrendering the panels. The general structure looks like that:
<p:layoutUnit position="west" minSize="150" size="300">
<h:form id="tree">
<p:tree id="tree" value="#{tree.root}" var="node"
selectionMode="multiple" selection="#{tree.selectedNodes}">
<p:ajax event="select" listener="#{tree.treeSelect}" process=":main" update=":main:panels"/>
<p:ajax event="unselect" listener="#{tree.treeUnselect}" process=":main" update=":main:panels"/>
<p:treeNode>
<h:outputText value="#{node.title}" />
</p:treeNode>
</p:tree>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center" header="Panels" styleClass="noscroll">
<h:form id="main">
<p:outputPanel id="panels" styleClass="center-panels">
<!-- here go the panels -->
</p:outputPanel>
</h:form>
</p:layoutUnit>
But the panels contains the input fields. I've noticed, that the input fields are reseted after click on tree, so I've added the process attribute. I've tried with :main, :main:panels, #all, but none of them have functioned.
How can I work correctly with that scenario? PrimeFaces bugture (a bug that is feature) doesn't allow using single form when you are using p:layout, at least this is stated in documentation. And using multiple forms, I'm loosing data.
This is working for me:
<p:layoutUnit position="west" header="Opciones" size="175">
<h:form id="form1">
<p:panelMenu style="width:200px">
<p:submenu label="Clientes" >
<p:menuitem value="Adicionar" update=":form2" actionListener="# {templateMB.templateAddCliente}" />
<p:menuitem value="Buscar"/>
<p:menuitem value="Listado"/>
<p:menuitem value="Editar"/>
</p:submenu>
<p:submenu label="Contratos">
<p:menuitem value="Adicionar" icon="ui-icon-close"/>
</p:submenu>
<p:separator/>
<p:submenu label="Suplementos" >
<p:menuitem value="Adicionar" icon="ui-icon-signal"/>
</p:submenu>
</p:panelMenu>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:form id="form2">
<ui:include src="#{templateMB.centerTemplate}" />
</h:form>
</p:layoutUnit>
Related
I have a JSF application. In the home.xhtml, I have included 4 tabs. Each tab is a different xhtml form. The first form has an action listener. The problem is on all 4 tabs if I refresh (F5) the page, the action listener gets called.
On click of the command button, I check the DB to check if there are existing employees with the same details. If yes, I show the confirm dialog to proceed with Generation. If the user clicks Yes here, the new ID is generated. This generation function gets called again and again if I refresh the page. I made the call as ajax="false" as well but it does not help. If I make ajax="true", It does not let me change the tabs. The page sort of hangs. Please suggest me on how to stop this.
<h:form id="employeeIdGenerationForm" prependId="false">
<p:confirmDialog id="confirmationID" widgetVar="confirmationVar" header="Confirmation" showEffect="fade" hideEffect="explode"
message="#{employeeMaintenanceBean.employee.getWarningsList()}"
rendered="#{employeeMaintenanceBean.showExistingEmployeeWarning}" closable="false">
<p:commandButton value="Yes" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" onclick="PF('confirmationVar').hide()"
actionListener="#{employeeMaintenanceBean.generateEmployeeID}" ajax="false"
update="#form:confirmation #form:msgPanel_EmployeeIDGeneration #form:firstName #form:surName" />
<p:commandButton value="No" styleClass="ui-confirmdialog-no" icon="ui-icon-close" onclick="PF('confirmationVar').hide()"/>
</p:confirmDialog>
<p:panel styleClass="messagePanel"
style="color: #004986; font-size: 15px;"
header="New Employee ID Generation">
<br />
<h:panelGrid columns="1" id="msgPanel_EmployeeIDGeneration"
width="100%" align="center" style="text-align:center;">
<p:messages />
</h:panelGrid>
<h:panelGrid columns="2" border="0">
<h:outputLabel styleClass="label" value="First Name" />
<p:inputText value="#{employeeMaintenanceBean.employee.firstName}"
id="firstName" required="true"
requiredMessage="First Name is mandatory" maxlength="50"
styleClass="value" />
<h:outputLabel styleClass="label" value="Last Name" />
<p:inputText value="#{employeeMaintenanceBean.employee.lastName}"
id="surName" required="true"
requiredMessage="Last Name is mandatory" maxlength="50"
styleClass="value" />
<h:outputLabel styleClass="label" value="Comments" />
<p:inputTextarea
value="#{employeeMaintenanceBean.employee.comments}" id="comments"
maxlength="256" styleClass="value" />
<p:commandButton id="generateID" ajax="false"
actionListener="#{employeeMaintenanceBean.isExistingEmployee}"
title="Generate Employee ID" value="Generate Employee ID" update="#form:confirmationID #form:msgPanel_EmployeeIDGeneration">
</p:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
The main home.xhtml is:
<h:head/>
<h:body>
<ui:composition template="/template/common/commonLayout.xhtml">
<ui:define name="content">
<p:idleMonitor timeout="300000">
<p:ajax event="idle" listener="#{baseBean.sessionTimeOut}"/>
</p:idleMonitor>
<p:tabView id="tabView" activeIndex="#{tabViewBean.mainTabActiveIndex}" dynamic="true" cache="false">
<p:ajax event="tabChange" listener="#{tabViewBean.onMainTabChange}" update="tabView" />
<p:tab id="employeeIdGeneration" title="New Employee ID Generation" rendered="#{tabViewBean.currentUser.hasAccessToPage('employeeIdGeneration')}">
<ui:include src="employeeIdGeneration.xhtml"/>
</p:tab>
<p:tab id="employeeMaintenance" title="Update New Employee Details" rendered="#{tabViewBean.currentUser.hasAccessToPage('employeeMaintenance')}">
<ui:include src="employeeIdMaintenance.xhtml"/>
</p:tab>
<p:tab id="employeeHistoryView" title="New Employee Update History" rendered="#{tabViewBean.currentUser.hasAccessToPage('employeeHistoryView')}">
<ui:include src="employeeHistoryView.xhtml"/>
</p:tab>
<p:tab id="userAccessMaintenance" title="User Access Maintenance" rendered="#{tabViewBean.currentUser.hasAccessToPage('userAccessMaintenance')}">
<ui:include src="userMaintenance.xhtml"/>
</p:tab>
</p:tabView>
</ui:define>
</ui:composition>
</h:body>
My env. is : Primefaces 5.1; jdk 7.0.40;JSF 2.0 (Mojarra 2.03-FCS); Tomcat 7.0.
I build a p:selectOneListbox and the p:contextMenu : all works fine. The problem is : how to retrieve which item in the list fired the contextMenu (that correctly appears on right click) when no selection was yet performed ?
<h:form id="recipeFilesForm">
<h:outputText value="Recipe files" style="position:relative;left:40px;font-size:0.9em;" />
<p:selectOneListbox id="recipeFileList" value="#{RecipeFormMngr0.selecteduserFileIndex}"
style="width:190px;font-size:0.7em;text-align:left;position:relative;left:-24px">
<f:selectItems value="#{RecipeFormMngr0.recipeFileNamesItems}" var="u" itemLabel="#{u.label}" itemValue="#{u.value}">
</f:selectItems>
<p:ajax event="click" listener="#{RecipeFormMngr0.selecteduserFileIndexSelected}" />
</p:selectOneListbox>
<p:contextMenu for="recipeFileList" style="font-size:0.7em;">
<p:menuitem value="Show" actionListener="#{RecipeFormMngr0.showRecipeContent}" ajax="true" process=":loginForm0_1:userSettingTab:recipeFilesForm" />
<p:menuitem value="Delete" actionListener="#{RecipeFormMngr0.deleteRecipeFile}" ajax="true" process=":loginForm0_1:userSettingTab:recipeFilesForm" />
<p:menuitem value="Edit" actionListener="#{RecipeFormMngr0.editRecipeContent}" ajax="true" process=":loginForm0_1:userSettingTab:recipeFilesForm" />
</p:contextMenu>
</h:form>
I have a page with a tabView, with 3 tabs, each tab has a tree. The tree of the third tab (DEVICES CATEGORY/TYPE), depends on what I select in the tree of the second tab (CERTIFICATIONS SYSTEM/PROGRAM). I generate the tree of the third tab dynamically when tab changes, using the event "tabChange"
<p:ajax event="tabChange" listener="#{profileMB.onTabChange}" />
When I select an element of the tree of the second tab and I change to the third tab, for the first time, it works OK, but when I return to the second tab and I mark differents nodes of the tree and I change to the third tab, the third tabs doesn't refresh.
The methods of the event it works OK, and generate the tree well.
public void onTabChange(TabChangeEvent event) {
log.debug(Constants.BEGIN);
if(selectedNodesCS!=null && selectedNodesCS.length>0){
rootDeviceCategory =
getDeviceCategoryService().createRootStructure(rootDeviceCategory, null,listCertSystem,listCertProgram);
}
}
I tried using the update in the ajax event "tabChange":
<p:ajax event="tabChange" listener="#{profileMB.onTabChange}" update=":formManagerProfile:tabsProfile:tabDC" />
but the console says:
Can not update component "org.primefaces.component.tabview.Tab" with id "formManagerProfile:tabsProfile:tabDC" without a attached renderer
This is the code of my XHTML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form id="formManagerProfile" style="margin: auto auto">
<h:panelGroup id="displayManager">
<p:panelGrid id="panelUp" style="text-align: left;"
styleClass="panelGridWithoutBorder">
<p:row>
<p:column>
<h:outputText value="#{msg['profile.name']}: " for="profileName" />
</p:column>
<p:column>
<h:inputText id="profileName" value="#{profileMB.profileName}"
maxlength="64" styleClass="width-100x100" />
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputText value="#{msg['profile.profileGroup']}: "
for="profileGroup" />
</p:column>
<p:column>
<p:selectOneMenu id="profileGroup"
value="#{profileMB.profileGroupSelected}"
converter="#{selectOneMenuConverterSelf}">
<f:selectItem itemLabel="" itemValue="#{null}" />
<f:selectItems id="pgSelectedItem"
value="#{profileMB.listProfileGroups}" var="pgItem"
itemValue="#{pgItem}" itemLabel="#{pgItem.name}" />
</p:selectOneMenu>
</p:column>
<p:column>
<p:commandButton id="editProfileGroup"
icon="#{msg['icon.update']}"
value="#{msg['button.text.updateProfileGroup']}"
title="#{msg['button.text.updateProfileGroup']}"
actionListener="#{profileMB.managementProfileGroup}"
update=":managerProfileGroupForm :growl"
oncomplete="PF('profileGroupManagerDialogWidget').initPosition();PF('profileGroupManagerDialogWidget').show()" />
</p:column>
</p:row>
</p:panelGrid>
<p:panel styleClass="text_align_left">
<p:commandButton id="saveButtonUp" icon="#{msg['icon.save']}"
value="#{msg['button.text.save']}"
title="#{msg['button.text.save']}"
action="#{profileMB.saveProfile}" update=":growl" />
<p:commandButton id="backButtonUp" icon="#{msg['icon.back']}"
value="#{msg['button.text.back']}"
title="#{msg['button.text.back']}" action="#{profileMB.backAction}"
ajax="false" />
</p:panel>
</h:panelGroup>
<h:panelGroup>
<p:tabView id="tabsProfile" dynamic="true">
<p:ajax event="tabChange" listener="#{profileMB.onTabChange}" />
<p:tab id="tabMenu" title="MENUS">
<p:tree value="#{profileMB.rootAction}" var="elementAction"
selectionMode="checkbox" selection="#{profileMB.selectedNodes}">
<p:treeNode>
<h:outputText value="#{elementAction}" />
</p:treeNode>
</p:tree>
</p:tab>
<p:tab id="tabCS" title="CERTIFICATIONS SYSTEM/PROGRAM">
<p:tree id="TreeCS" value="#{profileMB.rootCertSystem}"
var="elementCS" selectionMode="checkbox"
selection="#{profileMB.selectedNodesCS}">
<!-- <p:ajax event="select" listener="#{profileMB.onClickTreeCS}" /> -->
<!-- <p:ajax event="unselect" listener="#{profileMB.onClickUnSelectTreeCS}" /> -->
<p:ajax async="true" delay="none" immediate="true"
process="TreeCS" event="select" />
<p:ajax async="true" delay="none" immediate="true"
process="TreeCS" event="unselect" />
<p:treeNode>
<h:outputText value="#{elementCS}" />
</p:treeNode>
</p:tree>
</p:tab>
<p:tab id="tabDC" title="DEVICES CATEGORY/TYPE">
<p:tree id="TreeDC" value="#{profileMB.rootDeviceCategory}"
var="elementDC" selectionMode="checkbox"
selection="#{profileMB.selectedNodesDevCat}">
<p:ajax event="select" listener="#{profileMB.onClickTreeDC}" />
<p:ajax event="unselect"
listener="#{profileMB.onClickUnSelectTreeDC}" />
<p:treeNode>
<h:outputText value="#{elementDC}" />
</p:treeNode>
</p:tree>
</p:tab>
</p:tabView>
</h:panelGroup>
</h:form>
</ui:composition>
I'm using primefaces v5.1, JSF v2.2.8, spring v3.2.5, hibernate v4.2.7 and java v1.7
I found the solution in p:tabView I must used cache="false"
Hi I have some validation on my form (Java web application), and when the validation is displayed, it should reload the page. When it does this, I lose all the data input in the dropdown list in first tab.(Data in text boxes are retained)
Below is how I define my tabview :
<p:tabView id="tabView" dynamic="true">
Anyone can help on this? Thanks in Advance
I am using PrimeFaces 4.0, spring, hibernate.
<h:form prependId="false">
<p:panel>
<h:panelGrid id="detail" columns="2" styleClass="grid"columnClasses="label,value">
<p:tabView id="tabView" dynamic="true" >
<p:tab id="tab1" title="bUS Details">
<h:outputTextvalue="#{ebusmsgs['ebus.bustitle.title']}:" />
<h:inputText id="ebus_bustitle" value="#{BusComponent.bus.empMinDiv}" />
</p:tab>
<p:tab id="tab2" title="Mechanic Details">
<h:outputTextvalue="#{ebusmsgs['ebus.mechanictitle.title']}:" />
<h:inputText id="ebus_mechanictitle" value="#{BusComponent.bus.empMinDiv}" />
</p:tab>
</p:tabView>
</h:panelGrid>
</p:panel>
</h:form>
I want to render the panel content by the value in the submenu selected .But the panel is not rendered.Is there anyother way to render the panel in submenu
<h:panelGroup id="menu" layout="block">
<h:form>
<h:outputStylesheet name="css/primefaces.css" />
<p:growl id="messages" autoUpdate="true" />
<f:ajax event="click" render=":content">
<p:panelMenu style="width:200px " styleClass="ui-menubar"
autoSubmenuDisplay="true">
<p:submenu label="Ajax ">
<p:menuitem value="Home" action = "#{menuBar.setPage('menu1.xhtml')}" />
</p:submenu>
</p:panelMenu>
</f:ajax>
</h:form>
</h:panelGroup>
<h:panelGroup id="content" layout="block" >
<h:form id="contentform">
<ui:include src="#{menuBar.page}" />
</h:form>
</h:panelGroup>
You can use the update attribute of your <p:menuitem
p:menuitem got update and process attributes
In general don't mix JSF f:ajax with primefaces components and visa versa