3

actually I got a inputText and some ajax Request to render a datatable when a keyup event appears.

mypage.xhmtl:

 <h:form id="form">

    <h:inputText id="number_in" value="#{bean.number}" redisplay="false" >
         <f:ajax event="keyup" render=":form:dataTable" />
    </h:inputText>

    <h:dataTable id="dataTable" ...>
    ...
    </h:dataTable>

 <h:form>

I don't want to render the dataTable from the jsf page anymore. I want to render the dataTable in a MangedBean by FacesContext when a listener method is invoked.

mypage.xhtml:

<h:form id="form">

    <h:inputText id="number_in" value="#{bean.number}" redisplay="false" >
         <f:ajax event="keyup" listener="#{bean.onKeyup}" />
    </h:inputText>

    <h:dataTable id="dataTable" ...>
    ...
    </h:dataTable>

mybean.java:

  @ManagedBean(name="bean")
  @SessionScoped
  public class Bean {
     ...
     public void onKeyUp(AjaxBehaviorEvent event) {
        //Here I want to render the dataTable
     }
     ...
  }

How can I achieve that?

Paul Wasilewski
  • 9,762
  • 5
  • 45
  • 49
  • When exactly would you like to do that? When a managed bean action or listener method is invoked, for example? If so, please show the code of the component and method which is responsible for this, then we can tell you how to alter it accordingly. – BalusC Jun 21 '12 at 12:51
  • I just add more code and, hopefully, improved my Question. – Paul Wasilewski Jun 21 '12 at 13:07

2 Answers2

13

You can programmatically add render IDs to PartialViewContext#getRenderIds().

FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("form:dataTable");

Note that this can contain only absolute client IDs and should not be prefixed with :.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks a lot. Will the dataTable rendered immediately? – Paul Wasilewski Jun 21 '12 at 13:13
  • No, only when the render response phase is executed for the same request. That's only one phase away. The listener method is executed during invoke application phase. – BalusC Jun 21 '12 at 13:13
-2
FacesContext.getCurrentInstance().getPartialViewContext().setRenderAll(true);
josliber
  • 43,891
  • 12
  • 98
  • 133
  • 5
    Why is this the correct answer? Please add some explanation also. – d4Rk Sep 08 '15 at 20:55
  • 1
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – JAL Sep 10 '15 at 16:55