[英]jsf rendered condition not working with selectOneMenu
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.
tipoTaxon基本上是我数据库中的一个表,并且是类,因此我必须制作一个转换器。 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" 使用render =“ test”或render =“ formTaxon2”
I added a listener method to p:ajax and it worked so i know it is getting invoked. 我向p:ajax添加了一个侦听器方法,它可以正常工作,因此我知道它正在被调用。
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.
我的表单也没有保存,因此我想它无法从tipotaxon或number转换,但是它为null,稍后再解决。
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. 更新答案我的代码在这里有很多错误,我做了很多更改,但是主要的问题是转换器上的EJB无法正常工作。 I ended up using ManagedBean.
我最终使用了ManagedBean。 More on that here http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#ProcessingGETRequestParameters
此处的更多信息http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#ProcessingGETRequestParameters
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
. 正如我在说以前的回答你的问题 ,无论是
<p:selectOneMany>
值必须指向你的用户类, TipoTaxon
,每<f:selectItem>
/ <f:selectItems>
项目值也必须指向同一用户类, TipoTaxon
。
As you see, neither itemValue="0"
, nor itemValue="txn.nombreTipo"
satisfies the abovementioned statement. 如您所见,
itemValue="0"
或itemValue="txn.nombreTipo"
满足上述声明。 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. 对于以后的发布,我的建议是发布完整,相关且必要格式化的代码 ,在您的情况下,包括转换器代码,模型类和托管Bean部件。 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.
另外,请勿将同一问题重复两次/重复等,而应尝试自己解决 ,否则它将作为重复项关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.