Category Archives: Bean

How to select entire row using checkbox


To select all the rows in a table design a page like

 

 

 

 

 

 

create a binding to the table, the valuechangelistener of the checkbox will have the following code


 

 

 

 

 

working example can be downloaded from

http://adfproject.googlecode.com/files/SelectAllRowsInATable.zip

get handle to the next and previous view of the train model


Add the following jstl function library to the jsp:root tag

xmlns:fn=http://java.sun.com/jsp/jstl/functions

and proceed with

text="goto page# #{fn:substringAfter(controllerContext.currentViewPort.taskFlowContext.trainModel.next ,'@')}"
text="goto page# #{fn:substringAfter(controllerContext.currentViewPort.taskFlowContext.trainModel.previous ,'@')}"

some of the values that you can get related to trainModel previous and next actions are

#{controllerContext.currentViewPort.taskFlowContext.trainModel.goNext}
#{controllerContext.currentViewPort.taskFlowContext.trainModel.goPrevious}

Note: to get the display name from the trainstop you have to manually have the binding for next and previous strings added to the bean and evaluate the text manually like

public class Bean {
    TrainModel train;
    TrainStopModel trainStopModel;
String next;
  String previous;
    public Bean() {
      PageFlowStack stack = StateUtils.getCurrentViewPort().getPageFlowStack();
          if (stack.size() > 0)
          {
            train = stack.peek().getTrainModel();
          }
    }
  public static Object evaluateEL(String el) {
      FacesContext facesContext = FacesContext.getCurrentInstance();
      ELContext elContext = facesContext.getELContext();
      ExpressionFactory expressionFactory =
          facesContext.getApplication().getExpressionFactory();
      ValueExpression exp =
          expressionFactory.createValueExpression(elContext, el,
                                                  Object.class);

      return exp.getValue(elContext);
  }
    public void setNext(String next) {
        this.next = next;
    }

    public String getNext() {

      trainStopModel = train.getNextTrainStop(train.getCurrentTrainStop());
      this.next  = trainStopModel.getTextAndAccessKey();
        return next;
    }

    public void setPrevious(String previous) {
      this.previous = previous;
   }

    public String getPrevious() {
        if(train != null){
      trainStopModel = train.getPreviousTrainStop(train.getCurrentTrainStop());
          this.previous  = trainStopModel.getActivityId().getLocalActivityId();
        }
        return previous;
    }
   }

Ways to set the Query Mode programatically


The following snippet will be helpful in setting up the mode of the query criteria in programmatic way.

public Boolean setAdvancedMode(){
              QueryDescriptor descriptor =
                      (QueryDescriptor)evaluateEL
                  ("#{bindings.SearchCriteriaQuery.queryDescriptor}");
              descriptor.changeMode(QueryDescriptor.QueryMode.ADVANCED);
             return true;
}

public Object evaluateEL(String el) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory =
            facesContext.getApplication().getExpressionFactory();
        ValueExpression exp =
            expressionFactory.createValueExpression(elContext, el,
                                                    Object.class);
       return exp.getValue(elContext);
    }

Easiest way to get the current binding from the bean


use the following snippet to get the current binding

BindingContainer bindings =  BindingContext.getCurrent().getCurrentBindingsEntry();
 AttributeBinding at = (AttributeBinding)bindings.getControlBinding("Period");
 at.getInputValue();

The above mentioned code is useful only in case of retrieving values of any attribute binding in the page definition file. To retrieve specific information use it like

//For search binding use it like
FacesCtrlSearchBinding fc =
(FacesCtrlSearchBinding)bindings.findExecutableBinding("PeriodQuery");
or
FacesCtrlSearchBinding fc =
(FacesCtrlSearchBinding)bindings.get("PeriodQuery");

//For LOV binding use it like
FacesCtrlLOVBinding fc = (FacesCtrlLOVBinding)bindings.get("PeriodLOV");

some of the useful methods that can also be used for retrieving binding is

private BindingContainer getBindings() {
BindingContainer bindings =
(BindingContainer)fc.getApplication().evaluateExpressionGet(fc, "#{bindings}",
 BindingContainer.class);
return (bindings == null) ? null : bindings;
 }

to retrieve the bindings  or executable you use it like

//to retireve the tree/table bindings
FacesCtrlHierBinding fc = (FacesCtrlHierBinding)bindings.get("Period");

//to retireve the tree/table iterator
DCIteratorBinding dc = (DCIteratorBinding)bindings.get("PeriodIterator");