我有那个转换器:
public class PollConverter implements Converter {
private static PollanswersDao pollsDao = new PollanswersDao();
public Object getAsObject(FacesContext context, UIComponent component, String value) {
return pollsDao.read(Long.parseLong(value));
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
return String.valueOf(((PollanswersEntity)value).getId());
}
}
在faces-config.xml中:
<converter>
<converter-id>PollsConverter</converter-id>
<converter-class>org.test.majas.converters.PollConverter</converter-class>
</converter>
所以,我可以通过ID唯一识别民意调查。好吧,我使用这个转换器:
<h:form>
<h:selectOneRadio layout="pageDirection" value="#{votesBean.answer}">
<f:converter converterId="PollsConverter"/>
<f:selectItems value="#{pollsBean.selectItems}" var="item" itemLabel="#{item.value.title}" />
</h:selectOneRadio>
<h:messages/>
<h:commandButton value="#{msgs.vote}" action="#{votesBean.addVote}"/>
</h:form>
但是这个项目标签=&#34;#{item.value.title}&#34;不工作我的selectItems项目标签是ID值...我如何将itemLabels显示为对象&#34; title&#34;领域。
PollsBean:
@Named
@SessionScoped
public class PollsBean implements Serializable {
...
private List<SelectItem> selectItems;
...
public List<SelectItem> getSelectItems() {
return selectItems;
}
public void setSelectItems(List<SelectItem> selectItems) {
this.selectItems = selectItems;
}
...
}
感谢。