I'm creating a web page. The content should change according to user selection.
I require 2 radio buttons which give the option to select one day and many days (start date and end date) if one day selected page should display one calender to select date else two calenders to select start date and end date I tried to use rendered propety with ajax but I can't view calenders how could i do this
my xhtml
<h:form id="f1">
<p:growl id="createmsg"/>
<h:panelGrid columns="2" cellpadding="10">
<p:panel id="add_visitor_details_pnl" style="width:100%">
<h:panelGrid id="grid" columns="2" cellpadding="10">
<h:outputText value="Organization :" />
<p:selectOneMenu editable="true" value="#{visitorBean.organization}" style="width:160px" filter="true" filterMatchMode="startsWith">
<f:selectItems value="#{visitorBean.organizations}" />
</p:selectOneMenu>
<h:outputText value="Visitor Name :" />
<p:selectOneMenu value="#{visitorBean.name}" style="width:160px" filter="true" filterMatchMode="startsWith">
<f:selectItems value="#{visitorBean.names}" />
</p:selectOneMenu>
<h:outputText value="Visitor ID :" />
<p:selectOneMenu value="#{visitorBean.id}" style="width:160px" filter="true" filterMatchMode="startsWith">
<f:selectItems value="#{visitorBean.ids}" />
</p:selectOneMenu>
<h:outputText value="Purpose :" />
<p:inputTextarea id="purpose_it" value="#{visitorBean.purpose}" required="true" autoResize="false"
requiredMessage="Enter Purpose" rows="10" cols="50"/>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="10">
<p:selectOneRadio id="customRadio" value="#{visitorBean.option}" >
<f:selectItem itemLabel="Create a one day appointment" itemValue="1" />
<f:selectItem itemLabel="create a day period appointment" itemValue="2" />
<p:ajax event="change" listener="#{visitorBean.selectDayType()}"
update=":f1:add_visitor_details_pnl" />
</p:selectOneRadio>
</h:panelGrid>
<h:panelGrid id="date" columns="3" cellpadding="10">
<h:outputText id="date1" value="Date" rendered="#{visitorBean.cal1}"/>
<p:calendar id="calender_Cal1" value="#{visitorBean.date_time}"
pattern="yyyy-MM-dd" rendered="#{visitorBean.cal1}"
required="true" requiredMessage="Enter Date Time"/>
<p:calendar id="calender_Cal2" value="#{visitorBean.date_time}"
pattern="yyyy-MM-dd" rendered="#{visitorBean.cal2}"
required="true" requiredMessage="Enter Date Time"/>
</h:panelGrid>
<h:panelGrid columns="2" cellpadding="10">
<p:commandButton id="submit_visitor_Btn" value="Create"
action="#{visitorBean.submitVisitorData()}"
update=":f1:visitor_dataTable,:f1:grid,:f1:createmsg"/>
</h:panelGrid>
my ajax mthod
public void selectDayType(){
if(option =="1")
cal1 = "true";
else if(option =="2"){
cal1="true";
cal2="true";
}
Try surrounding the calendars with a:
<p:outputPanel id="someId" >
...
</p:outputPanel>
Primefaces - Output Panel
Related
I have problem with "" component in my application. I have a datatable with 2 fields editable first is an inputtext and second field is a dateInput.
Inside fields I put to update value in list but when submit it to bean not updated the values.
Below is my page.xhtml and bean.
<p:dialog id="modalNovosParametrosRecesso" header="Salvar Novos Parâmetros de Estagiário"
widgetVar="widgetvarNovoParametro"
draggable="true" resizable="false"
closable="false" modal="true" width="630">
<h:outputText styleClass="modalRecessoAuto" value="#{msg.MN064}" escape="false" />
<br />
<h:panelGroup>
<br />
<p:dataTable id="tableRegRecessoAuto" var="recessoAuto"
value="#{parametroEstagiarioMB.visao.listaOcorrenciaRegistroRecesso}"
styleClass="hide-column-names" rowIndexVar="rowIndex" >
<p:column style="width:98px;">
<h:outputLabel value="#{rowIndex+1}º Recesso de " style="color: #0039BA" />
<p:inputText value="#{recessoAuto.diasRecesso}" size="2">
<p:ajax event="blur" update=":frmFiltro:tableRegRecessoAuto" ignoreAutoUpdate="true" global="false" />
</p:inputText>
<h:outputLabel value="dia(s) começando em " style="color: #0039BA" />
<p:inputMask value="#{recessoAuto.dtInicioOcorrencia}" mask="99/99/9999" size="10">
<f:convertDateTime pattern="dd/MM/yyyy" locale="pt_BR" />
<p:ajax event="blur" update=":frmFiltro:tableRegRecessoAuto" ignoreAutoUpdate="true" global="false"/>
</p:inputMask>
<h:outputLabel value=" e finalizando em " style="color: #0039BA; margin-left: 5px;"/>
<h:outputLabel id="dtLbl1" value="#{recessoAuto.dtFimOcorrencia}" style="color: #0039BA; margin-left: 5px;" >
<f:convertDateTime for="dtLbl1" pattern="dd/MM/yyyy" locale="pt_BR"/>
</h:outputLabel>
</p:column>
-->
<div style="padding-left: 170px;">
<p:commandLink styleClass="btnLaranja marginTop"
ignoreAutoUpdate="true" global="false" ajax="false" action="#{parametroEstagiarioMB.salvarRecessoPrimeiraParametrizacao()}"
update=":frmFiltro:tableRegRecessoAuto">
<span>Confirmar</span>
</p:commandLink>
<p:commandLink styleClass="btnLaranja marginTop"
id="btnCancelarRecessoAuto"
oncomplete="PF('widgetvarNovoParametro').hide();"
ignoreAutoUpdate="true" global="false" actionListener="#{parametroEstagiarioMB.cancelar}">
<f:setPropertyActionListener
target="#{parametroEstagiarioMB.visao.exibirModal}"
value="#{false}" />
<span>Cancelar</span>
</p:commandLink>
<p:commandLink styleClass="btnLaranja marginTop"
id="btnVerRegrasAuto"
oncomplete="PF('widgetvarModalRegras').show();"
ignoreAutoUpdate="true" global="false">
<span>Regras</span>
</p:commandLink>
</div>
</p:dialog>
My Bean:
public void salvarRecessoPrimeiraParametrizacao(){
int count = 0;
final DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot()
.findComponent(":frmFiltro:tableRegRecessoAuto");
List<OcorrenciaPonto> teste = new ArrayList<OcorrenciaPonto>();
for(OcorrenciaPonto c : (List<OcorrenciaPonto>) dataTable.getValue()){
teste.add(c);
count+=1;
}}
datatable.getValues() not get new values and yes old values that displayed in screen.
Are you using getters and setters correctly?
Have you tried to use immediate="true" on input fields?
I saw you are using <p:ajax> . I had some troubles with this. Maybe, if you change to **<f:ajax>** this must works so well.
I have a selectOneMenu that loads anothers in demand. See:
<h:outputLabel value="Tabela: *" />
<p:selectOneMenu id="selectOneMenuTabela"
converter="entityConverter"
value="#{orcamentoMB.tabelaSelecionada}" effect="fade"
required="true" requiredMessage="A Tabela é obrigatória">
<f:selectItem itemLabel="Selecione uma Tabela" itemValue="" />
<f:selectItems value="#{orcamentoMB.tabelas}" var="tabela"
itemLabel="#{tabela.nome}" itemValue="#{tabela}" />
<p:ajax event="change" update="selectOneMenuProcedimento" />
</p:selectOneMenu>
<h:outputText value="Procedimento: *" />
<p:selectOneMenu id="selectOneMenuProcedimento"
disabled="#{orcamentoMB.tabelaSelecionada == null}"
converter="entityConverter" filter="true"
filterMatchMode="contains"
value="#{orcamentoMB.itemTabelaProcedimentoSelecionado}"
effect="fade" required="true"
requiredMessage="O procedimento é obrigatório">
<f:selectItem itemLabel="Selecione um Procedimento" itemValue="" />
<f:selectItems value="#{orcamentoMB.tabelaSelecionada.itens}"
var="item" itemLabel="#{item.procedimento.nome}"
itemValue="#{item}" />
<p:ajax event="change"
update="localAplicacao, selectOneMenuDente,selectOneMenuFace" />
</p:selectOneMenu>
<h:outputText value="Local Aplicação: *" />
<h:outputText id="localAplicacao"
value="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.localAplicacao.descricao}" />
<h:outputText value="Dente: *" />
<p:selectOneMenu id="selectOneMenuDente" converter="entityConverter"
filter="true" filterMatchMode="contains"
disabled="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento == null || orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.dentesAsList.size() == 0}"
value="#{orcamentoMB.denteSelecionado}" effect="fade">
<f:selectItem itemLabel="Selecione um Dente" itemValue="" />
<f:selectItems
value="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.dentesAsList}"
var="dente" itemLabel="#{dente.descricao}" itemValue="#{dente}" />
</p:selectOneMenu>
<h:outputText value="Face: *" />
<p:selectOneMenu id="selectOneMenuFace" converter="entityConverter"
disabled="#{orcamentoMB.itemTabelaProcedimentoSelecionado.procedimento.facesAplicacaoAsList.size() == 0 || orcamentoMB.itemTabelaProcedimentoSelecionado == null}"
value="#{orcamentoMB.faceSelecionada}" effect="fade">
<f:selectItem itemLabel="Selecione uma Face" itemValue="" />
<f:selectItems
value="#{orcamentoMB.itemOrcamento.itemTabelaProcedimento.procedimento.facesAplicacaoAsList}"
var="face" itemLabel="#{face.descricao}" itemValue="#{face}" />
</p:selectOneMenu>
The "selectOneMenuTabela" and "selectOneMenuProcedimento" works fine, the value are setted in ManagedBean, but the others not.
When i try to execute this commandButton bellow:
<p:commandButton value="Incluir" icon="ui-icon-plus" process="#this"
disabled="#{orcamentoMB.bean.situacao.codigo != 'AGUARDANDO_ACEITACAO'}"
update=":formManterOrcamento:tabViewManterOrcamento:tabProcedimentos,:formManterOrcamento:panelTotais"
actionListener="#{orcamentoMB.addItemOrcamento}" />
THe value inside "denteSelecionado" is null, and the values inside "selectOneMenuFace" aren't loaded.
Since you are having p:ajax event="change"on first two selectOneMenu they are being submitted that is why you are getting those value. To process them on click of commandButton add those component ids to process attribute along with #this like process like process="#this,selectOneMenuFace,selectOneMenuDente,.."
If the component is disabled or readOnly then they won't be processed.
Hope this helps
When "selectOneMenu" is placed in the "dataTable" column header it:
1) triggers row sorting everytime it is opened or after the button next to it is clicked and "selectOneMenu" is opened (it shouldn't be like that);
2) fails to assign value to the backing bean.
How can "selectOneMenu" be attached to the column header so that these problems wouldn't occur?
*.xhtml code with dataTable which causes 1) and 2) problems:
<h:form id="someForm0">
<p:dataTable id="sdt" var="variable" value="#{otherBean.tableModel}" rows="10">
<p:column sortBy="#{variable.name}" filterBy="#{variable.name}" filterMatchMode="contains" >
<f:facet name="header">
<h:outputText value="Name"/>
<h:panelGrid columns="2" cellpadding="1">
<p:selectOneMenu id="abc" value="#{userBean.someChars}">
<f:selectItem itemLabel="" itemValue="select" />
<f:selectItem itemLabel="AAA" itemValue="AAA" />
<f:selectItem itemLabel="BBB" itemValue="BBB" />
<f:selectItem itemLabel="CCC" itemValue="CCC" />
</p:selectOneMenu>
<h:commandButton id="btn" value="Submit" type="submit" action="#{userBean.submitChars}"/>
</h:panelGrid>
</f:facet>
<h:outputText value="#{variable.name}"/>
</p:column>
</p:dataTable>
</h:form>
Backing bean code:
#ManagedBean
public class UserBean
{
private String someChars;
public String getSomeChars()
{
return someChars;
}
public void setSomeChars(String someChars)
{
this.someChars = someChars;
}
public String submitChars()
{
if(getSomeChars() != null)
{
System.out.println("Selected chars are: " + getSomeChars());
}
else
{
System.out.println("Selected chars are equal to null!");
}
return null;
}
}
Here is fragment of the previously mentioned *.xhtml code, and selectOneMenu works just great when placed into the basic form:
<h:form id="someForm">
<p:selectOneMenu id="abc" value="#{userBean.someChars}">
<f:selectItem itemLabel="" itemValue="select" />
<f:selectItem itemLabel="AAA" itemValue="AAA" />
<f:selectItem itemLabel="BBB" itemValue="BBB" />
<f:selectItem itemLabel="CCC" itemValue="CCC" />
</p:selectOneMenu>
<h:commandButton id="btn" value="Submit" type="submit" action="#{userBean.submitChars}"/>
</h:form>
I think the last resort would be adding elements from the dataTable column header to the dataTable header:
<h:form id="someForm1">
<p:dataTable id="sdt" var="variable" value="#{otherBean.tableModel}" rows="10">
<f:facet name="header">
<h:panelGrid columns="2" cellpadding="1">
<p:selectOneMenu id="abc" value="#{userBean.someChars}">
<f:selectItem itemLabel="" itemValue="select" />
<f:selectItem itemLabel="AAA" itemValue="AAA" />
<f:selectItem itemLabel="BBB" itemValue="BBB" />
<f:selectItem itemLabel="CCC" itemValue="CCC" />
</p:selectOneMenu>
<h:commandButton id="btn" value="Submit" type="submit" action="#{userBean.submitChars}"/>
</h:panelGrid>
</f:facet>
<p:column sortBy="#{variable.name}" filterBy="#{variable.name}" filterMatchMode="contains" >
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{variable.name}"/>
</p:column>
</p:dataTable>
</h:form>
Try as below :
<h:form id="someForm0">
<p:dataTable id="sdt" ...>
<p:column headerText="header">
<p:selectOneMenu id="abc" value="#{userBean.someChars}">
<f:selectItem itemLabel="" itemValue="select" />
<f:selectItem itemLabel="AAA" itemValue="AAA" />
<f:selectItem itemLabel="BBB" itemValue="BBB" />
<f:selectItem itemLabel="CCC" itemValue="CCC" />
<p:ajax event="valueChange" update=":someForm0:sdt"/>
</p:selectOneMenu>
</p:column>
</p:dataTable>
<h:commandButton ....>
</h:form>
UserBean.java
private String someChars;
public String getSomeChars() {
return someChars;
}
public void setSomeChars(Stirng someChars) {
this.someChars = someChars;
}
I'm using Mojarra, PF 3.5 SNAPSHOT, Tomcat 7.0.32 and trying to make a datatable update itself when changes have been done by other clients. I'm also using CDF beans along with MyCODI, #ViewAccessScoped.
When I was using 3.4, in-row editing (instead of in-cell editing) and standard #ConversationScoped it was working.
This is the xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:t="http://myfaces.apache.org/tomahawk">
<ui:composition template="commonLayout.xhtml">
<ui:define name="content">
<p:growl id="growlmessage" showDetail="false" autoUpdate="true"/>
<p:contextMenu for="staffTable">
<p:menuitem value="Open" update="staffTable" icon="ui-icon-close" actionListener="#{staffbean.onOpen}" />
<p:menuitem value="Delete" update="staffTable" icon="ui-icon-close" onclick="confirmation.show()" />
</p:contextMenu>
<p:confirmDialog id="confirmDialog" message="#{text['viewedit.delete.confirm']}"
header="#{text['viewedit.delete.header']}" severity="alert" widgetVar="confirmation" appendToBody="true" closable="false" visible="false" >
<p:commandButton action="#{staffbean.onDelete}" ajax="true" value="Yes" oncomplete="confirmation.hide()" icon="ui-icon-check" />
<p:commandButton value="No" onclick="confirmation.hide()" type="button" icon="ui-icon-closethick" />
</p:confirmDialog>
<p:dataTable id="staffTable" var="staff" widgetVar="staffList" value="#{staffbean.objectList}" paginator="true" rows="15" paginatorPosition="bottom" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" currentPageReportTemplate="#{text['table.staff.filter.count']}" rowsPerPageTemplate="15,25,50,100" emptyMessage="#{text['table.staff.filter.notfound']}" filteredValue="#{staffbean.filteredObject}" editable="true" editMode="cell" draggableColumns="true" rowKey="#{staff.id}" selection="#{staffbean.selectedObject}" selectionMode="single">
<f:facet name="header">
<p:columnGroup type="header">
<p:row>
<p:column colspan="4">
<h:outputText value="#{text['table.staff.header']}" />
</p:column>
</p:row>
<p:separator/>
<p:row>
<p:panelGrid columns="5" styleClass="headerGrid">
<p:column colspan="2">
<h:outputText value="#{text['table.filter.global']}" />
<p:inputText id="globalFilter" onkeyup="staffList.filter()" style="width:150px" />
</p:column>
<p:column colspan="2">
<p:selectOneMenu id="pageonly" value="#{staffbean.pageOnly}" >
<f:selectItem itemLabel="#{text['dataexporter.pageonly']}" itemValue="true" />
<f:selectItem itemLabel="#{text['dataexporter.entirepage']}" itemValue="false" />
<p:ajax event="change" listener="#{staffbean.exportXLS}" update="#form" immediate="true" />
</p:selectOneMenu>
<h:commandLink>
<p:graphicImage id="exportPage" value="/resources/img/excel.png" />
<p:dataExporter type="xls" target="staffTable" fileName="staff" pageOnly="#{staffbean.pageOnly}"/>
<p:tooltip for="exportPage" value="#{text['dataexporter.tooltip']}" showEffect="fade" hideEffect="fade" />
</h:commandLink>
</p:column>
</p:panelGrid>
</p:row>
</p:columnGroup>
</f:facet>
<p:column id="nameColumn" headerText="#{text['label.name']}" sortBy="#{staff.name}" filterBy="#{staff.name}" filterMatchMode="contains">
<p:cellEditor>
<f:facet id="nameoutput" name="output">
<h:outputText value="#{staff.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{staff.name}" style="width:100%" required="true" requiredMessage="#{text['validation.error.required.name']}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column id="staffnoColumn" headerText="#{text['label.staffno']}" sortBy="#{staff.staffno}" filterBy="#{staff.staffno}" filterMatchMode="contains">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{staff.staffno}" />
</f:facet>
<f:facet id="staffliststaffno" name="input">
<p:inputText value="#{staff.staffno}" style="width:100%" required="true" requiredMessage="#{text['validation.error.required.staffno']}">
<pe:keyFilter regEx="/^\d+$/" preventPaste="false"/>
<f:validator validatorId="staffnoValidator" />
<f:validator validatorId="numericValidator" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<f:facet name="footer" id="footer">
There are #{fn:length(staffbean.objectList)} staff in total.
</f:facet>
<p:ajax event="cellEdit" listener="#{staffbean.onEdit}" update="#form" />
</p:dataTable>
</ui:define>
<ui:define name="socket">
<p:socket channel="/ba" >
<p:ajax event="message" update="ba_staffTable" />
</p:socket>
</ui:define>
</ui:composition>
Bean:
public void update(Object object) {
if (!getEm().getTransaction().isActive()) {
getEm().getTransaction().begin();
}
try {
get().merge(object);
get().getTransaction().commit();
} catch (PersistenceException e) {
if (ExceptionUtil.is(e, ConstraintViolationException.class) || ExceptionUtil.is(e, RollbackException.class)) {
e.printStackTrace();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, ResourceLoader.MESSAGES.getProperty("staff.error.dbconstraint"), null));
if (getEm().getTransaction().isActive()) {
getEm().getTransaction().rollback();
}
}
}
PushContextFactory.getDefault().getPushContext().push("/ba", "");
}
Your table id is staffTable not ba_staffTable
Im trying to have the option set to a specific value from the backend after an AJAX-call, however although all other field-types are successfully set the selectOneMenu is not. Im using Primefaces/JSF.
xhtml:
<p:inputText id="cpr" value="#{customerbean.customer.cpr}">
<p:ajax event="change" listener="#{customerbean.fetchCustomerDatafromCBS}" update="#form" immediate="true" >
<f:param name="cprNumber" value="#{customerbean.customer.cpr}"/>
</p:ajax>
<f:validator validatorId="cprValidator" />
</p:inputText>
<p:selectOneMenu id="gender" value="#{customerbean.customer.gender}" required="#{!customerbean.disabled}" requiredMessage="#{text['validation.error.required.gender']}" disabled="#{customerbean.disabled}">
<f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" />
<f:selectItem itemLabel="Male" itemValue="Male" />
<f:selectItem itemLabel="Female" itemValue="Female" />
</p:selectOneMenu>
bean:
getCustomer().setGender(fetchedCustomer.getGender().trim());
NOTE
I just discovered that the value IS set (because the database row is inserted with the correct value) - but the selectOneMenu UI object on the browser does not reflect that.
ENTIRE VIEW:
<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:t="http://myfaces.apache.org/tomahawk">
<ui:composition template="commonLayout.xhtml">
<ui:define name="content">
<p:panelGrid columns="2" styleClass="companyHeaderGrid" >
<f:facet name="header">
Create customer
</f:facet>
<h:outputLabel for="cpr" value="CPR" />
<h:outputLabel for="passportno" value="Passport No." />
<p:inputText id="cpr" value="#{customerbean.customer.cpr}">
<p:ajax event="change" listener="#{customerbean.fetchCustomerDatafromCBS}" update="#form" immediate="true" >
<f:param name="cprNumber" value="#{customerbean.customer.cpr}"/>
</p:ajax>
<f:validator validatorId="cprValidator" />
</p:inputText>
<p:inputText id="passportno" value="#{customerbean.customer.passportno}" readonly="#{customerbean.disabled}">
<f:validator validatorId="passportnoValidator" />
</p:inputText>
<h:outputLabel for="name" value="Name"/>
<h:outputLabel for="nationality" value="Nationality" />
<p:inputText id="name" value="#{customerbean.customer.name}" required="true" requiredMessage="#{text['validation.error.required.name']}" readonly="#{customerbean.disabled}"/>
<p:inputText id="nationality" value="#{customerbean.customer.nationality}" required="true" requiredMessage="#{text['validation.error.required.nationality']}" readonly="#{customerbean.disabled}" />
<h:outputLabel for="dob" value="Date of Birth" />
<h:outputLabel for="address" value="Address" />
<p:calendar id="dob" value="#{customerbean.customer.dob}" pattern="ddmmyyyy" readonly="#{customerbean.disabled}" />
<p:inputText id="address" value="#{customerbean.customer.address}" readonly="#{customerbean.disabled}" />
<h:outputLabel for="mailingaddress" value="Mailing Address" />
<h:outputLabel for="gender" value="Gender" />
<p:inputText id="mailingaddress" value="#{customerbean.customer.mailingAddress}" readonly="#{customerbean.disabled}" />
<p:selectOneMenu id="gender" value="#{customerbean.customer.gender}" required="#{!customerbean.disabled}" requiredMessage="#{text['validation.error.required.gender']}" disabled="#{customerbean.disabled}">
<f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" />
<f:selectItem itemLabel="Male" itemValue="Male" />
<f:selectItem itemLabel="Female" itemValue="Female" />
</p:selectOneMenu>
<h:outputLabel for="mobileno" value="Mobile No." />
<h:outputLabel for="faxno" value="Fax No." />
<p:inputText id="mobileno" value="#{customerbean.customer.mobileno}" required="true" requiredMessage="#{text['validation.error.required.mobileno']}" validatorMessage="#{text['validation.error.mobileno']}" readonly="#{customerbean.disabled}" >
<f:validateLongRange minimum="0" maximum="99999999999999" />
</p:inputText>
<p:inputText id="faxno" value="#{customerbean.customer.faxno}" readonly="#{customerbean.disabled}" />
<h:outputLabel for="otherno" value="Other No." />
<h:outputLabel for="primaryemail" value="Primary email" />
<p:inputText id="otherno" value="#{customerbean.customer.otherno}" readonly="#{customerbean.disabled}" />
<p:inputText id="primaryemail" value="#{customerbean.customer.primaryemail}" required="false" validatorMessage="#{text['validation.error.required.email']}" readonly="#{customerbean.disabled}">
<f:validateRegex pattern="([\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z])?" />
</p:inputText>
<h:outputLabel for="alternativeemail" value="Alternative email" />
<p:inputText id="alternativeemail" value="#{customerbean.customer.alternativeemail}" required="false" validatorMessage="#{text['validation.error.required.email']}" readonly="#{customerbean.disabled}">
<f:validateRegex pattern="([\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z])?" />
</p:inputText>
<h:outputLabel for="maritalstatus" value="Marital status" />
<h:outputLabel for="nochildren" value="No. of Children" />
<p:selectOneMenu id="maritalstatus" value="#{customerbean.customer.maritalStatus}" disabled="#{customerbean.disabled}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Single" itemValue="Single" />
<f:selectItem itemLabel="Married" itemValue="Married"/>
<f:selectItem itemLabel="Divorced" itemValue="Divorced"/>
<f:selectItem itemLabel="Widow" itemValue="Widow"/>
</p:selectOneMenu>
<p:inputText id="nochildren" value="#{customerbean.customer.nochildren}" readonly="#{customerbean.disabled}" />
<f:facet name="footer">
<center>
<p:commandButton action="#{customerbean.add(customerbean.customer)}" ajax="false" value="Save" icon="ui-icon-check" />
<p:commandButton value="Reset" update="cpr passportno name nationality dob address mailingaddress gender genderhidden mobileno faxno otherno primaryemail alternativeemail maritalstatus maritalstatushidden nochildren messages" process="#this"
icon="ui-icon-cancel">
<pe:resetInput for="cpr passportno name nationality dob address mailingaddress gender genderhidden mobileno faxno otherno primaryemail alternativeemail maritalstatus maritalstatushidden nochildren"/>
</p:commandButton>
</center>
</f:facet>
</p:panelGrid>
<p:inputText id="genderhidden" type="hidden" value="#{customerbean.customer.gender}" />
<p:inputText id="maritalstatushidden" type="hidden" value="#{customerbean.customer.maritalStatus}" />
</ui:define>
</ui:composition>
</html>
Set customerbean to #ViewScoped
eg:
#ManagedBean
#ViewScoped
public class customerbean implements Serializable {
}
Ok, I found the culprit: noSelectionOption="true" on the f:selectItem. Once I remove that, it works fine. The reason maritalStatus worked is because it doesnt have the noSelectionOption attribute.