解決策を見つけるのを手伝ってください。
これは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;
}
....
}
そしてあなたの助けに感謝します。