Package javax.faces.application

Examples of javax.faces.application.NavigationCase


      /*
       * GIVEN a parent navigation handler that knows about a specific view
       */
      ConfigurableNavigationHandler parent = mock(ConfigurableNavigationHandler.class);
      FacesContext facesContext = mock(FacesContext.class);
      NavigationCase navigationCase = mock(NavigationCase.class);
      when(parent.getNavigationCase(facesContext, "something", "/viewId.xhtml")).thenReturn(navigationCase);

      /*
       * WHEN RewriteNavigationHandler processes a redirect outcome created by Navigate class
       */
      RewriteNavigationHandler handler = new RewriteNavigationHandler(parent);
      NavigationCase result = handler.getNavigationCase(facesContext, "something",
               "rewrite-redirect:/viewId.xhtml?param1=foo&param2=bar");

      /*
       * THEN it will return the correct navigation case from the parent handler
       */
 
View Full Code Here


      PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
      PrettyConfig config = prettyContext.getConfig();
      if ((outcome != null) && PrettyContext.PRETTY_PREFIX.equals(outcome))
      {
         String viewId = context.getViewRoot().getViewId();
         NavigationCase navigationCase = parent.getNavigationCase(context, fromAction, viewId);
         return navigationCase;
      }
      else if ((outcome != null) && outcome.startsWith(PrettyContext.PRETTY_PREFIX) && config.isMappingId(outcome))
      {
         /*
          * FIXME this will not work with dynamic view IDs... figure out another solution
          * (<rewrite-view>/faces/views/myview.xhtml</rewrite-view> ? For now. Do not support it.
          */
         UrlMapping mapping = config.getMappingById(outcome);
         String viewId = mapping.getViewId();
         if (mapping.isDynaView())
         {
            viewId = dynaview.calculateDynaviewId(context, mapping);
         }
         viewId = FacesNavigationURLCanonicalizer.normalizeRequestURI(context, viewId);

         URL url = new URL(viewId);
         url.getMetadata().setLeadingSlash(true);
         QueryString qs = QueryString.build("");
         if (viewId.contains("?"))
         {
            qs.addParameters(viewId);
         }
         qs.addParameters("?" + PrettyFacesWrappedResponse.REWRITE_MAPPING_ID_KEY + "=" + mapping.getId());

         viewId = url.toString() + qs.toQueryString();

         NavigationCase navigationCase = parent.getNavigationCase(context, fromAction, viewId);
         return navigationCase;
      }
      else
      {
         NavigationCase navigationCase = parent.getNavigationCase(context, fromAction, outcome);
         return navigationCase;
      }
   }
View Full Code Here

   {
      // TODO integrate rewrite with navigation (See PrettyNavigationHandler)
      if (REWRITE_PREFIX.equals(outcome))
      {
         String viewId = context.getViewRoot().getViewId();
         NavigationCase navigationCase = parent.getNavigationCase(context, fromAction, viewId);
         return navigationCase;
      }
      else if (outcome != null && outcome.startsWith(REDIRECT_PREFIX)) {
         String url = outcome.substring(REDIRECT_PREFIX.length());
         String viewId = AddressBuilder.create(url).getPath();
         return parent.getNavigationCase(context, fromAction, viewId);
      }
      else
      {
         NavigationCase navigationCase = parent.getNavigationCase(context, fromAction, outcome);
         return navigationCase;
      }
   }
View Full Code Here

       
        // Check outcome
        if (outcome==null)
            return;
       
        NavigationCase navigationCase = getNavigationCase(context, from, outcome);
        boolean redirect = (navigationCase != null ?
                            navigationCase.isRedirect() :
                           (outcome.indexOf("faces-redirect=true") >= 0));
        // Check for forward (not redirect)
        if (!redirect)
        {
            log.debug("Handling forward navigation.");
View Full Code Here

    @Override
    public NavigationCase getNavigationCase(FacesContext context, String fromAction, String outcome)
    {
        if (parent instanceof ConfigurableNavigationHandler)
        {
            NavigationCase navigationCase = ((ConfigurableNavigationHandler) parent).getNavigationCase(context, fromAction, outcome);
            /*
            if (navigationCase!=null && !navigationCase.isRedirect())
            {
                log.trace("Performing a forward operation!");
            }
View Full Code Here

    }

    @Override
    public void handleNavigation(FacesContext facesContext, String fromAction, String outcome)
    {
        NavigationCase navigationCase = getNavigationCase(facesContext, fromAction, outcome);

        if (navigationCase != null)
        {
            if (log.isLoggable(Level.FINEST))
            {
                log.finest("handleNavigation fromAction=" + fromAction + " outcome=" + outcome +
                          " toViewId =" + navigationCase.getToViewId(facesContext) +
                          " redirect=" + navigationCase.isRedirect());
            }
            if (navigationCase.isRedirect())
            {
                //&& (!PortletUtil.isPortletRequest(facesContext)))
                // Spec section 7.4.2 says "redirects not possible" in this case for portlets
                //But since the introduction of portlet bridge and the
                //removal of portlet code in myfaces core 2.0, this condition
                //no longer applies
               
                ExternalContext externalContext = facesContext.getExternalContext();
                ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
                String toViewId = navigationCase.getToViewId(facesContext);
                String redirectPath = viewHandler.getRedirectURL(facesContext, toViewId, navigationCase.getParameters(), navigationCase.isIncludeViewParams());
               
                // JSF 2.0 the javadoc of handleNavigation() says something like this
                // "...If the view has changed after an application action, call
                // PartialViewContext.setRenderAll(true)...". The effect is that ajax requests
                // are included on navigation.
                PartialViewContext partialViewContext = facesContext.getPartialViewContext();
                if ( partialViewContext.isPartialRequest() &&
                     !partialViewContext.isRenderAll() &&
                     !facesContext.getViewRoot().getViewId().equals(toViewId))
                {
                    partialViewContext.setRenderAll(true);
                }
               
                // JSF 2.0 Spec call Flash.setRedirect(true) to notify Flash scope and take proper actions
                externalContext.getFlash().setRedirect(true);
                try
                {
                    externalContext.redirect(redirectPath);
                    facesContext.responseComplete();
                }
                catch (IOException e)
                {
                    throw new FacesException(e.getMessage(), e);
                }
            }
            else
            {
                ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
                //create new view
                String newViewId = navigationCase.getToViewId(facesContext);
                // JSF 2.0 the javadoc of handleNavigation() says something like this
                // "...If the view has changed after an application action, call
                // PartialViewContext.setRenderAll(true)...". The effect is that ajax requests
                // are included on navigation.
                PartialViewContext partialViewContext = facesContext.getPartialViewContext();
View Full Code Here

     */
    public NavigationCase getNavigationCase(FacesContext facesContext, String fromAction, String outcome)
    {
        String viewId = facesContext.getViewRoot().getViewId();
        Map<String, Set<NavigationCase>> casesMap = getNavigationCases();
        NavigationCase navigationCase = null;

        Set<? extends NavigationCase> casesSet = casesMap.get(viewId);
        if (casesSet != null)
        {
            // Exact match?
View Full Code Here

        String implicitViewId = null;
        boolean includeViewParams = false;
        int index;
        boolean isRedirect = false;
        String queryString = null;
        NavigationCase result = null;
        String viewId = facesContext.getViewRoot().getViewId();
        String viewIdToTest = outcome;
       
        // If viewIdToTest contains a query string, remove it and set queryString with that value.
       
        index = viewIdToTest.indexOf ("?");
       
        if (index != -1)
        {
            queryString = viewIdToTest.substring (index + 1);
            viewIdToTest = viewIdToTest.substring (0, index);
           
            // If queryString contains "faces-redirect=true", set isRedirect to true.
           
            if (queryString.indexOf ("faces-redirect=true") != -1)
            {
                isRedirect = true;
            }
           
            // If queryString contains "includeViewParams=true", set includeViewParams to true.
           
            if (queryString.indexOf ("includeViewParams=true") != -1)
            {
                includeViewParams = true;
            }
        }
       
        // FIXME: the spec states that redirection (i.e., isRedirect=true) is implied when preemptive navigation is performed,
        // though I'm not sure how we're supposed to determine that.
       
        // If viewIdToTest does not have a "file extension", use the one from the current viewId.
        // TODO: I don't know exactly what the spec means by "file extension".  I'm assuming everything after "."
       
        index = viewIdToTest.indexOf (".");
       
        if (index == -1)
        {
            index = viewId.indexOf (".");
           
            if (index != -1)
            {
                viewIdToTest += viewId.substring (index);
            }
        }
       
        // If viewIdToTest does not start with "/", look for the last "/" in viewId.  If not found, simply prepend "/".
        // Otherwise, prepend everything before and including the last "/" in viewId.
       
        if (!viewIdToTest.startsWith ("/"))
        {
            index = viewId.lastIndexOf ("/");
           
            if (index == -1)
            {
                viewIdToTest = "/" + viewIdToTest;
            }
           
            else
            {
                viewIdToTest = viewId.substring (0, index + 1) + viewIdToTest;
            }
        }
       
        // Call ViewHandler.deriveViewId() and set the result as implicitViewId.
       
        try
        {
            implicitViewId = facesContext.getApplication().getViewHandler().deriveViewId (facesContext, viewIdToTest);
        }
       
        catch (UnsupportedOperationException e)
        {
            // This is the case when a pre-JSF 2.0 ViewHandler is used.  In this case, the default algorithm must be used.
            // FIXME: I think we're always calling the "default" ViewHandler.deriveViewId() algorithm and we don't
            // distinguish between pre-JSF 2.0 and JSF 2.0 ViewHandlers.  This probably needs to be addressed.
        }
       
        if (implicitViewId != null)
        {
            Map<String, List<String>> params = new HashMap<String, List<String>>();
           
            // Append queryString to implicitViewId if it exists.
           
//            if (queryString != null)
//            {
//                implicitViewId += "?" + queryString;
//            }
           
            // Finally, create the NavigationCase.
           
            // FIXME: the spec doesn't really say how the redirect parameters are supposed to be
            // populated.  Assuming for now that they should stay empty...
           
            result = new NavigationCase (viewId, fromAction, outcome, null, implicitViewId, params,
                isRedirect, includeViewParams);
        }
       
        return result;
    }
View Full Code Here

       
        for(org.apache.myfaces.config.element.NavigationCase configCase : configCases)
        {  
            if(configCase.getRedirect() != null)
            {
                apiCases.add(new NavigationCase(rule.getFromViewId(),configCase.getFromAction(),configCase.getFromOutcome(),configCase.getIf(),configCase.getToViewId(),configCase.getRedirect().getViewParams(),true,configCase.getRedirect().isIncludeViewParams()));
            }
            else
            {
                apiCases.add(new NavigationCase(rule.getFromViewId(),configCase.getFromAction(),configCase.getFromOutcome(),configCase.getIf(),configCase.getToViewId(),null,false,false));
            }
        }
       
        return apiCases;
    }
View Full Code Here

            throw new FacesException("navigation handler must be instance of ConfigurabeNavigationHandler for use h:link or h:button");
        }
        ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) nh;
       
        //fromAction is null because there
        NavigationCase navigationCase = navigationHandler.getNavigationCase(facesContext, null, href);

        // when navigation case is null, force the "link" to be rendered as text
        if (navigationCase == null)
        {
            return null;
        }
       
        href = navigationCase.getToViewId(facesContext);
               
        if (fragment != null)
        {
            fragment = fragment.trim();
           
            if (fragment.length() > 0)
            {
                href += "#" + fragment;
            }
        }
       
        Map<String, List<String>> parameters = new HashMap<String,List<String>>();
       
        for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
        {
            UIComponent child = (UIComponent)it.next();
            if (child instanceof UIParameter)
            {
                // check for the disable attribute (since 2.0)
                if (((UIParameter) child).isDisable())
                {
                    // ignore this UIParameter and continue
                    continue;
                }
                String name = ((UIParameter)child).getName();
                Object value = ((UIParameter)child).getValue();
                if (parameters.containsKey(name))
                {
                    parameters.get(name).add(value.toString());
                }
                else
                {
                    ArrayList<String> list = new ArrayList<String>(1);
                    list.add(value.toString());
                    parameters.put(name, list);
                }
            }
        }
       
        if (navigationCase.isIncludeViewParams()) {
            parameters.putAll (navigationCase.getParameters());
        }
       
        // In theory the precedence order to deal with params is this:
        // component parameters, navigation-case parameters, view parameters
        // getBookmarkableURL deal with this details.
        href = viewHandler.getBookmarkableURL(facesContext, href, parameters, navigationCase.isIncludeViewParams() || component.isIncludeViewParams());
               
        return href;
    }
View Full Code Here

TOP

Related Classes of javax.faces.application.NavigationCase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.