Hide some elements in p:selectOneMenu primefaces - jsf-2

I have a SelectOneMenu that I want hide somevalues that came from Bean based on condition (x.situacao eq 'INATIVO').
<p:selectOneMenu id="selectonemenu"
value="#{pessoaBean.pessoa.profissao}" filter="true"
filterMatchMode="startsWith" converter="simpleEntityConverter"
required="true" requiredMessage="Selecione uma Profissao para Pessoa">
<f:selectItem itemValue="" itemLabel="Selecione..."
noSelectionOption="true" />
<f:selectItems value="#{profissaoBean.profissoes}" var="x"
itemLabel="#{x.nome}" itemValue="#{x}"
itemDisabled="#{x.situacao eq 'INATIVO'}"/>
</p:selectOneMenu>
As far I got is disabled value but not hide it from selectonemenu.
How do that? One way is filter this on Bean but I wanna use an already method that I have.

Related

disable/ enable primefaces components

I want to disable some primefaces components after a selection from p:selectOneMenu but when I choose no selection option it still disabled
<p:outputLabel value="Manager" style="color:white;font-weight: bold;" />
<p:selectOneMenu id="manager" value="#{employeeMB.selectedManager}" immediate="true">
<f:selectItem itemLabel="Selectionner..." noSelectionOption="true"/>
<f:selectItems value="#{employeeMB.managers}" />
<p:ajax update="managerSelect role" />
</p:selectOneMenu>
<p:outputLabel value="Est un Manager"
style="color:white;font-weight: bold;" />
<p:selectBooleanCheckbox id="managerSelect"
value="#{employeeMB.employee.isManager}"
disabled="#{employeeMB.selectedManager != null}" />
<p:outputLabel for="role" value="Role Utilisateur" style="color:white;font-weight: bold;" />
<p:selectManyCheckbox id="role" value="#{employeeMB.selectedRoles}">
<f:selectItem itemLabel="Employée" itemValue="ROLE_EMPLOYEE" />
<f:selectItem itemLabel="Manager" itemValue="ROLE_MANAGER" itemDisabled="#{employeeMB.selectedManager != null}"/>
<f:selectItem itemLabel="RH" itemValue="ROLE_RH" itemDisabled="#{employeeMB.selectedManager != null}"/>
</p:selectManyCheckbox>
That can happen when the updated model value is not null, but an empty string. You'd need to reconfigure JSF to interpret empty string submitted values as null to avoid the model being polluted with empty strings via below entry in web.xml.
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
Nonetheless, better use #{not empty bean.property} instead of #{bean.property != null}. It also covers empty strings.
Unrelated to the concrete problem, the noSelectionOption is useless over there. Carefully read Best way to add a "nothing selected" option to a selectOneMenu in JSF to understand it. I also have my doubts about your understanding of the immediate attribute there. Get rid of it. It has no sensible value anymore in JSF 2.x world thanks to all that ajax magic.

<f:ajax listener is not called for the rendered element [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 5 years ago.
I have a selectOneMenu element(carType) which populates another selectOneMenu(manufacture) element on changing it. This works fine and I get it rendered everytime.
Then I have another selectOneMenu(model) which gets populated evertime the manufacture list is changed. This does not seem to work however.I see that the listener is not called at all for carManufacturerChanged. Any help will be appreciated. Code is :
<p:selectOneMenu value="#{createControler.carType}">
<f:selectItem itemLabel="Select Car Type" itemValue="" />
<f:selectItems value="#{createControler.carTypeList}" var="carType"
itemLabel="#{carType}" itemValue="#{carType}"/>
<f:ajax event="change" listener="#{createControler.carTypeChanged}" render="manufacture"/>
</p:selectOneMenu><br></br><br></br>
<p:selectOneMenu value="#{createControler.carManufacturer}" id="manufacture">
<f:selectItem itemLabel="Select Car Manufacturer" itemValue="" />
<f:selectItems value="#{createControler.carManufacturerList}" var="carManufacturer"
itemLabel="#{carManufacturer.manufacture}" itemValue="#{carManufacturer.manufacture}"/>
<f:ajax event="change" listener="#{createControler.carManufacturerChanged}" render="model" />
</p:selectOneMenu><br></br><br></br>
<p:selectOneMenu value="#{createControler.carModel}" id="model">
<f:selectItem itemLabel="Select Car Model" itemValue="" />
<f:selectItems value="#{createControler.carModelList}" var="carModel"
itemLabel="#{carModel.model}" itemValue="#{carModel.model}"/>
</p:selectOneMenu><br></br><br></br>
EDIT : When I add another <f:selectItem itemValue="random" itemLabel="random" /> in the carManufacturer menu, and select it, then the listener is called. So, I think the problem might be that listener is not triggered for elements that are rendered in runtime. Might be of help to someone who can answer.
Go check you corresponding CDI bean's scope. If it's RequestScoped, change the scope to ViewScoped or scopes that spans multiple requests.

PrimeFaces UI SelectOneButton

I am using Primefaces 4.0 with JSF 2.0
my requirement is to do some specific task behind (ON / OFF) selection button, my code is like
<h:form>
<h:panelGrid>
<p:selectOneButton value="#{buttonBean.number}">
<f:selectItem itemLabel="ON" itemValue="1" />
<f:selectItem itemLabel="OFF" itemValue="0" />
</p:selectOneButton>
</h:panelGrid>
</h:form>
for now UI and all is fine but, value is not passed on click to the bean which is buttonBean.number unless i submit it using a submit button.
My aim is to pass and set number = 0 and number = 1 by only click not submit it, where "0" is for Off and "1" is for On,
Another solution without submit
<p:selectOneMenu id="listFilter" value="#{sess.selectedFileId}">
<p:ajax update="mytable" listener="#{beanBacking.fileChanged()}" partialSubmit="true" />
<f:selectItem itemLabel="-- ALL --" itemValue="#{null}" />
<f:selectItems value="#{beanBacking.fileList}" />
</p:selectOneMenu>
<p:ajax /> learn p:ajax more HERE, from this page will not even refersh.

p ajax listener using pretty faces

I have a 2 combo boxes 1.company & 2.city, when I select any company from company's combo box, it will change city combo box on ajax my Question is that should I use
<p:ajax update="city" listener="pretty:cityOnChange" />
OR
<p:ajax update="city" listener="#{actionClass.cityOnChange}" />
when I use below statement I get exception
listener="pretty:cityOnChange": Cannot convert pretty:cityOnChange of type class java.lang.String to class javax.el.MethodExpression
<p:ajax update="city" listener="pretty:cityOnChange" />
this is the code which I am using
<h:outputLabel value="select Company" />
<p:selectOneMenu id="companySelectId" value="#{circleAction.companyBeans.companyBeansId}">
<f:selectItems value="#{circleAction.companyBeans.companyMap}"/>
<p:ajax update="city" listener="pretty:cityOnChange" />
</p:selectOneMenu>
No, you cannot use an PrettyFaces navigation string as a value for the listener attribute. The attribute must refer to method using an EL expression. Just like the exception tells you.

Cascade dynamic rendering selectOneMenu doesn't work

My problem I thougth is simple but I can't find a clear solution.
I have three selectOneMenu, and I want that the first one is always rendered, the second one is rendered if the first one has some value selected and the third one is rendered if the second has some value selected.
The relation between the first one and the second works well, but doesn't work between the second and the third.
When I change the value for the first selectOneMenu the second selectOneMenu is diplayed or hidden correctly.
But when I change the value for the second nothing happened to the third selectOneMenu, like if the f:ajax render isn't fired.
Bellow the jsf code:
<h:panelGrid columns="2">
<h:outputText value="Type Paiement" />
<h:selectOneMenu
value="#{employeurBean.idTypePaiement}">
<f:selectItem itemValue="" itemLabel="Choix typePaiement" />
<f:selectItems value="#{typePaiementBean.typesPaiement}" var="vtp"
itemLabel="#{vtp.libelle}" itemValue="#{vtp.idTypePaiement}" />
<f:ajax event="change" render="gmodp" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="gmodp">
<h:panelGroup rendered="#{employeurBean.idTypePaiement == 2}">
<h:outputText value="Mode Paiement" />
<h:selectOneMenu
value="#{employeurBean.idModePaiement}">
<f:selectItem itemValue="" itemLabel="Choix mode Paiement" />
<f:selectItems value="#{modePaiementBean.modesPaiement}" var="vmp"
itemLabel="#{vmp.libelle}" itemValue="#{vmp.idModePaiement}" />
<f:ajax event="change" render="grib"/>
</h:selectOneMenu>
</h:panelGroup>
</h:panelGrid>
<h:panelGrid id="grib">
<h:panelGroup rendered="#{employeurBean.idModePaiement == 1}">
<h:outputText value="Compte" />
<h:inputText value="#{employeurBean.compte}">
</h:inputText>
</h:panelGroup>
</h:panelGrid>
Is there any idea to achieve that.
Many thanks for your help
This construct will fail if the bean is request scoped and/or you're doing business actions (such as preloading the list) in getter methods instead of action listener methods. Ensure that the bean is been placed in the view scope and that you're doing business actions in action listener methods.
If that doesn't solve the problem, then you really have to post the backing bean code along the view code in your question.

Resources