I've have a primefaces web application, which consists of several tabs in which the user can enter and edit some data. If a user edits data and want to save this, he presses a save button and the data will be persisted to an database. If he want's to revert his entries he simply press the reset button.
Each tab is a own included .xhtml page.
Now we want to check, if the user navigates away with the menu or press the reset button, if there were made some changes and ask him if he really want to browse away without saving.
Do you have any suggestions?
Here the page of the tabs:
<p:tabView id="tabView"
activeIndex="#{management.activeTabIndex}"
rendered="#{management.dataFetched}"
styleClass="tab-view">
<p:ajax event="tabChange" update=":tabForm" />
<p:tab id="firstTab" title="First">
<p:panel id="firstPanel" styleClass="info-panel">
<ui:include src="/home/test/infoHost.xhtml" />
</p:panel>
</p:tab>
<p:tab id="secondTab" title="Second">
<p:panel id="secondPanel" styleClass="info-panel">
<ui:include src="/home/test/infoDb.xhtml" />
</p:panel>
</p:tab>
<p:tab id="thirdTab" title="Third">
<p:panel id="thirdPanel" styleClass="info-panel">
<ui:include src="/home/test/infoSt.xhtml" />
</p:panel>
</p:tab>
</p:panel>
</p:tab>
</p:tabView>
</h:form>
Many thanks in advance!
I would write jQuery function when tab is clicked and bind it to tabs. In this function I would get the content of data, create <p:remoteCommand> which invoke backing bean function. As a parameter I would pass data from jQuery function and in backing bean compare it with the value of field storing data. If these things differ call a dialog from backing bean "Are you sure...".
http://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml
http://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml
Related
I am new to JSF, checking related questions did not give me right answer.
I have 2 xhtml files. I specially delete all of items, like style, rendered, beans, etc. All the values displays good, but i cant make it update after pressing button.
1st of them named for example Description is a form with 3 tabs, each of them is a dataTable. Structure is a
<p:tabView id="tabs">
<p:tab id="first">
<h:form id="one">
<p:dataTable id="firstTable/>
</h:form>
</p:tab>
<p:tab id="second">
<h:form id="two">
<p:dataTable id="secondTable/>
</h:form>
</p:tab>
<p:tab id="third">
<h:form id="three">
<p:dataTable id="thirdTable/>
</h:form>
</p:tab>
2nd is a dialog, opened by some button in other component, here i can edit some inputs, and with commandButton "Save"
<h:form id="dialog">
<p:dataTable id="one">
<p:column headerText="FirstColumn">
<p:inputText onfocus="this.select()" id="newInput"
value="#{data['rmp']}"/>
</p:column>
</p:dataTable>
<p:commandButton id="save"
actionListener="#{dialogView.submit}"/>
</h:form>
After pressing "save" button i want my 2nd tab in first xhtml to update and display new value. It is only updates after i refresh the page manually.
I tried to add update="#([id$=':tabs:second'])" but it doesn't work right.
Please help me
I have a requirement, where I have to create tabs. First two tabs are static tabs, next tabs are dynamic based on the records in database table.
When I try to create, only first tabs are coming, remaining tabs are not coming.
Here is my work
<p:tabView id="view1" value="#{bean.values}" var="tab" dynamic="true">
<p:tab id="view11" title="${msgs.ckd_title}">
// first tab content
</p:tab>
<p:tab id="view12" title="${msgs.pc_qsys_title_material}">
// second tab content
</p:tab>
<p:tabView id="view13" value="#{bean.values}" var="tab">
<p:tab id="view3" title="#{tab.label}">
//dynamic tab content
</p:tab>
</p:tabView>
</p:tabView>
I tried with ui:repeat, still no luck
<p:tabView id="supersetTabs"value="#{pcSuperSetReportBean.plantSuperSets}" var="tab">
<p:tab id="provisioninReportBySupplier" title="#{tab.label}">
//dynamic tab content
</p:tab>
</p:tabView>
"Dynamic" implies that bean logic is going to generate variable tab content. So your bean will have to populate the model referred to by value and
something (either an update parameter on a page component, or bean code) will have to tell the page to refresh the tabview supersetTabs.
I have next code:
<p:layoutUnit position="center" size="50%" styleClass="nestedUnit">
<p:tabView id="tableTabView>
<p:tab title="Inbox">
<h:form id="tableForm">
<p:dataTable id="tableMsg">
//data
</p:dataTable>
</h:form>
</p:tab>
</p:tabView>
</p:layoutUnit>
</p:layout>
Also I have some button, which removing element from table and update It. But how I can update this table? Which arguments should be in update? I'm tried update=":tableForm" and update=":tableTabView:tableForm" and update=":tableTabView" but not results. Where I was wrong?
Open firebug or developer tools in your web browser. See what value is the component aquiring at client side and put that id in your update attribute.
I'm using Primefaces 3.4 (also tried 3.3) and Mojarra 2.1.7. But I have a problem updating my dynamical tabs within a p:tabView.
I have 2 buttons which should add an additional tab. The first button is outside the p:tabView. When clicking this button, the backing bean is called, the p:tabView is updated, and the new tab is shown. But when I click the second button, which is inside a tab of that tabView, the backing bean is called, but the tabView is NOT updated.
This lack of updating occures only in dynamic tabs. When I modify the given example to have only one tab, and displaying a value which changes when clicking the buttons, the tabView is updated by both buttons, and the new Value is shown. So it is an problem only occuring in dynamic tabs.
Here is my code.
<f:view contentType="text/html">
<h:form>
<p:commandButton value="press me" action="#{idTestBean.addTab}" update=":ApplicationTab"/>
</h:form>
<p:tabView id="ApplicationTab" cache="false" dynamic="false" var="tab" value="#{idTestBean.tabList}">
<p:tab title="tab" closable="false" >
<p:panel>
<h:form>
<p:commandButton value="press me" action="#{idTestBean.addTab}" update=":ApplicationTab"/>
</h:form>
#{idTestBean.count}
</p:panel>
</p:tab>
</p:tabView>
</f:view>
The different tabs contains separate forms that needed to be submitted separate. therefore I had the approach of more than one form.
Well this must do the trick:
<f:view contentType="text/html">
<h:form>
<p:commandButton value="press me" action="#{idTestBean.addTab}" update="#form"/>
<p:tabView id="ApplicationTab" cache="false" dynamic="false" var="tab" value="#{idTestBean.tabList}">
<p:tab title="tab" closable="false" >
<p:panel>
<p:commandButton value="press me" action="#{idTestBean.addTab}" update="#form"/>
#{idTestBean.count}
</p:panel>
</p:tab>
</p:tabView>
</h:form>
</f:view>
Today i did the same problem too, I had a dynamic tabview, and inside tabs, there're some panels that needed to be updated when tab changes, so what i did was, i added the p:ajax on event TabChange, and in the update attribute, i added the form id and tabviewId like this:
:formID:tabViewID
and it worked at last.
Just so you know.
I need to fetch corresponding data into bean whenever some certain tab is selected from the tabview. For this I have been trying to use f:event with preRenderComponent but that doesnt help with desired.
How can I execute listener corresponding to the tab whenever a certain tab is selected in tabview.
<p:tabView dynamic="true" cache="false">
<p:tab title="People I'm following" >
<f:event type="preRenderComponent" listener="#{listRetriever.retrieveFollowies()}"/>
<ui:repeat value="#{listRetriever.list}" var="person">
#{person}<br/>
</ui:repeat>
</p:tab>
<p:tab title="People following me" >
<f:event type="preRenderComponent" listener="#{listRetriever.retrieveFollowers()}"/>
<ui:repeat value="#{listRetriever.list}" var="person">
#{person}<br/>
</ui:repeat>
</p:tab>
</p:tabView>
TabChangeEvent passes you the selected tab instance, live sample;
http://www.primefaces.org/showcase-labs/ui/tabviewChangeListener.jsf