[英]jsf rendered condition not working with selectOneMenu
嗨,我讀過很多類似的問題,但是答案對我沒有用。
我有這個
<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}" />
如您所見,當選擇一個選項時,我要呈現測試。 tipoTaxon基本上是我數據庫中的一個表,並且是類,因此我必須制作一個轉換器。 看來現在如此,我現在沒有遇到以前的錯誤。 現在我沒有得到任何錯誤,但是“測試”沒有被渲染。
我嘗試了以下
#{taxonDM.taxon.tipoTaxon != null}
也
#{taxonDM.taxon.tipoTaxon.idTipoTaxon != null}"
我嘗試在另一個面板上設置測試
<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>
使用render =“ test”或render =“ formTaxon2”
我向p:ajax添加了一個偵聽器方法,它可以正常工作,因此我知道它正在被調用。
public void tipoTaxonesXX(AjaxBehaviorEvent e){
System.out.println("Working");
}
它確實在我的控制台上打印了“正在工作”。 我的表單也沒有保存,因此我想它無法從tipotaxon或number轉換,但是它為null,稍后再解決。
這是轉換器,如果有人需要
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());
}
}
我需要提出一些例外
更新答案我的代碼在這里有很多錯誤,我做了很多更改,但是主要的問題是轉換器上的EJB無法正常工作。 我最終使用了ManagedBean。 此處的更多信息http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#ProcessingGETRequestParameters
正如我在說以前的回答你的問題 ,無論是<p:selectOneMany>
值必須指向你的用戶類, TipoTaxon
,每<f:selectItem>
/ <f:selectItems>
項目值也必須指向同一用戶類, TipoTaxon
。
如您所見, itemValue="0"
或itemValue="txn.nombreTipo"
滿足上述聲明。 更正它,然后查看它是否有效。
對於以后的發布,我的建議是發布完整,相關且必要格式化的代碼 ,在您的情況下,包括轉換器代碼,模型類和托管Bean部件。 另外,請勿將同一問題重復兩次/重復等,而應嘗試自己解決 ,否則它將作為重復項關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.