我遇到了标题中描述的问题。我的selectOneMenu不改变我的价值:/SelectOneMenu不使用新的值
<h:column>
<f:facet name="header">
<h:outputText value="Vorgesetzter" />
</f:facet>
<h:outputText
value="#{s.manager.surename}, #{s.manager.forename}"
rendered="#{not s.editable}" />
<h:selectOneMenu value="#{s.manager.userID}"
styleClass="inputlabel" id="Vorgesetzter"
rendered="#{s.editable}">
<f:selectItem
itemValue="${null}" itemLabel="-"/>
<f:selectItems value="#{userBean.userList}" var="us"
itemLabel="#{us.surename}, #{us.forename}"
itemValue="#{us.userID}" />
</h:selectOneMenu>
</h:column>
<h:column>
<h:commandButton value="bearbeiten"
action="#{sectionBean.switchEdit(s)}"
rendered="#{not s.editable}" />
<h:commandButton value="speichern"
action="#{sectionBean.updateSection(s)}"
rendered="#{s.editable}" />
<h:commandButton value="abbrechen"
action="#{sectionBean.switchEdit(s)}"
rendered="#{s.editable}" />
</h:column>
这是一块sections.xhtml。它被表单标签包围。
这是我的豆:
package at.ac.htlperg.beans;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import at.ac.htlperg.dao.SectionDAO;
import at.ac.htlperg.model.Section;
@ManagedBean
@SessionScoped
public class SectionBean {
SectionDAO sectionDAO;
public SectionBean() {
sectionDAO = new SectionDAO();
}
public SectionDAO getSectionDAO() {
return sectionDAO;
}
public void setSectionDAO(SectionDAO sectionDAO) {
this.sectionDAO = sectionDAO;
}
public List<Section> getSectionList() {
return sectionDAO.getSectionList();
}
public String deleteSection(Section s) {
sectionDAO.deleteSection(s);
return null;
}
public String switchEdit(Section s) {
sectionDAO.switchEdit(s);
return null;
}
public String saveSection() {
sectionDAO.saveSection(sectionDAO.getSection());
return "/secured/sealed/sections.xhtml";
}
public String updateSection(Section s) {
sectionDAO.updateSection(s);
this.switchEdit(s);
return null;
}
}
方法updateSection应该访问数据库并做一个了Session.update(S)。 但它不会保存新值,既不在selectOneMenu中,也不在上面的常用文本框中(不在所示的代码中)。
任何人都知道什么是错的?
假设xhmtl中的's'是'Section',那么你能显示它的代码吗?另请注意,'s.manager.userID'会导致更改管理员的用户标识,而不是该部分的管理员。这可能不被你的模型支持。 – Thomas 2012-01-14 13:29:52
JSF更新了模型值吗?在'updateSection()'方法中调试'Section s'的内容。你使用什么持久性API?休眠? @Thomas这也是我想到的第一个,但OP也提到“通常的文本框”也不起作用。 – BalusC 2012-01-14 13:30:37