p ajax listener using pretty faces - jsf-2

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.

Related

ValueCangeListener work on second try in JSF 2.0

I have two selectOneMenu elements which their id's make difference only.
valueChangeListener works on second try.
At first try, page is refreshing, but does not go the valueChangeCode, thefore no value changes. At second try it goes valueChangeCode and it gets new value and both of selectOneMenu show new value.
<h:selectOneMenu id="changeCurrency" value="#dataBean.showCurrency}" valueChangeListener="#myBean.changePaymentCurreny}"
valueChangeListener="#{myBean.changePaymentCurreny}"
immediate="true"
onchange="submit()">
<f:selectItems value="#{my.currencyList}" />
</h:selectOneMenu>
<h:selectOneMenu id="changeCurrency2"
value="#{dateBean.showCurrency}"
valueChangeListener="#{myBean.changePaymentCurreny}"
immediate="true"
onchange="submit()">
<f:selectItems value="#{myBean.currencyList}" />
</h:selectOneMenu>
In ValueChangeListener code.
dataBean.setShowCurrency(newCurrency);
FacesContext.getCurrentInstance().renderResponse();
FacesContext.getCurrentInstance().getViewRoot().getChildren().clear();
When i remove the line which ends with getChidren.clear, and i change value of one them, changeListener called and changes the value at first try.
On view, only one selectmenu which i changed, shows new value. Other selectOnemenu still show the old value.
dataBean and myBean are in sessionScope. When i myBean put on requestscope, ajax request which works on page load, does not cath the mybean cause of being null.
Could anyone make clear this station.
Thanks very much.
try change the valueChangeListener for an ajax event tag like this.
<h:selectOneMenu id="changeCurrency" value="#dataBean.showCurrency}" valueChangeListener="#myBean.changePaymentCurreny}" onchange="submit()">
<f:selectItems value="#{my.currencyList}" />
<f:ajax event="change" listener="#{myBean.changePaymentCurreny}" process="#this" partialSubmit="true" />
</h:selectOneMenu>
<h:selectOneMenu id="changeCurrency2" value="#{dateBean.showCurrency}" onchange="submit()">
<f:selectItems value="#{myBean.currencyList}" />
<f:ajax event="change" listener="#{myBean.changePaymentCurreny}" process="#this" partialSubmit="true" />
</h:selectOneMenu>

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}".

JSF 2: Cannot choose default entry in dropdown element when dropdown is required and default entry is null

I have the following JSF 2 code:
<p:selectOneMenu id="dropdown" value="#{data.selection}" required="true" converter="selectOneMenuConverter">
<f:selectItem itemLabel="Select one..." itemValue="" noSelectionOption="true" />
<f:selectItems value="#{data.entries}" var="entry" itemLabel="#{entry.name}" itemValue="#{entry}" />
<p:ajax update="display" event="change" />
</p:selectOneMenu>
<h:panelGroup id="display">
<h:outputText value="#{data.selection}" />
</h:panelGroup>
Everything works as expected when I choose a value from the dropdown.
When the user "deselects" an entry by choosing "Select One", JSF complains that this is not possible because the selectonemenu is required.
The problem comes from there that the p:ajax makes a partial submit that triggers validation. Immediate=true does also not work because in case the immediate happens on an input field (like selectonemenu is) a validation is performed.
The validation shall only happen when the user presses the "go on" button on the bottom of the page (not shown in code)
Further the given converter converts the Strings to Objects and for the default value it returns null (that's also the expected value within the domain for "no selection").
So my question is what I must do to fulfill my case.
For my this is a standard case and I cannot imagine that there is no solution for this.
Any ideas?
Best regards,
Florian
The validation shall only happen when the user presses the "go on" button on the bottom of the page (not shown in code)
Then just tell the dropdown's required attribute to do exactly that instead of hardcoding a true.
<h:form id="form">
<p:selectOneMenu ... required="#{not empty param['form:go']}">
...
</p:selectOneMenu>
...
<p:commandButton id="go" ... />
</h:form>
The #{not empty param['form:go']} will only evaluate true when the form submit has actually been taken place by the submit button which has the client ID form:go in the particular example. If you don't like hardcoding client IDs either, then reference it as follows:
<h:form>
<p:selectOneMenu ... required="#{not empty param[go.clientId]}">
...
</p:selectOneMenu>
...
<p:commandButton binding="#{go}" ... />
</h:form>

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