2012-11-06 31 views
5

Tôi có 2 menu thả xuống: Loại & Mã. Tôi muốn thả xuống Mã để thay đổi giá trị tùy thuộc vào menu thả xuống Loại nếu giá trị = A hoặc B hoặc C. Làm cách nào tôi có thể chuyển giá trị của A hoặc B hoặc C vào trình nghe để có thể hiểu và xử lý Danh sách của tôi?Cách chuyển giá trị vào Trình nghe trong selectOneMenu

 <h:outputLabel value="Type" for="idType" /> 
    <h:selectOneMenu id="idType" value="#{myController.type}"> 
     <f:selectItem itemLabel="AAA" itemValue="AAA" /> 
     <f:selectItem itemLabel="BBB" itemValue="BBB" /> 
     <f:selectItem itemLabel="CCC" itemValue="CCC" /> 
     <f:ajax event="valueChange" listener="#{myController.changeCodeList}" render="idCode" execute="@this" /> 
    </h:selectOneMenu> 
    <h:outputLabel value="Code" for="idCode" /> 
    <h:selectOneMenu id="idCode" value="#{myController.code}" > 
     <f:selectItem itemLabel="Select ..." noSelectionOption="true" /> 
     <f:selectItems value="#{myController.codeList}" /> 
    </h:selectOneMenu> 
+1

Ajax4jsf là một sublibrary của RichFaces với thẻ của 'thư viện '. Bạn dường như không sử dụng nó ở bất cứ đâu. Vui lòng không sử dụng thẻ '[ajax4jsf]' trên câu hỏi của bạn sau đó. – BalusC

Trả lời

6

tháo event="valueChange" từ <f:ajax hoặc thay thế bằng event="change"

Bạn không cần phải vượt qua giá trị như nó đã ở đó (trong changeCodeList phương pháp)

public void changeCodeList(AjaxBehaviorEvent ev) { 
    System.out.println(type); //here is your value 
    //now repopulate your list based on the value 
    codeList = someMethod(type); 
} 
+0

Tuyệt. Cảm ơn bạn rất nhiều – Peter

+0

Bạn được chào đón. – Daniel

0

Bạn có thể sử dụng

<f:setPropertyActionListener value="You want to pass" target="Backing bean property that you want to set" /> 

n tùy chọn khác là

<a4j:support ajaxSingle="true" reRender="codeCombo" 
          event="onchange"></a4j:support> 

nên sử dụng a4j: hỗ trợ bạn có thể rerender mã trên việc lựa chọn các loại

+2

Cảm ơn bạn đã trả lời yor, tôi sẽ kiểm tra. Có lẽ richface4 không hỗ trợ a4j: support, tôi không thể thấy phần tử đó – Peter

Các vấn đề liên quan