Programmatically getting UIComponents of a JSF view in bean's constructor

前端 未结 4 1372
执笔经年
执笔经年 2020-12-14 04:34

Imagine a JSF page with several components such as , , , etc. Each compon

4条回答
  •  無奈伤痛
    2020-12-14 05:01

    I tried your solution and it worked :). Here i just posting my answer that how i did it. Actually someone just asked me this question that can we get all the components inside a constructor when our page invoke, i.e., why i asked on this forum:). Here is my code

    /** Creates a new instance of ExporterProfileUpdateRequestGrid */
    public ExporterProfileUpdateRequestGrid() {
    
        session = ConnectionUtil.getCurrentSession();
        exporterProfileUpdateRequestList = new ArrayList();
    
        int test = selectedRadioButton;
        System.out.println();
        //getExporterProfileUpdateRequestGrid();
    
    } //end of constructor
    
    @PostConstruct
    public void init() {
    
        UIViewRoot viewRoot =  FacesContext.getCurrentInstance().getViewRoot();
        UIComponent component1 = viewRoot.findComponent("exporterProfileUpdateRequestGrid");  //form id
        HtmlForm form = (HtmlForm)component1;
    
        List componentList = form.getChildren();
    
        for(int i=0; i panelComponentList = myPanel.getChildren();
    
                for(int j=0; j

    I want to ask that i got form(HtmlForm) here, but panel1 and myTable null, why? Although i get panel and table by inspecting HtmlForm children, but why i can't get them directly.

    Thanks

提交回复
热议问题