Package javax.faces.application

Examples of javax.faces.application.Application


        {
            throw new FacesException("FacesContext is null");
        }

        // init the View
        Application application = facesContext.getApplication();
        ViewHandler viewHandler = application.getViewHandler();
       
        // Call initView() on the ViewHandler. This will set the character encoding properly for this request.
        viewHandler.initView(facesContext);

        UIViewRoot viewRoot = facesContext.getViewRoot();

        RestoreViewSupport restoreViewSupport = getRestoreViewSupport();

        // Examine the FacesContext instance for the current request. If it already contains a UIViewRoot
        if (viewRoot != null)
        {
            if (log.isLoggable(Level.FINEST))
                log.finest("View already exists in the FacesContext");
           
            // Set the locale on this UIViewRoot to the value returned by the getRequestLocale() method on the
            // ExternalContext for this request
            viewRoot.setLocale(facesContext.getExternalContext().getRequestLocale());
           
            restoreViewSupport.processComponentBinding(facesContext, viewRoot);
            return false;
        }
       
        String viewId = restoreViewSupport.calculateViewId(facesContext);

        // Determine if the current request is an attempt by the
        // servlet container to display an error page.
        // If the request is an error page request, the servlet container
        // is required to set the request parameter "javax.servlet.error.message".
        final boolean errorPageRequest = facesContext.getExternalContext().getRequestMap()
                                                 .get("javax.servlet.error.message") != null;
       
        // Determine if this request is a postback or an initial request.
        // But if it is an error page request, do not treat it as a postback (since 2.0)
        if (!errorPageRequest && restoreViewSupport.isPostback(facesContext))
        { // If the request is a postback
            if (log.isLoggable(Level.FINEST))
                log.finest("Request is a postback");

            try
            {
                facesContext.setProcessingEvents(false);
                // call ViewHandler.restoreView(), passing the FacesContext instance for the current request and the
                // view identifier, and returning a UIViewRoot for the restored view.
                viewRoot = viewHandler.restoreView(facesContext, viewId);
                if (viewRoot == null)
                {
                    // If the return from ViewHandler.restoreView() is null, throw a ViewExpiredException with an
                    // appropriate error message.
                    throw new ViewExpiredException("No saved view state could be found for the view identifier: " + viewId,
                        viewId);
                }
               
                // Restore binding
                // This code was already called on UIViewRoot.processRestoreState, or if a StateManagementStrategy
                // is used, it is called from there.
                //restoreViewSupport.processComponentBinding(facesContext, viewRoot);
               
                // Store the restored UIViewRoot in the FacesContext.
                facesContext.setViewRoot(viewRoot);
            }
            finally
            {
                facesContext.setProcessingEvents(true);
            }
        }
        else
        { // If the request is a non-postback
            if (log.isLoggable(Level.FINEST))
                log.finest("Request is not a postback. New UIViewRoot will be created");
           
            //viewHandler.deriveViewId(facesContext, viewId)
            ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(facesContext,
                    restoreViewSupport.deriveViewId(facesContext, viewId));
           
            if (vdl != null)
            {
                ViewMetadata metadata = vdl.getViewMetadata(facesContext, viewId);
               
                Collection<UIViewParameter> viewParameters = null;
               
                if (metadata != null)
                {
                    viewRoot = metadata.createMetadataView(facesContext);
                   
                    if (viewRoot != null)
                    {
                        viewParameters = metadata.getViewParameters(viewRoot);
                    }
                }
   
                // If viewParameters is not an empty collection DO NOT call renderResponse
                if ( !(viewParameters != null && !viewParameters.isEmpty()) )
                {
                    // Call renderResponse() on the FacesContext.
                    facesContext.renderResponse();
                }
            }
            else
            {
                // Call renderResponse
                facesContext.renderResponse();
            }
           
            // viewRoot can be null here, if ...
            //   - we don't have a ViewDeclarationLanguage (e.g. when using facelets-1.x)
            //   - there is no view metadata or metadata.createMetadataView() returned null
            if (viewRoot == null)
            {
                // call ViewHandler.createView(), passing the FacesContext instance for the current request and
                // the view identifier
                viewRoot = viewHandler.createView(facesContext, viewId);
            }
           
            // Subscribe the newly created UIViewRoot instance to the AfterAddToParent event, passing the
            // UIViewRoot instance itself as the listener.
            // -= Leonardo Uribe =- This line it is not necessary because it was
            // removed from jsf 2.0 section 2.2.1 when pass from EDR2 to Public Review
            // viewRoot.subscribeToEvent(PostAddToViewEvent.class, viewRoot);
           
            // Store the new UIViewRoot instance in the FacesContext.
            facesContext.setViewRoot(viewRoot);
           
            // Publish an AfterAddToParent event with the created UIViewRoot as the event source.
            application.publishEvent(facesContext, PostAddToViewEvent.class, viewRoot);
        }

        // add the ErrorPageBean to the view map to fully support
        // facelet error pages, if we are in ProjectStage Development
        // and currently generating an error page
View Full Code Here


    /* App */

    public static FacesApplication getFacesApplication()
    {
        ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
        Application app = appFactory.getApplication();
        return (FacesApplication) app;
    }
View Full Code Here

        throws AbortProcessingException
    {
        log.info("ApplicationStartupListener:processEvent");
        if (event instanceof PostConstructApplicationEvent)
        {
            Application app = ((PostConstructApplicationEvent) event).getApplication();
            if (!(app instanceof FacesApplication))
                throw new AbortProcessingException("Error: Application is not a "+FacesApplication.class.getName()+" instance. Please create a ApplicationFactory!");
            // Create and Init application
            ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
            FacesApplication jsfApp = (FacesApplication)app;
View Full Code Here

  @Override
  public Object getManagedBean(final String beanName, final FacesContext fc)
  {
    // Find Bean
        final ELContext elcontext = fc.getELContext();
        final Application application = fc.getApplication();
        return application.getELResolver().getValue(elcontext, null, beanName);
  }
View Full Code Here

    {
        // Cleanup
        FacesContext ctx = pe.getFacesContext();
        if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE || ctx.getResponseComplete())
        {
            Application app = ctx.getApplication();
            if (!(app instanceof FacesApplication))
                throw new AbortProcessingException("Error: Application is not a JsfApplication instance. Please create a ApplicationFactory!");
            // Cast and release
            FacesApplication jsfApp = (FacesApplication)app;
            jsfApp.releaseAllConnections(ctx);
View Full Code Here

            // is delegated because we don't have here the required Resource instance
            return ((ComponentBuilderHandler) _delegate).createComponent(ctx);
        }
        UIComponent c = null;
        FacesContext faces = ctx.getFacesContext();
        Application app = faces.getApplication();
        if (_delegate.getBinding() != null)
        {
            ValueExpression ve = _delegate.getBinding().getValueExpression(ctx, Object.class);
            if (this._rendererType == null)
            {
                c = app.createComponent(ve, faces, this._componentType);
            }
            else
            {
                c = app.createComponent(ve, faces, this._componentType, this._rendererType);
            }
            if (c != null)
            {
                c.setValueExpression("binding", ve);
            }
        }
        else
        {
            if (this._rendererType == null)
            {
                c = app.createComponent(this._componentType);
            }
            else
            {
                c = app.createComponent(faces, this._componentType, this._rendererType);
            }
        }
        return c;
    }
View Full Code Here

     * @param component The EditableValueHolder to which the validators should be added
     */
    private void addDefaultValidators(FacesContext context, AbstractFaceletContext actx,
                                      EditableValueHolder component)
    {
        Application application = context.getApplication();
        Map<String, String> validators = new HashMap<String, String>();
       
        // add all defaultValidators
        Map<String, String> defaultValidators = application.getDefaultValidatorInfo();
        if (defaultValidators != null && defaultValidators.size() != 0)
        {
            validators.putAll(defaultValidators);
        }
        // add all enclosing validators
        Iterator<String> enclosingValidatorIds = actx.getEnclosingValidatorIds();
        if (enclosingValidatorIds != null && enclosingValidatorIds.hasNext())
        {
            while (enclosingValidatorIds.hasNext())
            {
                String validatorId = enclosingValidatorIds.next();
                if (!validators.containsKey(validatorId))
                {
                    validators.put(validatorId, null);
                }
            }
        }
       
        if (!validators.isEmpty())
        {
            // we have validators to add
            Set<Map.Entry<String, String>> validatorInfoSet = validators.entrySet();
            for (Map.Entry<String, String> entry : validatorInfoSet)
            {
                String validatorId = entry.getKey();
                String validatorClassName = entry.getValue();
                Validator enclosingValidator = null;
               
                if (validatorClassName == null)
                {
                    // we have no class name for validators of enclosing <f:validateBean> tags
                    // --> we have to create it to get the class name
                    // note that normally we can use this instance later anyway!
                    enclosingValidator = application.createValidator(validatorId);
                    validatorClassName = enclosingValidator.getClass().getName();
                }
               
                // check if the validator is already registered for the given component
                // this happens if <f:validateBean /> is nested inside the component on the view
                Validator validator = null;
                for (Validator v : component.getValidators())
                {
                    if (v.getClass().getName().equals(validatorClassName))
                    {
                        // found
                        validator = v;
                        break;
                    }
                }
               
                if (validator == null)
                {
                    if (shouldAddDefaultValidator(validatorId, context, actx, component))
                    {
                        if (enclosingValidator != null)
                        {
                            // we can use the instance from before
                            validator = enclosingValidator;
                        }
                        else
                        {
                            // create it
                            validator = application.createValidator(validatorId);
                        }
                        // add the validator to the component
                        component.addValidator(validator);
                    }
                    else
View Full Code Here

        return;
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("outcome = '" + outcome + "'");
      }
      Application application = facesContext.getApplication();
      NavigationHandler navigationHandler = application.getNavigationHandler();
      navigationHandler.handleNavigation(facesContext, null, outcome);

      if (facesContext.getViewRoot() == null) {
        ViewHandler viewHandler = application.getViewHandler();
        String viewId = getFromViewId();
        UIViewRoot view = viewHandler.createView(facesContext, viewId);
        facesContext.setViewRoot(view);
      }
View Full Code Here

  protected HtmlCommandLink getLink(FacesContext facesContext, HtmlDataScroller scroller,
          String text, int pageIndex)
  {
    String id = HtmlDataScrollerRenderer.PAGE_NAVIGATION + Integer.toString(pageIndex);
    Application application = facesContext.getApplication();

    HtmlCommandLink link = (HtmlCommandLink) application
            .createComponent(HtmlCommandLink.COMPONENT_TYPE);
    link.setId(scroller.getId() + id);
    link.setTransient(true);
    UIParameter parameter = (UIParameter) application
            .createComponent(UIParameter.COMPONENT_TYPE);
    parameter.setId(scroller.getId() + id + "_param");
    parameter.setTransient(true);
    parameter.setName(scroller.getClientId(facesContext));
    parameter.setValue(id);
    List children = link.getChildren();
    children.add(parameter);
    if (text != null)
    {
      HtmlOutputText uiText = (HtmlOutputText) application
              .createComponent(HtmlOutputText.COMPONENT_TYPE);
      uiText.setTransient(true);
      uiText.setValue(text);
      children.add(uiText);
    }
View Full Code Here

  }

  protected HtmlCommandLink getLink(FacesContext facesContext, HtmlDataScroller scroller,
          String facetName)
  {
    Application application = facesContext.getApplication();

    HtmlCommandLink link = (HtmlCommandLink) application
            .createComponent(HtmlCommandLink.COMPONENT_TYPE);
    link.setId(scroller.getId() + facetName);
    link.setTransient(true);
    UIParameter parameter = (UIParameter) application
            .createComponent(UIParameter.COMPONENT_TYPE);
    parameter.setId(scroller.getId() + facetName + "_param");
    parameter.setTransient(true);
    parameter.setName(scroller.getClientId(facesContext));
    parameter.setValue(facetName);
View Full Code Here

TOP

Related Classes of javax.faces.application.Application

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.