如何级联列表,因此如果用户更改 selectedCategory 列表中的选择,它应该更新 selectedTo 列表。
这是我的片段:
<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>
我注意到它更新了 selectedFrom 列表,但没有进一步级联到 selectTo 列表。
根据尝试呈现 selectedFrom 和 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 传递的内容。
问候,
米腾。