how to get value from ?

前端 未结 1 1813
陌清茗
陌清茗 2021-01-25 00:46

i want to get the value from . i tryed this code but it doesn\'t work :


        
        

        
1条回答
  •  感情败类
    2021-01-25 01:46

    You've after all 2 problems.

    First, the error "erreur de validation. La valeur est incorrecte" which is the French translation of "Validation Error: Value is not valid" means that the submitted value doesn't equals() any one of the available items in . Your code is not complete enough to point out the root cause, but I guess that you've a List there in and thus every item is Department, but you're trying to set it as a String value of id instead of as Department. This is not right. You need to supply a converter between Department and String and use #{departementController.selected} instead.

    Something like this:

    
        
    
    

    with

    private Department selectedDepartment;
    private List availableDepartments;
    

    And a @FacesConverter which converts between Department and its unique String representation.

    Your second problem is that you seem to be focusing too much on JSF 1.x targeted examples as to populating another field on change of the dropdown. You're using a rather clumsy/hacky JSF 1.x workaround for that. In JSF 2.x you can just use for this.

    
        
        
    
    
    

    with

    public void changeDepartment() {
        input = selectedDepartment.getId();
    }
    

    See also:

    • Our selectonemenu wiki page

    0 讨论(0)
提交回复
热议问题