2012-01-14 5 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の一部です。フォームタグで囲まれています。

これは私のBeanです:

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(複数可)しなければなりません。 しかし、新しい値をselectOneMenuや上の通常のテキストボックス(表示されているコードではありません)に保存することはありません。

何が間違っているのですか?

+0

xhmtlの 's'は' Section'ですので、コードを表示できますか?また、 's.manager.userID'はセクションのマネージャではなく、マネージャのユーザIDを変更することにも注意してください。これはお使いのモデルでサポートされていない可能性があります。 – Thomas

+0

モデル値はJSFによって更新されていますか? 'updateSection()'メソッドで 'Section s'の内容をデバッグします。どの永続性APIを使用していますか?休止状態? @トーマスはこれも私が思った最初のものでしたが、OPはまた、 "通常のテキストボックス"もうまくいかないと言いました。 – BalusC

答えて

0

JSF 1.2でも同様の問題がありました。問題は、h:selectOneMenuが、疑わしいオブジェクトの代わりにString値を返したことです。

この「バグ」は、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

関連する問題