Question

I have a requirement in which I have an af:query panel which after querying populates an af:table.

Now based on the table rows when any 1 row is selected, the graphs below it should be populated based on some columns.

Now my problem is that on search when the table is populated for the first time, no row is selected.

I need the first row to be selected automatically. I have searched multiple solutions from the net forums but till now haven't found any working solution.

Please help me what code should I use to select a row programmatically. and also where should I put this code in the backing bean.

Was it helpful?

Solution

As you've correctly mentioned, at the first render of the table no row is selected. I've encountered this problem too, and i've dealt with it by calling a getting the first row of the corresponding VO on BeforePhase (i.e: on the page first rendering or refresh).

I understand that you intend to do so for the first searching. The af:query component has a property called QueryListener. You can link it with a method inside a backing bean. The content should be like:

  private QueryEvent qEvent = null;

  public void queryListener(QueryEvent queryEvent) {
    setQEvent(queryEvent);
    JSFUtils.invokeMethodExpression("#{bindings.YourViewObjectNameViewCriteriaQuery.processQuery}", Object.class,
                                    QueryEvent.class, getQEvent());

    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();  //Edited
    DCBindingContainer bc = (DCBindingContainer)bindings;
    DCIteratorBinding iterator = bc.findIteratorBinding("YourViewObject1Iterator");
    Row r = iterator.getCurrentRow(); //Here you've got the very first row, and can operate with it
   .....
  }

  public void setQEvent(QueryEvent qEvent) {
   this.qEvent = qEvent;
  }

  public QueryEvent getQEvent() {
  return qEvent;
 }

With this, you should be able to get the first row when the query is executed (i.e: when the search is done). After getting the first row, you can programmatically the graph process execution or whatever you do.

NOTE: invokeMethodExpression can be found inside JSFUtils, which is a starndard class with static methods which source code you can download here: JSFUtils.java

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top