請幫我找到解決方案。驗證錯誤值無效:primefaces
這是XHTML代碼:
<p:selectOneMenu value="#{activteBean.act.activiteFamille}"
converter="familleAct"
var="f" required="Une famille est obligatoire" >
<f:selectItems value="#{activteBean.actFamList}" var="famille" itemLabel="# {famille.dsgFam}" itemValue="#{famille}"/>
<p:column>#{f.refFam}</p:column>
<p:column>#{f.dsgFam}</p:column>
</p:selectOneMenu>
這裏是我的轉換器:
@FacesConverter(forClass=ActiviteFamille.class,value="familleAct")
public class ActiviteFamilleConverter implements Converter {
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String code) {
if (code.trim().equals("")) {
return null;
} else {
ActiviteFamilleDao actFamDao = new ActiviteFamilleDao();
List<ActiviteFamille> actFamList = actFamDao.findAll();
for (ActiviteFamille af : actFamList) {
if (af.getRefFam().equals(code)) {
return af;
}
}
}
return null;
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return String.valueOf(((ActiviteFamille) value).getRefFam());
}
}
}
管理bean:
@ManagedBean(name = "activteBean")
@ViewScoped
public class ActivteBean implements Serializable {
private Activite act = new Activite();
private ActiviteDao actDao = new ActiviteDao();
private List<Activite> actList;
private boolean init;
private ActiviteFamilleDao actFamDao = new ActiviteFamilleDao();
private List<ActiviteFamille> actFamList;
public boolean isInit() {
act = new Activite();
actList = actDao.findAll();
actFamList=actFamDao.findAll();
return init;
}
....
}
,感謝你的幫助。
您可以嘗試在轉換器方法中查看發送內容和接收內容。 – lamostreta
你問什麼問題? –