Reputation: 1466
Hi I have read tons of similar questions but the answers didnt work for me.
I have this
<p:selectOneMenu id="tipoTaxon" value="#{taxonDM.taxon.tipoTaxon}"
name="tipoTaxon">
<f:converter converterId="tipoTaxonConverter" />
<f:selectItem itemLabel="Seleccione uno" itemValue="0" />
<f:selectItems value="#{tipoTaxonDM.tiposTaxones}" var="txn"
itemValue="#{txn.idTipoTaxon}" itemLabel="#{txn.nombreTipo}" />
<p:ajax render="test" />
</p:selectOneMenu>
<p:inputText id="test" rendered="#{taxonDM.taxon.tipoTaxon != null}" />
As you can see I want to render test when an option is selected. tipoTaxon is basically a table on my database and is class, so I had to make a converter. It seems to work so for now, I am not getting the errors I had before. Now I dont get any errors but "test" is not getting rendered.
I tried the following
#{taxonDM.taxon.tipoTaxon != null}
also
#{taxonDM.taxon.tipoTaxon.idTipoTaxon != null}"
I tried setting test on another panel
<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:converter converterId="tipoTaxonConverter" />
<f:selectItem itemLabel="Seleccione uno" itemValue="0" />
<f:selectItems value="#{tipoTaxonDM.tiposTaxones}" var="txn"
itemValue="#{txn.idTipoTaxon}" itemLabel="#{txn.nombreTipo}" />
<p:ajax render="formTaxon2" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="2" id="formTaxon2">
<p:inputText id="test" rendered="#{taxonDM.taxon.tipoTaxon != null}" />
</h:panelGrid>
using render="test" or render="formTaxon2"
I added a listener method to p:ajax and it worked so i know it is getting invoked.
public void tipoTaxonesXX(AjaxBehaviorEvent e){
System.out.println("Working");
}
It did printed "Working" on my console. My form is not saving either so I guess it has trouble transforming from tipotaxon or number, but it gets null, i ll fix that later.
Here is the converter if someone needs to
import ec.edu.puce.biologia.model.TipoTaxon;
@FacesConverter("tipoTaxonConverter")
public class TipoTaxonConverter implements Converter {
private TipoTaxonDao tipoTaxonDao;
@Override
public Object getAsObject(final FacesContext arg0, final UIComponent arg1,
final String value) {
if (value == null || !value.matches("\\d+")) {
return null;
}
try {
TipoTaxon tipoTaxon = tipoTaxonDao.recuperar(Long.valueOf(value));
System.out.println("Getting the operation value = "
+ tipoTaxon.getNombreTipo());
return tipoTaxon;
} catch (NumberFormatException e) {
return null;
// throw new ConverterException(new
// FacesMessage("Unknown operation ID: " + value));
} /*
* catch (EntidadNoEncontradaException e) { throw new
* ConverterException(new FacesMessage("Unknown operation ID: " +
* value)); }
*/
}
@Override
public String getAsString(final FacesContext arg0, final UIComponent arg1,
final Object value) {
if (!(value instanceof TipoTaxon)
|| ((TipoTaxon) value).getIdTipoTaxon() == null) {
return null;
}
return String.valueOf(((TipoTaxon) value).getIdTipoTaxon());
}
}
I need to put some exceptions
UPDATE ANSWER My code here has many errors, I changed it a lot, but the main problem was that the EJB on the converter didnt work. I ended up using ManagedBean. More on that here http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#ProcessingGETRequestParameters
Upvotes: 0
Views: 1550
Reputation: 11742
As I said in my previous answer to your question, both <p:selectOneMany>
value must point to your user class, TipoTaxon
, and every <f:selectItem>
/<f:selectItems>
itemValue must also point that same user class, TipoTaxon
.
As you see, neither itemValue="0"
, nor itemValue="txn.nombreTipo"
satisfies the abovementioned statement. Correct it and see it working.
My advice for future postings will be to post the complete, relevant and necessarily formatted code, which in your case includes converter code, your model class and managed bean parts. Also, do not post the same question twice/thrice, etc. and instead try to work it out on your own, otherwise it'll be closed as duplicate.
Upvotes: 1