Parameters Process Failed when I select a - jsf-2

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

Related

Change input based on combo value

I know this question exists somewhere else in SO but either the solutions are old (and JSF seems to have improved a lot) or I cannot make the solution work.
As simple as it sounds, I would like to replace the text of an input element based on the value of a combo box. I would like to use Ajax, and would like this to work even if there is only one element in the combo (it doesn't matter if by default the selection of the combo is empty).
<h:selectOneMenu id="fnamecombo" valueChangeListener="#{namesController.setForename(fnamecombo)}">
<c:forEach items="#{namesController.myForenames}" var="myforename">
<f:selectItem itemValue="#{myforename}" itemLabel="#{myforename}" />
</c:forEach>
<f:ajax render="fnameinput" />
</h:selectOneMenu>
<h:inputText value="#{namesController.forename}" id="fnameinput" />
This doesn't work. So first of all, I have no idea how to call the setForename method. If I use valueChangeListener="#{namesController.setForename('xxxxx')}" it works, but only the 1st time and iff there are more than one element in the combo, since otherwise the event does not seem to be fired.
What is the easy fix?
EDIT
Ok, so I have made progress. It was easier than I expected:
<h:selectOneMenu id="fnamecombo" value="#{namesController.forename}">
<c:forEach items="#{namesController.myForenames}" var="myforename">
<f:selectItem itemValue="#{myforename}" itemLabel="#{myforename}" />
</c:forEach>
<f:ajax render="fnameinput" />
</h:selectOneMenu>
<h:inputText value="#{namesController.forename}" id="fnameinput" />
This seems to work on a selectItem that I create by hand, but not on the one that is printing with the foreach loop. So this is the rendered code, where I obtained 'john' from the loop and I manually created 'example':
<select id="myForm:fnamecombo" name="myForm:fnamecombo" size="1" onchange="mojarra.ab(this,event,'valueChange',0,'myForm:fnameinput')">
<option value="example">example</option>
<option value="john">john</option>
</select>
It works with 'example' but not with 'john'.
Finally I got the answer.
<h:selectOneMenu id="fnamecombo" value="#{namesController.forename}">
<f:selectItems value="#{namesController.myForenames}" />
<f:ajax render="fnameinput" />
</h:selectOneMenu>
<h:inputText value="#{namesController.forename}" id="fnameinput" />
No need for forEach as mentioned by Alexandre Lavoie.
This answer by Luiggi Mendoza gave me the hint to find it out. The reason my input was not updated by the values in the f:selectItems and it was in the ones that I introduced manually is the scope of the managed bean. I realised that the input was actually being updated in any case, but when coming from the f:selectItems the input was updated with null. Why? Because the scope of namesController was #RequestScoped and not #ViewScoped. Changing this solves the problem.

Does hideNoSelectionOption attribute work for Primefaces? [duplicate]

I have the following selectOneMenu and within of my component I want to have an item which shouldn't be shown, for e.g. in cases where the value from #{Mybean.value} match a value from #{Mybean.ListValues} I don't want to have an empty option in my combo box .
<p:selectOneMenu value="#{Mybean.value}" hideNoSelectionOption="true"
required="true" requiredMessage="Required data">
<f:selectItem itemLabel="" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{Mybean.ListValues}" var="option" itemLabel="#{option.optionName}"
itemValue="#{option.optionId}"/>
</p:selectOneMenu>
I searched, but I didn't find anything useful, just one link in primefaces forum where describes exactly this problem.
My primefaces version is 3.5
Edit: it is supported from version 9 and on, see the other answer.
That attribute doesn't exist in the official api or in the doc. Where did you get it from?
What you're actually looking for is the itemDisabled attribute on the f:selectItems component. It's this attribute that disables a selectItem from being selected. Historically, primefaces has had problems with that attribute.
Ideally, you should have
<p:selectOneMenu value="#{Mybean.value}" required="true" requiredMessage="Required data">
<f:selectItem itemLabel="" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems itemDisabled="#{Mybean.value=='aValue'}" value="#{Mybean.ListValues}" var="option" itemLabel="#{option.optionName}" itemValue="#{option.optionId}"/>
</p:selectOneMenu>
hideNoSelectionOption implemented in PrimeFaces 9.0
Issue: https://github.com/primefaces/primefaces/issues/5886
PR: https://github.com/primefaces/primefaces/pull/5909
So, basically and based on #kolossus answer, we can in primefaces (when you are using <p:selectOneMenu...) case add the following empty item
<f:selectItem itemValue="#{null}" itemLabel="--select--" itemDisabled="#{Mybean.value ne null}" />
We can in primefaces (when we have to use
Note: In such case we don't need the following two tags:
hideNoSelectionOption="true"
and
noSelectionOption="true"

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.

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.

Constructor of a viewScoped class invoked twice

I've been struggling with this for two days with no success and I think it's already time to ask for your help. But first of all, this is what I'm using:
JSF 2 Mojara 2.1.1
Primefaces 3.4.2
Netbeans 7.1.1
Tomcat 7.0.37
And now, the problem: I have a main page which is composed by several other pages using several <ui:include .. /> tags, like this:
<ui:composition template="/resources/templates/template1.xhtml">
<ui:define name="appData">
<p:panelGrid columns="1" id="contenidoAplicacion" styleClass="noborder">
<h:form id="fNewPerson">
<p:panel header="New employee" style="min-height:40em">
<ui:include src="./forms/personal.xhtml" />
<p:accordionPanel styleClass="noborder" activeIndex="3">
<p:tab id="tabSomeData" title="Identidad profesional" >
<ui:include src="./forms/formSomeData.xhtml" />
</p:tab>
....
....
</ui:define>
</ui:composition>
The personal.xhtm file looks like this:
<p:panelGrid>
<p:row>
<p:column >
<h:outputLabel value="Field1"/>
<p:inputText label="Field1" id="field1" value="#{dataBacking.selectedPerson.field1}" tabindex="1"
required="true" size="10" >
<f:convertNumber for="field1" integerOnly="true" groupingUsed="false"/>
</p:inputText>
<p:inputText id="field2" value="#{dataBacking.selectedPerson.field2}" tabindex="2" required="true" size="1" maxlength="1" >
<p:ajax event="keyup" listener="#{dataBacking.check}"
process="field1 field2" partialSubmit="true"
update="field1 field2 photo"/>
</p:inputText>
</p:column>
<p:column rowspan="5" >
<p:graphicImage id="photo" value="#{dataBacking.selectedPerson.photo}" width="90" />
</p:column>
</p:row>
...
</p:panelGrid>
The check() method in the dataBacking class is irrelevant because it only checks if the field1 and the field2 meet some rules and it works properly. The problem comes when the main page is loaded for the first time. In that case, the <p:ajax /> component in personal.xhtml doesn't work. I have to reload the page (simply by pressing the F5 key) and this time it works as it would be expected.
I've been changing some attributes of the component, but nothing seems to work. I really don't know what else to do. Any kind of help will be apreciated.
EDITED. After one more day, I think the problem has nothing to do with Primefaces ajax component, as the title of the question suggested. I've come to this conclusion through these two facts:
The behaviour with the <f:ajax .../> component remains the same.
I've figured out that the view relative to the first time I load the page is not persisted. I'll try to explain myself.
The DataBacking class has defined its scope as view so that the page can "see" all the attributes and methods during the time it's been shown to the user. However, I've noticed that the constructor is called twice: the first time the page is loaded (and then, none of the methods of the class are successfully invoked) and when I refresh the page. In this last case, the behaviour of both the page and the class is the expected one.

Resources