disable/ enable primefaces components - jsf-2

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.

Related

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.

Parameters Process Failed when I select a

Hi I am doing something really simple but it is not working I am using jboss and jsf 2.0.
So I am trying to create a form that shows some fields according to a selection from the user of dropdown menu so I am using selectOneMenu
<h:panelGrid columns="2" id="formTaxon">
<h:outputLabel value="Nombre Científico Taxón" for="taxonInput" />
<p:inputText value="#{taxonDM.taxon.nombreCientificoTaxon}"
id="taxonInput" />
<h:outputLabel value="Nombre Común" for="nombreComunInput" />
<p:inputText value="#{taxonDM.taxon.nombreComunTaxon}"
id="nombreComunInput" />
<h:outputLabel value="Tipo" for="tipoTaxon" />
<p:selectOneMenu id="tipoTaxon" value="#{taxonDM.taxon.tipoTaxon}"
name="tipoTaxon">
<f:selectItem itemLabel="Seleccione uno" itemValue="" />
<f:selectItems value="#{tipoTaxonDM.tiposTaxones}" var="txn"
itemValue="#{txn.idTipoTaxon}" itemLabel="#{txn.nombreTipo}" />
<f:ajax process="#this"
listener="#{taxonController.tipoTaxonesXX}" render="formTaxon" />
</p:selectOneMenu>
<p:inputText id="test" val="" />
</h:panelGrid>
I also tried without the listener first
But nothing works, I dont get any errors on the server I get an error when I check the scripts with firebug
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class java.lang.IllegalStateException</error-name><error-message><![CDATA[Parameters processing failed.]]></error-message></error></partial-response>
I tested it on a jboss 7.0.2 and 7.1.1 with firefox. I read there was a bug between IE and jboss 7.1.1 related with this but I guess this is not the case.
I also tried with h:selectOneMenu instead of p:selectOneMenu. There was no change.
You are binding the value of your dropdown box as a taxon.tipoTaxon in <p:selectOneMenu id="tipoTaxon" value="#{taxonDM.taxon.tipoTaxon}">, when the item values are idTipoTaxon.
As far as we can get, the former is of type TipoTaxon and the latter is of type Integer, most probably. So when JSF tries to convert between those types it fails.
You need either to provide for a Converter so that JSF would know how to convert submitted strings to your model objects (you can find many examples here, on Stack Overflow), or bind dropdown value as an integer as well like value="#{taxonDM.taxon.idTipoTaxon}".

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.

update value: radio-button values togglig back and forth

I'm trying to update a a radio-componet, which is triggered by a onchange-event of a select-box. I see the radio-button toggling as desired after the onchange, but it automatically toggles back the next second.
<h:selectOneMenu id="selectId" value="#{someBean.someSelectValue}"
onchange="this.form.submit()" valueChangeListener="#{someBean.someChange}" immediate="true">
<p:ajax update="radioId"/>
<f:selectItems value="#{someBean.availableSraTitel}" />
</h:selectOneMenu>
<h:selectOneRadio id="radioId" value="#{someBean.someRadioValue}">
<f:selectItem itemLabel="Yes" itemValue="true" />
<f:selectItem itemLabel="No" itemValue="false" />
</h:selectOneRadio>
What am I missing here?
Jonny
Remove onchange="this.form.submit()" (the f:ajax will submit the value to the server)
Also remove immediate="true" (I don't think you really planning to skip any validations here)
Last thing, change <p:ajax update="radioId"/> into <f:ajax render="radioId"/>
p:ajax is from primefaces and you are using plain JSF components
As suggested by BalusC : You also better replace the valueChangeListener="#{someBean.someChange}" by adding listener="#{someBean.someChange}" to your f:ajax (you should change teh signature of the method too)

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