How to pass a parameter along with h:commandButton

前端 未结 1 1678
谎友^
谎友^ 2020-12-05 15:23

One of the most common approaches to change locale in JSF+Seam - with :



        
1条回答
  •  感动是毒
    2020-12-05 15:54

    Either pass as method argument (only if your environment supports EL 2.2),

    
    
    
    

    with

    public void change(String language) {
        locale = new Locale(language);
        // ...
    }
    

    Or use

    
        
    
    
        
    
    
        
    
    

    with

    private String language;
    
    public void change() {
        locale = new Locale(language);
        // ...
    }
    

    Or use

    
        
    
    
        
    
    
        
    
    

    with

    public void change() {
        locale = new Locale(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("language"));
        // ...
    }
    

    (you can also let JSF automatically set it by a @ManagedProperty("#{param.language}"), but this requires the bean to be request scoped, or a , see also ViewParam vs @ManagedProperty(value = "#{param.id}"))


    Enough ways to pass a parameter from view to controller. Take your pick. The serves in JSF context a somewhat different purpose and it can only be manipulated by JavaScript in the onclick which is ugly.

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