Beispiel #1
0
  /**
   * Translate the outcome attribute value to the target URL.
   *
   * @param context the current FacesContext
   * @param outcome the value of the outcome attribute
   * @return the target URL of the navigation rule (or the outcome if there's not navigation rule)
   */
  private String determineTargetURL(FacesContext context, String outcome) {
    ConfigurableNavigationHandler cnh =
        (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler();
    NavigationCase navCase = cnh.getNavigationCase(context, null, outcome);
    /*
     * Param Name: javax.faces.PROJECT_STAGE Default Value: The default value is ProjectStage#Production but IDE can set it differently
     * in web.xml Expected Values: Development, Production, SystemTest, UnitTest Since: 2.0
     *
     * If we cannot get an outcome we use an Alert to give a feedback to the Developer if this build is in the Development Stage
     */
    if (navCase == null) {
      if (FacesContext.getCurrentInstance()
          .getApplication()
          .getProjectStage()
          .equals(ProjectStage.Development)) {
        return "alert('WARNING! " + W_NONAVCASE_BUTTON + "');";
      } else {
        return "";
      }
    } // throw new FacesException("The outcome '"+outcome+"' cannot be resolved."); }
    String vId = navCase.getToViewId(context);

    Map<String, List<String>> params = getParams(navCase, this);
    String url;
    url =
        context
            .getApplication()
            .getViewHandler()
            .getBookmarkableURL(
                context, vId, params, isIncludeViewParams() || navCase.isIncludeViewParams());
    return url;
  }
Beispiel #2
0
  /** Find all parameters to include by looking at nested uiparams and params of navigation case */
  protected static Map<String, List<String>> getParams(NavigationCase navCase, Button button) {
    Map<String, List<String>> params = new LinkedHashMap<String, List<String>>();

    // UIParams
    for (UIComponent child : button.getChildren()) {
      if (child.isRendered() && (child instanceof UIParameter)) {
        UIParameter uiParam = (UIParameter) child;

        if (!uiParam.isDisable()) {
          List<String> paramValues = params.get(uiParam.getName());
          if (paramValues == null) {
            paramValues = new ArrayList<String>();
            params.put(uiParam.getName(), paramValues);
          }

          paramValues.add(String.valueOf(uiParam.getValue()));
        }
      }
    }

    // NavCase Params
    Map<String, List<String>> navCaseParams = navCase.getParameters();
    if (navCaseParams != null && !navCaseParams.isEmpty()) {
      for (Map.Entry<String, List<String>> entry : navCaseParams.entrySet()) {
        String key = entry.getKey();

        // UIParams take precedence
        if (!params.containsKey(key)) {
          params.put(key, entry.getValue());
        }
      }
    }

    return params;
  }
Beispiel #3
0
  public String getSectionURI() {
    FacesContext context = FacesContext.getCurrentInstance();

    NavigationHandler handler = context.getApplication().getNavigationHandler();

    if (handler instanceof ConfigurableNavigationHandler) {
      ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) handler;

      areaId = getCurrentArea().getId();
      sectionId = getCurrentSection().getId();

      NavigationCase navCase =
          navigationHandler.getNavigationCase(
              context, null, "/bookshop2" + SEPARATOR + areaId + SEPARATOR + sectionId);
      if (navCase != null) return navCase.getToViewId(context);
      return getAreaURI();
    }

    return null;
  }
Beispiel #4
0
  /**
   * This method will attempt to find the <code>view</code> identifier based on action reference and
   * outcome. Refer to section 7.4.2 of the specification for more details.
   *
   * @param caseList The list of navigation cases.
   * @param fromAction The action reference string.
   * @param outcome The outcome string.
   * @return The <code>view</code> identifier.
   */
  private CaseStruct determineViewFromActionOutcome(
      List<NavigationCase> caseList, String fromAction, String outcome) {

    CaseStruct result = new CaseStruct();
    for (NavigationCase cnc : caseList) {
      String cncFromAction = cnc.getFromAction();
      String fromOutcome = cnc.getFromOutcome();
      String toViewId = cnc.getToViewId();
      if ((cncFromAction != null) && (fromOutcome != null)) {
        if ((cncFromAction.equals(fromAction)) && (fromOutcome.equals(outcome))) {
          result.viewId = toViewId;
          result.navCase = cnc;
          return result;
        }
      }

      if ((cncFromAction == null) && (fromOutcome != null)) {
        if (fromOutcome.equals(outcome)) {
          result.viewId = toViewId;
          result.navCase = cnc;
          return result;
        }
      }

      if ((cncFromAction != null) && (fromOutcome == null)) {
        if (cncFromAction.equals(fromAction)) {
          result.viewId = toViewId;
          result.navCase = cnc;
          return result;
        }
      }

      if ((cncFromAction == null) && (fromOutcome == null)) {
        result.viewId = toViewId;
        result.navCase = cnc;
        return result;
      }
    }

    return null;
  }
Beispiel #5
0
  public String getAreaURI() {
    FacesContext context = FacesContext.getCurrentInstance();

    NavigationHandler handler = context.getApplication().getNavigationHandler();

    if (handler instanceof ConfigurableNavigationHandler) {
      ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) handler;

      areaId = getCurrentArea().getId();
      // sectionId = getCurrentSection().getId();

      NavigationCase navCase =
          navigationHandler.getNavigationCase(
              context, null, "/bookshop2" + SEPARATOR + areaId + SEPARATOR + areaId);
      // NavigationCase navCase = new NavigationCase("/index.xhtml", null, null, null,
      // "/bookshop2/area1/area1.xhtml", null, false, true);
      return navCase.getToViewId(context);
    }

    return null;
  }
Beispiel #6
0
  /**
   * Add a navigation case to the internal case set. If a case set does not already exist in the
   * case list map containing this case (identified by <code>from-view-id</code>), start a new list,
   * add the case to it, and store the set in the case set map. If a case set already exists,
   * overwrite the previous case.
   *
   * @param navigationCase the navigation case containing navigation mapping information from the
   *     configuration file.
   */
  public void addNavigationCase(NavigationCase navigationCase) {

    String fromViewId = navigationCase.getFromViewId();
    Set<NavigationCase> caseSet = navigationMap.get(fromViewId);
    if (caseSet == null) {
      //noinspection CollectionWithoutInitialCapacity
      caseSet = new LinkedHashSet<NavigationCase>();
      caseSet.add(navigationCase);
      navigationMap.put(fromViewId, caseSet);
    } else {
      // if there already is a case existing for the
      // fromviewid/fromaction.fromoutcome combination,
      // replace it ...  (last one wins).
      caseSet.add(navigationCase);
    }
  }