TabView interfaces do not support selectOneMenu values

Hi, I have a tabView layout that looks like this:

<!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: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"> <h:head></h:head> <h:body> <p:messages /> <h:form id="form"> <p:tabView dynamic="true"> <p:tab title="Tab"> <p:inputText required="true" value="value"></p:inputText> </p:tab> <p:tab title="Select"> <p:selectOneMenu value="#{dummyController.selectedValue}" id="select" required="true" requiredMessage="Select is required"> <f:selectItem itemValue="1" itemLabel="asd"></f:selectItem> <f:selectItem itemValue="2" itemLabel="qwe"></f:selectItem> <f:selectItem itemValue="3" itemLabel="zc"></f:selectItem> </p:selectOneMenu> <p:message for="select" /> </p:tab> <p:tab title="Tab"> <p:inputText required="true" value="value"></p:inputText> </p:tab> </p:tabView> <h:commandButton action="#{dummyController.submit}" /> </h:form> </h:body> </ui:composition> 

and its controller

 import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; @ManagedBean @ViewScoped public class DummyController implements Serializable { private static final long serialVersionUID = 1L; private int selectedValue; public void submit() { } public int getSelectedValue() { return selectedValue; } public void setSelectedValue(int selectedValue) { this.selectedValue = selectedValue; } } 

it has weird behavior, follow tp playback instructions:

  • open the tab "Selection"
  • open another tab
  • click send twice

the first press nothing happens as regular, the next press brings up the required message for selection, although it always matters

Tell me if something is missing or there are any solutions.

+4
source share
3 answers

There is no direct solution, this is an error in the tabView elements, I came up with this workaround and worked

  <!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: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"> <h:head></h:head> <h:body> <p:messages /> <h:form id="form"> <p:tabView dynamic="true" activeIndex="#{dummyController.activeindex}" > <p:tab title="Tab" id="tab1"> <p:inputText required="true" value="value"></p:inputText> </p:tab> <p:tab title="Select" id="selectTab"> <p:selectOneMenu disabled="#{dummyController.activeindex != 1}" value="#{dummyController.selectedValue}" id="select" required="true" requiredMessage="Select is required"> <f:selectItem itemValue="" itemLabel=""></f:selectItem> <f:selectItem itemValue="1" itemLabel="asd"></f:selectItem> <f:selectItem itemValue="2" itemLabel="qwe"></f:selectItem> <f:selectItem itemValue="3" itemLabel="zc"></f:selectItem> </p:selectOneMenu> <p:message for="select" /> </p:tab> <p:tab title="Tab" id="tab3"> <p:inputText required="true" value="value"></p:inputText> </p:tab> </p:tabView> <h:commandButton action="#{dummyController.submit}" /> </h:form> </h:body> </ui:composition> 

and controller:

 package com.ibm.sa.kap.ui.controller; import java.io.Serializable; @ManagedBean @ViewScoped public class DummyController implements Serializable { private static final long serialVersionUID = 1L; private int selectedValue; private int activeindex; public void submit() { } public int getSelectedValue() { return selectedValue; } public void setSelectedValue(int selectedValue) { this.selectedValue = selectedValue; } public int getActiveindex() { return activeindex; } public void setActiveindex(int activeindex) { this.activeindex = activeindex; } } 

it is conditionally disabled according to the tab index to prevent the tab value being reset, how dirty !!

+1
source

Unfortunately, the implementation of p:tabView with dynamic="true" is wrong. There are various problems: http://code.google.com/p/primefaces/issues/list?can=2&q=tabView+dynamic&colspec=ID+Type+Status+Priority+TargetVersion+Reporter+Owner+Summary&y=5000&cells=tiles , but the most affected are components like p:selectOneMenu .

I had this problem in my own project - the values ​​from the selected lists were not sent if they were active on the other tab. Solution - does not use dynamic tabs unless they are fixed. There are too many errors inside.

Another thing that doesn't work is to refresh the tab view from the ajax onTabChange .

+1
source

Since <p:selectOneMenu requires a value to save the selected item.

0
source

Source: https://habr.com/ru/post/1489013/


All Articles