如何級聯列表,以便如果用戶更改了selectedCategory列表中的選擇,它應更新selectedTo列表。jsf級聯列表
這裏是我的代碼片段:
<h:selectOneMenu id="selectedCategory" value="#{converterBean.selectedCategory}">
<f:ajax execute="selectedCategory" render="selectedFrom"/>
<f:selectItems value="#{converterBean.categories}"/>
</h:selectOneMenu>
<h:selectOneListbox id="selectedFrom" value="#{converterBean.selectedFrom}" size="5">
<f:selectItems value="#{converterBean.fromList}"/>
<f:ajax execute="selectedCategory selectedFrom" render="selectedTo"/>
</h:selectOneListbox>
<h:selectOneListbox id="selectedTo" value="#{converterBean.selectedTo}" size="5">
<f:selectItems value="#{converterBean.toList}"/>
</h:selectOneListbox>
我注意到,它的更新列表地選自但不會進一步級聯到selectTo列表。
按照建議儘量使兩者地選自和selectedTo的類別選擇從頁面張貼的要求是:
POST http://localhost:8081/converter_web/faces/converter.xhtml HTTP/1.1
Accept: */*
Faces-Request: partial/ajax
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Referer: http://localhost:8081/converter_web/
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Host: localhost:8081
Content-Length: 1253
Connection: Keep-Alive
Pragma: no-cache
Cookie: JSESSIONID=DDDEA598A60CC468763C36B536513B41
converter_form=converter_form&converter_form%3AselectedCategory=temperature&converter_form%3AselectedFrom=mm&converter_form%3AselectedTo=cm&converter_form%3Avalue=0.0&javax.faces.ViewState=b%2BArKl5NJujWibUQzHf3dUG2JlT%2Bnq7KygA2%2FXpXXscCouBr5xT9Br%2BmoP78%2FvuPAYG%2Bi7Q0jFEKGqJpFgRo%2BDU4ZV251yac84pu3bZ71V9j%2BHvRPMkWw82S8q0v2p1jmn3msPXxvKrQQ1oVpr7pGBPXc2faQGXHW55Md%2BKSkspIgCxXx3x3T6NDaJ1%2BGTEFkyb1DE%2BdoQHQ4EjqV3jEC5mq56OlsHgEmkQ8TVCQM%2FPmAfUBWiQEHqBYzohXNfFpO3kfdrKjeTrq648UtGPYU88VJ9mtIOptYEfwFKN9y%2FG9MOBKEfRZ9XlJz2bPt1zmATIg3iRT1W7YVtmHq7e9g%2FUxsM82duMxFUWhoFPHfrFk4tt48LFH29Hk60y3eeFxqtg7g1JxPD1aQrLN9sxBduS53nFWObCms1YU40uvMT2yjX0kp4wM8YwqT2jTFDtLHcVBide1RGTnzFGzjOrbCJ8rIEmWfPa1yUMkXRBBsgpKWFIl0ueBQiCT%2BDoD9UXlNOQGS%2F5tIdP%2BVTO%2FkWiBo5X99SpKwKY8%2B2pqzJKDrPRXIwci52Wi%2Fo%2Fw%2B0TkpnVrtDaDl7w2eYjmq7bYZFRDjWy3Jtgc5V1DUF%2BhX3Bfiq7l%2Fq5YL4DYx0NBI2esfJ0LTFCqXu8aCk%2BWOPOWnOCSGA5Y9EGUXgzV6q%2Fp%2FFWa8Kj8E%2FeoB380eFwXAEiyyRGv&javax.faces.source=converter_form%3AselectedCategory&javax.faces.partial.event=change&javax.faces.partial.execute=converter_form%3AselectedCategory&javax.faces.partial.render=converter_form%3AselectedFrom%20converter_form%3AselectedTo&javax.faces.behavior.event=valueChange&javax.faces.partial.ajax=true
我們希望只selectedCategory被髮送,但它在發送Ajax調用所有表單域。它雖然調用getCategories(),getFromList(),getToList(),但當它調用getToList時,它使用category = temperature和from = mm。 from = mm是POST請求中傳遞的參數selectedFrom = mm。
Regards,
Miten。
Baydogan我已經嘗試過了,導致只有一個當前類別老地選自請求予以公佈。我們想要的是使用selectedCategory填充selectedFrom列表,然後使用selectedCategory和新的selectedFrom查詢selectedTo。 – Miten
我不確定我是否瞭解您的具體功能要求,但是這不僅僅是將'selectedFrom'添加到'execute'的問題?我也很驚訝地發現應該負責填充下拉列表的ajax監聽器丟失了,這表明你在getter方法中做了商業工作,這在JSF中被認爲是一件壞事。 – BalusC
@BalusC據我瞭解,添加要執行的字段僅僅意味着我們希望他們發佈請求。所以當我提交類別時,我只發佈selectedCategory,而當我從單元提交時,我傳遞了selectedCategory和selectedFrom。當類別改變時,來自單位需要刷新。當單位選擇更改爲單位需要刷新時。給出類似的國家 - >州 - >城市級聯。據我所知,渲染方法是我們可以在服務層調用業務邏輯的地方。 – Miten