0

I have a Task Flow with two views: listOfClients and newClient. Shown here:

TaskFlow

listOfClients view has a table which I want to sort before rendering it. To do it, I want to create a SortEvent with the table as source (as shown in the docs, section 29.4.4 ), but I cannot access the table before rendering the view.

I call the method queueSortIdEvent in a pageFlow-scoped managed bean but findComponent cannot find the table (returns null ). Tried also view-scoped, same result.

My code in the bean is:

public UIComponent findComponent(final String id) {

    FacesContext context = FacesContext.getCurrentInstance(); 
    UIViewRoot root = context.getViewRoot();
    final UIComponent[] found = new UIComponent[1];

    root.visitTree(new FullVisitContext(context), new VisitCallback() {     
        @Override
        public VisitResult visit(VisitContext context, UIComponent component) {
            if(component.getId().equals(id)){
                found[0] = component;
                return VisitResult.COMPLETE;
            }
            return VisitResult.ACCEPT;              
        }
    });

    return found[0];

}
public void queueSortIdEvent(){
    SortCriterion sc = new SortCriterion("ClientId", true);
    List<SortCriterion> listSC = new ArrayList<>();
    listSC.add(sc);
    SortEvent new = new SortEvent(findComponent("t1"), listSC); // the table id is "t1"
    new.queue();
}

Is there a way to queue the event before rendering the view?

Note: findComponent function works fine in other parts of the code, got it from here

My JDeveloper version is 12.1.3

Community
  • 1
  • 1
vguzmanp
  • 785
  • 1
  • 10
  • 31

1 Answers1

0

What JDeveloper version are you using?

The findComponent won't work because nothing has been rendered yet. So your component isn't available (= doesn't exists yet) at that moment.

I think there is an easier way to do sorting. On your page/fragment, go to 'Bindings', select your iterator (middle column), click on Edit (pencil icon) and set the sorting you want in the 'Sort criteria' tab.

User404
  • 2,152
  • 2
  • 27
  • 35
  • I edited the question with the version. It's 12.1.3. Sadly this doesn't work in my case. When I go back the newly created row is inserted where I had selected before, not sorted – vguzmanp Oct 28 '14 at 10:23