2012-01-14 49 views
0

我遇到了標題中描述的問題。我的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中,也不在上面的常用文本框中(不在所示的代碼中)。

任何人都知道什麼是錯的?

+0

假設xhmtl中的's'是'Section',那麼你能顯示它的代碼嗎?另請注意,'s.manager.userID'會導致更改管理員的用戶標識,而不是該部分的管理員。這可能不被你的模型支持。 – Thomas 2012-01-14 13:29:52

+0

JSF更新了模型值嗎?在'updateSection()'方法中調試'Section s'的內容。你使用什麼持久性API?休眠? @Thomas這也是我想到的第一個,但OP也提到「通常的文本框」也不起作用。 – BalusC 2012-01-14 13:30:37

回答

0

不知道它是否有幫助,但在JSF 1.2中我有類似的問題。問題是,h:selectOneMenu返回String值而不是我懷疑的對象。

也許這個「bug」沒有解決JSF2.0。

嘗試類似:

// ManagedBean 
String userId; 

String getUserId(){return this.userId;} 
void setUserId(String userId){this.userId = userId;} 

// JSF 
<h:selectOneMenu value="#{managedBean.userId}" 
         styleClass="inputlabel" id="Vorgesetzter" 
         rendered="#{s.editable}">        
    <f:selectItems value="#{userBean.userList}" var="us" 
        itemLabel="#{us.surename}, #{us.forename}" 
        itemValue="#{us.userID}" /> 
</h:selectOneMenu> 

,並與userId工作之前將其轉換成你想要的對象,或者只是嘗試使用轉換器。

+1

這不是一個錯誤。這是設計。 Java對象不能作爲HTTP請求參數傳遞,而不能先將其轉換爲字符串。即便如此,這不是OP的具體問題。 OP的具體問題已經在托馬斯和我自己對這個問題的評論中得到了確定。但是,只要OP沒有提供任何反饋,就不可能給出合適的答案。 – BalusC 2012-01-17 14:02:25

相關問題