0

フォームを持つ単純な JSF アプリケーションがあり、コントロールの 1 つは次のselectOneListboxとおりです。

<h:selectOneListbox style="width: 231px; height: 27px;position:absolute;left:400px;top:325px;" value="#{PatientsSearch.selectedDoctor}">
    <f:selectItems value="#{PatientsSearch.doctors}" var="d" itemLabel="#{d.name}" itemValue="#{d.name}" />
</h:selectOneListbox>

アプリケーションを実行すると、リストが入力されていることがわかります (つまり、PatientsSearch.doctors が正しく取得されます) selectOneListbox。目的のアイテムを選択すると、そのフォームでは何も機能しなくなります。他のすべてのボタンはアイドル状態のようで、クリックに反応しなくなりました。ただし、 から何も選択されていない場合はselectOneListbox、すべてのボタンが期待どおりに機能します (つまり、マネージド Bean でコールバックがトリガーされます)。

アプリケーションをデバッグしたところ、リスト内の項目を選択した後、フォーム上の他のボタンをクリックしてもコールバックがトリガーされないことに気付きました。また、デバッガーでは、期待どおりにsetSelectedDoctor()が呼び出されることはありません (上記のスニペットを参照)。

私は JSF の Mojarra 2.0.1 実装を使用しています。

ここで何が欠けていますか?


更新:これはフォーム全体です:

    <h:form style="width: 876px; background-color: #FED981; padding-left: 60px; padding-top: 30px; margin-left: 80px; margin-top: 40px; color: #804000; font-style: normal; font-family: Verdana, Arial, Sans-Serif">
    <h:outputLabel style="position:absolute;left:200px;top:100px;" value="New appointment:"></h:outputLabel>
    <br>
    <br>
    <h:inputText style="width: 259px;position:absolute;left:200px;top:120px;" binding="#{PatientsSearch.inputText1}" valueChangeListener="#{PatientsSearch.lookForName}" immediate="true" id="inputText1" />
    <h:commandButton value ="Search patients by name:" style="width: 173px;position:absolute;left:465px;top:120px;" action="#{PatientsSearch.getPatientsByName}">
        <f:param name="day" value="#{request.getParameter('day')}" />
        <f:param name="month" value="#{request.getParameter('month')}" />
        <f:param name="year" value="#{request.getParameter('year')}" />  
    </h:commandButton>

    <br>
    <h:panelGroup id="pn_DETAILS_GRP" style="overflow:auto;position:absolute;top:155px;left:200px;width:300px;height:150px;solid black">
        <h:dataTable id="tb_USER_DETAILS" border="1" var="patient" value="#{PatientsSearch.patients}" style="width:300px;height:150px" rowClasses="oddRow, evenRow">
        <h:column id="name">
        <f:facet name="header">
        <h:outputText value="Name" style="font-size:10pt"/>
        </f:facet>
        <h:outputText value="#{patient.name}" style="font-size:8pt"/>
        </h:column>
        <h:column id="phone">
        <f:facet name="header">
        <h:outputText value="Phone" style="font-size:10pt"/>
        </f:facet>
        <h:outputText value="#{patient.phoneMobile}" style="font-size:8pt"/>
        </h:column>
        <h:column>
        <h:inputHidden id="patientId" value="#{patient.id}" />
        </h:column>
        </h:dataTable>
    </h:panelGroup>

    <h:inputHidden id="testId"  />

    <br><br><br>
    <h:outputLabel value="Choose doctor:" style="width: 200px;position:absolute;left:200px;top:325px;"></h:outputLabel>
    <h:selectOneListbox style="width: 231px; height: 27px;position:absolute;left:400px;top:325px;" value="#{PatientsSearch.selectedDoctor}" size="1">
        <f:selectItems value="#{PatientsSearch.doctors}" var="d"
            itemLabel="#{d.name}" itemValue="#{d.name}" />
    </h:selectOneListbox>
    <br><br><br>
    <h:commandButton value="Schedule" style="position:absolute;left:200px;top:430px;" action="#{PatientsSearch.scheduleAppointment}">
        <f:param name="day" value="#{request.getParameter('day')}" />
        <f:param name="month" value="#{request.getParameter('month')}" />
        <f:param name="year" value="#{request.getParameter('year')}" /> 
    </h:commandButton>

</h:form>
4

1 に答える 1

0

コメントによると、問題は の型が#{d.name}と同じではないこと#{PatientsSearch.selectedDoctor}です。このような状況では、2 つの解決策があります。

  1. 持っているものはすべて同じにして、#{PatientsSearch.selectedDoctor}getter/setter を String 型に変更します。
  2. SelectItemバッキング Bean でのリストを作成し、 #{PatientsSearch.selectedDoctor}getter/setter を String 型に変更します。バッキング Bean はすでにリスト コンポーネントの準備が整ったオブジェクトを提供しているため、itemValueandを削除することもできます。itemLabel
  3. itemValueから属性を変更しf:selectItems、カスタム コンバーターを作成します。

ビューをよりよく分離するので、私は2番目を好みます。次のように変更する必要があります。

<h:selectOneListbox style="width: 231px; height: 27px;position:absolute;left:400px;top:325px;" value="#{PatientsSearch.selectedDoctor}" size="1">
    <f:selectItems value="#{PatientsSearch.doctors}" var="d" itemLabel="#{d.name}" />
    <f:converter convertId="doctorConverter" />
</h:selectOneListbox>

コンバーターの場合、次のように開始できます。

@FacesConverter(value="doctorConverter")
public class DoctorConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        // Your code, select doctor from value ID for example.
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        // Your code, return doctor ID from value.
    }
}
于 2013-06-23T20:51:59.893 に答える