redraw on TabChangeEvent causes messages vanish

UI Components for JSF
Post Reply
arnieAustin
Posts: 120
Joined: 14 Feb 2015, 22:35
Location: Houston, TX

19 May 2019, 18:58

I have a tabView with 5 tabs. The fields on the first two make up an entity that must be stored en masse. The other tabs show child entities in their multitudes and are not enabled until the parent entity is saved.

There is a save button on the first two tab pages, as performing a save on either tab means saving the one, in fact, they both call the same actionListener method.

If there is field validation errors, they are shown on the current tab page as expected. Not entering any data on either tab or 1 or 2 should (and does) generate errors for both tabs. I know this because once errors appear on the active tab and I then click the other, the initial appearance of the tab shows the expected errors - for a second. Then the tab appears to be being repainted without any errors.

What is causing this and more to the point, how do I prevent it?

As example, here is a portion of the file with the tab view. The tab pages themselves are include files, each with its own h:form.

Code: Select all

				<p:tabView id="infoRequestEditTabPanel" dynamic="false"
					cache="false"
					activeIndex="#{infoRequestEdit.selectedTab}" width="100%"
					switchType="ajax">

					<p:ajax event="tabChange"
						listener="#{infoRequestEdit.onTabChange}"
						update="infoRequestEditOutputPanel" />

					<p:tab id="tabPageGeneral" name="tabPageGeneral"
						title="#{messages.getString('infoRequestEdit.label.tab.general.title')}"
						action="#{infoRequestEdit.switchTabToGeneral}"
						disabled="#{infoRequestEdit.tabGeneralLocked}"
						update="infoRequestEditTabMethodsPanel">
						<ui:include
							src="/protected/info/request/infoRequestEditTabGeneral.xhtml" />
					</p:tab>
Here is the event code:

Code: Select all

	public void onTabChange(TabChangeEvent event){
		Tab activeTab = event.getTab();
		if ( TAB_GENERAL.equals(activeTab.getId()) ) {
			switchTabToGeneral();
			return;
		}
		if ( TAB_AGENCY.equals(activeTab.getId()) ) {
			switchTabToAgency();
			return;
		}
--- --- ---
PF 12 | JSF 4 | CDI 4 | WildFly 27

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

20 May 2019, 13:19

1. Press F12 and watch the network traffic to explain why the messages are disappearing.

2. Do you have autoupdate on your p:messages?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

arnieAustin
Posts: 120
Joined: 14 Feb 2015, 22:35
Location: Houston, TX

24 May 2019, 16:35

Turns out it was the update value; was referencing the widgeVar instead of the id. So now the tab header does not disappear, but the messages still do.
--- --- ---
PF 12 | JSF 4 | CDI 4 | WildFly 27

arnieAustin
Posts: 120
Joined: 14 Feb 2015, 22:35
Location: Houston, TX

24 May 2019, 22:17

I currently have:

Code: Select all

<p:tabView id="infoRequestEditTabPanelId" widgetVar="infoRequestEditTabPanel" 
	cache="true" dynamic="true" style="width:100%;" 
	tabindex="#{infoRequestEdit.selectedTab}" >

	<p:ajax event="tabChange"
		listener="#{infoRequestEdit.onTabChange}"
		process="@this" update="infoRequestEditTabPanelId" />

	<p:tab id="tabPageGeneral" name="tabPageGeneral"
		title="#{messages.getString('infoRequestEdit.label.tab.general.title')}"
		action="#{infoRequestEdit.switchTabToGeneral}"
		disabled="#{infoRequestEdit.tabGeneralLocked}"
		update="infoRequestEditTabMethodsPanel">
		<ui:include
			src="/protected/info/request/infoRequestEditTabGeneral.xhtml" />
	</p:tab>

	<p:tab id="tabPageAgency" name="tabPageAgency"
		title="#{messages.getString('infoRequestEdit.label.tab.agency.title')}"
		action="#{infoRequestEdit.switchTabToAgency}"
		update="infoRequestEditTabMethodsPanel">
		<ui:include
			src="/protected/info/request/infoRequestEditTabAgency.xhtml" />
	</p:tab>
	...
And when I change tabs from general to tab and back, the validation messages disappear when the AJAX call to #{infoRequestEdit.onTabChange} returns and the update="infoRequestEditTabPanelId" is performed.

Is there no way to keep the JSF validation messages in the DOM between updates?
--- --- ---
PF 12 | JSF 4 | CDI 4 | WildFly 27

arnieAustin
Posts: 120
Joined: 14 Feb 2015, 22:35
Location: Houston, TX

24 May 2019, 22:51

DOH! :oops: I just read and remembered that the JSF messages are request scoped. So I stored them in a local member variable and in the onTabChange event, if the collection isn't empty I add them again.

Works perfectly.
--- --- ---
PF 12 | JSF 4 | CDI 4 | WildFly 27

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

25 May 2019, 13:27

Glad you got it resolved!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests