I have a rich:tabPanel where add tabs dinamically
<c:forEach var="tab" items="#{tabsBean.tabs}" >
<rich:tab name="#{tab.name}" >
<h:form id="#{tab.name}" >
<f:facet name="header">
<h:outputText value="#{tab.name}" />
<a4j:commandLink value="X" action="#{tabsBean.removeTab(tab)}" />
</f:facet>
<ui:include src="#{tab.path}" />
</h:form>
</rich:tab>
</c:forEach>
The troubles are
command link (X) is not show and when i close the tab i would open the #perv tab
How can i do?
f:facet name="header" must be a direct child of rich:tab (in your code it is a facet of h:form, but h:form does not support such facet, so it is not shown).
Note also if you are using RichFaces 4.x then you can not have form elements inside individual tabs, it is not supported yet, refer to:
https://issues.jboss.org/browse/RF-11306
Related
I'm working on a web application using JSF and PrimeFaces. One of the pages displays a table of entities, and I'm supposed to add a context menu to the table.
More specifically: The last column contains a p:menuButton whose content depends on the respective row. The menuItems are stored as a ui:compositionin another file, and I'm supposed to simply include them in the context menu.
The menuitems are dynamic, however. The entities do have a boolean member called enabled. For enabled entities, Edit, Delete, and Disable are displayed. For disabled entities, there's only Enable.
With the code below, the context menu is displayed, but they the content is only updated if I select another row via left click. Right-clicking does select rows, but the selectedPerson of the backingbean is not updated.
Apparently there were some changes in PrimeFaces 3.5. I found many references to the contextMenu ajax event.
But when I add it to the datatable like this:
<p:ajax event="contextMenu" update=":persons-form:contextMenu" />
.. the menu appears but disappears immediately. Presumably, because some update method is getting called. In the short timespan it's displayed, I can see it still showing the old menuitems.
So, to summarize: How can I make a contextmenu working as it should in a datatable with PrimeFaces 3.5? Meaning, right-clicking should select a row and also update the menu before displaying it, as the menuitems depend on the row data.
personList.xhtml:
<p:contextMenu id="contextMenu" for="persons">
<ui:include src="/layout/personActionMenu.xhtml">
<ui:param name="thePerson" value="#{personListBean.selectedPerson}"/>
</ui:include>
</p:contextMenu>
<p:dataTable id="persons"
value="#{personListBean.allPersons}"
var="p"
rowKey="#{p.id}"
selection="#{personListBean.selectedPerson}"
selectionMode="single"
rowStyleClass="#{p.enabled ? '' : 'disabledTableItem'}">
<p:ajax event="rowSelect" update=":persons-form:contextMenu"/>
<p:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{p.name}" />
</p:column>
<p:column>
<p:menuButton value="Actions">
<ui:include src="/layout/personActionMenu.xhtml">
<ui:param name="thePerson" value="#{p}"/>
</ui:include>
</p:menuButton>
</p:column>
</p:dataTable>
</h:form>
personActionMenu.xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:u="http://java.sun.com/jsf/composite/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<p:menuitem rendered="#{personListBean.isEnabled(thePerson)}" outcome="edit.xhtml" value="Edit" icon="ui-icon-gear">
<f:param name="id" value="#{thePerson.id}" />
</p:menuitem>
<p:menuitem actionListener="#{personListBean.deletePerson(thePerson)}" value="Delete" update=":person-form"
icon="ui-icon-close" rendered="#{personListBean.isEnabled(thePerson)}"/>
<p:menuitem actionListener="#{personListBean.toggleEnabled(thePerson)}" update=":persons-form" value="#{personListBean.toggleEnabledMenuItemLabel(thePerson)}" />
</ui:composition>
Please try this:
<p:contextMenu id="contextMenu" for="persons" widgetVar="ctxMenu" beforeShow="return true;">
<ui:include src="/layout/personActionMenu.xhtml">
<ui:param name="thePerson" value="#{personListBean.selectedPerson}"/>
</ui:include>
</p:contextMenu>
<p:dataTable ...>
...
<p:ajax event="contextMenu" update=":persons-form:contextMenu" oncomplete="ctxMenu.show(currentEvent);" />
...
</p:dataTable ...>
This is taken from CannyDuck´s post in the PF forum.
Hope this works for you as well.
I've been struggling with this for two days with no success and I think it's already time to ask for your help. But first of all, this is what I'm using:
JSF 2 Mojara 2.1.1
Primefaces 3.4.2
Netbeans 7.1.1
Tomcat 7.0.37
And now, the problem: I have a main page which is composed by several other pages using several <ui:include .. /> tags, like this:
<ui:composition template="/resources/templates/template1.xhtml">
<ui:define name="appData">
<p:panelGrid columns="1" id="contenidoAplicacion" styleClass="noborder">
<h:form id="fNewPerson">
<p:panel header="New employee" style="min-height:40em">
<ui:include src="./forms/personal.xhtml" />
<p:accordionPanel styleClass="noborder" activeIndex="3">
<p:tab id="tabSomeData" title="Identidad profesional" >
<ui:include src="./forms/formSomeData.xhtml" />
</p:tab>
....
....
</ui:define>
</ui:composition>
The personal.xhtm file looks like this:
<p:panelGrid>
<p:row>
<p:column >
<h:outputLabel value="Field1"/>
<p:inputText label="Field1" id="field1" value="#{dataBacking.selectedPerson.field1}" tabindex="1"
required="true" size="10" >
<f:convertNumber for="field1" integerOnly="true" groupingUsed="false"/>
</p:inputText>
<p:inputText id="field2" value="#{dataBacking.selectedPerson.field2}" tabindex="2" required="true" size="1" maxlength="1" >
<p:ajax event="keyup" listener="#{dataBacking.check}"
process="field1 field2" partialSubmit="true"
update="field1 field2 photo"/>
</p:inputText>
</p:column>
<p:column rowspan="5" >
<p:graphicImage id="photo" value="#{dataBacking.selectedPerson.photo}" width="90" />
</p:column>
</p:row>
...
</p:panelGrid>
The check() method in the dataBacking class is irrelevant because it only checks if the field1 and the field2 meet some rules and it works properly. The problem comes when the main page is loaded for the first time. In that case, the <p:ajax /> component in personal.xhtml doesn't work. I have to reload the page (simply by pressing the F5 key) and this time it works as it would be expected.
I've been changing some attributes of the component, but nothing seems to work. I really don't know what else to do. Any kind of help will be apreciated.
EDITED. After one more day, I think the problem has nothing to do with Primefaces ajax component, as the title of the question suggested. I've come to this conclusion through these two facts:
The behaviour with the <f:ajax .../> component remains the same.
I've figured out that the view relative to the first time I load the page is not persisted. I'll try to explain myself.
The DataBacking class has defined its scope as view so that the page can "see" all the attributes and methods during the time it's been shown to the user. However, I've noticed that the constructor is called twice: the first time the page is loaded (and then, none of the methods of the class are successfully invoked) and when I refresh the page. In this last case, the behaviour of both the page and the class is the expected one.
I hava a rich:tabPanel where i can add and remove tab dynamically
<rich:tabPanel id="tabsPanel" switchType="client" activeItem="#{tabsBean.activeTab}" itemChangeListener="#{tabsBean.tabChange()}" >
<c:forEach var="tab" items="#{tabsBean.tabs}" >
<rich:tab name="#{tab.name}" onheaderclick="switchTab('#{tab.name}');" >
<f:facet name="header">
<h:panelGrid columns="2">
<h:outputText value="#{tab.name}" />
<h:graphicImage value="#{pathImmagini.pathImmagineElimina}"
style="width:12px; height:12px;"
onclick="myFunc('#{tab.name}'); Event.stop(event);"/>
</h:panelGrid>
</f:facet>
<h:form id="#{tab.name}" >
<ui:include src="#{tab.pathComponent}" />
</h:form>
</rich:tab>
</c:forEach>
</rich:tabPanel>
where each tab has a its component *.xhtml (tab.pathComponent) , within of this components i have many a4j:commandlink that not works at first time.
this is one of my components (tab.pathComponent)
<rich:toolbar height="30" >
<a4j:commandLink action="#{tab.setNewObject('Nuovo Cliente')}" render="pannelloDatiCliente" execute="#this" >
<h:graphicImage value="#{pathImmagini.pathImmagineAggiungiSoggetto}"/>
</a4j:commandLink>
</rich:toolbar>
How i can do?
can you give bit more information regarding your xhtml. normally second click problem happens because of partial rendereing of page or UI. Can't tell the problem only with this part of code.
I'm developing my first JSF2 + Richfaces application and now I have this problem.
I have the following rich:tabPanel to which add and remove dynamically tab.
<h:form>
<rich:tabPanel id="tabsPanel" switchType="ajax" activeItem="#{tabsBean.activeTab}" >
<c:forEach var="tab" items="#{tabsBean.tabs}" styleClass="myRightPanel">
<rich:tab name="#{tab.name}" styleClass="myTab" >
<h:form id="#{tab.name}" >
<ui:include src="#{tab.pathDaIncludere}" />
</h:form>
</rich:tab>
</c:forEach>
</rich:tabPanel>
</h:form>
but to run I must add a <h:form> around each <rich:tab> otherwise the actions in the tabs will not work.
Is correct insert <h:form> in each tab?
I have pop-up with h:selectOneMenu. This pop-up will be displayed on a4j:commandLink click.
h:selectOneMenu has "value" attribute is not getting called on pop-up render (I debugged it using System.out.println()).
Because of this value is not being updated on pop-up display, I am seeing last operation value, even though I want to see empty list on new operation.
Any suggestions?
Note: Another observation is, if "add" some button in pop-up which refreshes the h:selectOneMenu, then it is working fine.
My code looks something like this:
<rich:popupPanel id="CModalPanel"
autosized="true"
resizeable="false"
moveable="true" domElementAttachment="parent">
<f:facet name="header">
<h:outputText value="Select list"/>
</f:facet>
<h:form id="cListID">
<a4j:outputPanel id="panelID">
<h:panelGroup>
<h:selectOneMenu id="cListMenu"
value="#{myBean.currvalue}" >
<f:selectItems value="#{myBean.plistItems}" />
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup>
<a4j:commandLink id="refreshButton"
actionListener="#{anotherBean.addMethod}"
render=":cListID" >
</a4j:commandLink>
</h:panelGroup>
</a4j:outputPanel>
</h:form>
</rich:popupPanel>
You need to update the content of <rich:popupPanel> before opening it.
<a4j:commandLink ... render=":cListID" oncomplete="#{rich:component('CModalPanel')}.show()" />
here's a related bug https://community.jboss.org/thread/169542