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
Related
So,
I've an ArrayList with the values of State and City, And I've to check if state are equals to some variable, lets call its "var1" and if this state are equals, I've to get the city names...
I'm creating a menu filter.
<div class="col-md-3">
<label>#{msg['state']}</label>
<h:selectOneMenu id="mdl-state" value="#{saisReportQueryBean.keyState}" class="form-control">
<f:ajax listener="#{saisReportQueryBean.Teste()}"/>
<f:selectItem itemValue="#{null}" itemLabel="#{msg['select_state']}" noSelectionOption="true" />
<f:selectItems value="#{saisReportQueryBean.keyState}" var="estado" itemValue="#{estado}" itemLabel="#{estado}" />
</h:selectOneMenu>
</div>
<div class="col-md-3">
<label>#{msg['city']}</label>
<h:selectOneMenu id="mdl-city" value="#{saisReportQueryBean.keyCity}" class="form-control">
<f:selectItem itemValue="#{null}" itemLabel="#{msg['select_city']}" noSelectionOption="true" />
<f:selectItems value="#{saisReportQueryBean.keyCity}" var="cidade" itemValue="#{cidade}" itemLabel="#{cidade}" />
</h:selectOneMenu>
</div>
When I select the state, I've to update my city itens with just only city in references with the state selected.
Here is my java code.:
protected void updateData() {
this.reportQuery = new SaisReportQuery();
this.queryExecuted = false;
cidades = cidadesIbgeBeanRemote.findAll();
cidades.sort((f1, f2) -> f1.getMunicipio().compareTo(f2.getMunicipio()));
Map<String, List<CidadeIbge>> estados = cidades.stream().collect(Collectors.groupingBy(CidadeIbge::getUf));
setKeyState(estados.keySet());
getKeyState().toString();
System.out.println(keyState);
}
Tks.
Sorry everyone for my uncompleted question.
My point is, when I select some value in my menu, this have to change another menu with the values in referente:
Front Implementation:
<h:panelGroup layout="block" class="col-md-3" id="panel-state">
<label>#{msg['state']}</label>
<h:selectOneMenu id="mdl-state" value="#{saisReportQueryBean.reportQuery.state}" binding="#{uf}" class="form-control input_no_round_corner">
<f:selectItem itemValue="#{null}" itemLabel="#{msg['select_state']}" noSelectionOption="true" />
<f:selectItems value="#{saisReportQueryBean.keyState}" var="estado" itemValue="#{estado}" itemLabel="#{estado}" />
<f:ajax listener="#{saisReportQueryBean.UpdateCityByState(uf.value)}" render=":panel-city" event="change" execute="#this" onevent="initializeChosenFieldsCity">
</f:ajax>
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup layout="block" class="col-md-3" id="panel-city">
<label>#{msg['city']}</label>
<h:selectOneMenu id="mdl-city" value="#{saisReportQueryBean.listCidades}" class="form-control input_no_round_corner">
<f:selectItem itemValue="#{null}" itemLabel="#{msg['select_city']}" noSelectionOption="true" />
<f:selectItems value="#{saisReportQueryBean.listCidades}" var="cidade" itemValue="#{cidade.municipio}" itemLabel="#{cidade.municipio}" />
</h:selectOneMenu>
</h:panelGroup>
Back implementation:
cidades = cidadesIbgeBeanRemote.findAll();
setKeyState(new ArrayList(estados.keySet()));
getKeyState().toString();
getKeyState().sort((f1, f2) -> f1.compareTo(f2));
I have a problem when I select an item from a component and when updating another component, it stops working. The strange thing is that with the application works correctly but with it breaks.
<p:panelGrid columns="#{bundle.columnas}" layout="grid" id="panel">
<p:outputLabel for="provincia" value="Provincia *" />
<p:selectOneMenu id="provincia"
value="#{inmuebleBacking.provincia}"
converter="provinciaConverter">
<f:selectItem itemLabel="Seleccione Una Provincia" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{provinciaBacking.findAllProvincias()}" var="prov" itemLabel="#{prov.provinciaNombre}" />
<p:ajax update="ciudad" listener="#{inmuebleBacking.provinciaSelecionada()}"/>
</p:selectOneMenu>
<p:outputLabel for="ciudad" value="Ciudad *" />
<h:selectOneMenu id="ciudad"
value="#{inmuebleBacking.ciudad}"
converter="ciudadConverter"
required="true">
<f:selectItem itemLabel="Seleccione Una Ciudad" itemValue="" />
<f:selectItems value="#{inmuebleBacking.ciudades}" var="ciudad" itemLabel="#{ciustrong textdad.ciudadNombre} cp: #{ciudad.cp}"/>
</h:selectOneMenu>
BackingBeans
#ViewScoped
#ManagedBean(name = "inmuebleBacking")
public class InmuebleBacking {
#EJB
private CiudadDAO ciudadDAO;
private List<Ciudad> ciudades;
public void provinciaSelecionada() {
Inmueble inmueble = (Inmueble) getEntity();
ciudades = ciudadDAO.findAllNamedBy("Ciudad.findByProvinciaId", "provinciaId", inmueble.getProvincia().getId());}
SCREENSHOTS
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 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
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.