【发布时间】:2012-01-14 13:04:21
【问题描述】:
我遇到了标题中描述的问题。我的 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将导致更改经理的用户 ID 而不是该部分的经理。您的型号可能不支持此功能。 -
JSF 是否更新了模型值?在
updateSection()方法中调试Section s的内容。您使用的是什么持久性 API?休眠? @Thomas 这也是我的第一个想法,但 OP 还提到“通常的文本框”也不起作用。