/**
  * Read controller from the request.
  *
  * @return the search controller
  */
 private SearchController readController() {
   FacesContextBroker broker = new FacesContextBroker();
   @SuppressWarnings("unused")
   FacesContext fc = broker.getFacesContext();
   // intentionally not used
   SearchController controller =
       (SearchController) broker.resolveManagedBean(JSFBEAN_SEARCH_CONTROLLER);
   controller.setSearchCriteria(this.getCriteria());
   return controller;
 }
  /**
   * Read SearchCriteria from the session.
   *
   * @return the search controller
   */
  private SearchCriteria readSessionCriteria() {
    FacesContextBroker broker = new FacesContextBroker();
    @SuppressWarnings("unused")
    FacesContext fc = broker.getFacesContext();
    fc.getApplication().getViewHandler().createView(fc, SEARCH_PAGE);

    // intentionally not used
    SearchCriteria criteria = (SearchCriteria) broker.resolveManagedBean(JSFBEAN_SEARCH_CRITERIA);

    return criteria;
  }
  /**
   * Show results.
   *
   * @throws Exception the exception
   */
  protected void showResults() throws Exception {
    FacesContextBroker broker = new FacesContextBroker();
    String dispatchTo = "";
    String tagName = "com.esri.gpt.control.filter.EncodingFilterTag";
    // will prevent going to front page
    this.getRequestContext().addToSession(tagName, "tag");
    HttpServletRequest httpReq = broker.extractHttpServletRequest();
    HttpServletResponse httpResp = broker.extractHttpServletResponse();
    FacesContext fctx = broker.getFacesContext();
    Application application = fctx.getApplication();

    if (this.isResultsOnly()) {
      dispatchTo = SEARCH_RESULTS_PAGE;

    } else {

      // TODO: Glassfish does not support this section (f=searchpage)
      NavigationHandler navHandler = application.getNavigationHandler();
      navHandler.handleNavigation(fctx, null, "catalog.search.results");
      dispatchTo = fctx.getViewRoot().getViewId();

      String jsfSuffix = SearchConfig.getConfiguredInstance().getJsfSuffix();
      if ("".equals(jsfSuffix)) {
        jsfSuffix = ".page";
      }
      if (jsfSuffix.indexOf('.') < 0) {
        jsfSuffix = "." + jsfSuffix;
      }
      // javax.faces.DEFAULT_SUFFIX
      dispatchTo = dispatchTo.replaceAll(".jsp", jsfSuffix);
      // ViewHandler.DEFAULT_SUFFIX_PARAM_NAME = jsfSuffix;
      // fctx.getExternalContext().dispatch(dispatchTo);
      // httpReq.getRequestDispatcher( dispatchTo).forward(httpReq, httpResp);

    }

    // Synching criteria with session criteria in thread so that search result
    // does
    // not have to wait for synch to complete.
    setExtraCriteriaProperties(httpReq);
    SynchSessionCriteria synchSc = new SynchSessionCriteria(criteria, this.readSessionCriteria());
    synchSc.synch();
    // Thread thread = new Thread(synchSc);
    // thread.start();
    jsfDispatchPage(fctx, dispatchTo);
  }