Package com.sun.faces.context

Examples of com.sun.faces.context.StateContext


     * @throws IOException if an error occurs building the view.
     */
    @Override
    public void buildView(FacesContext ctx, UIViewRoot view)
    throws IOException {
        StateContext stateCtx = StateContext.getStateContext(ctx);
        if (Util.isViewPopulated(ctx, view)) {
            Facelet f = faceletFactory.getFacelet(view.getViewId());
            // Disable events from being intercepted by the StateContext by
            // virute of re-applying the handlers.
            try {
                stateCtx.setTrackViewModifications(false);
                f.apply(ctx, view);
                reapplyDynamicActions(ctx);
                if (stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
                    markInitialStateIfNotMarked(view);
                }
            } finally {
                stateCtx.setTrackViewModifications(true);
            }
            return;
        }

        view.setViewId(view.getViewId());

        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Building View: " + view.getViewId());
        }
        if (faceletFactory == null) {
            ApplicationAssociate associate = ApplicationAssociate.getInstance(ctx.getExternalContext());
            faceletFactory = associate.getFaceletFactory();
            assert (faceletFactory != null);
        }
        RequestStateManager.set(ctx,
                                RequestStateManager.FACELET_FACTORY,
                                faceletFactory);
        Facelet f = faceletFactory.getFacelet(view.getViewId());

        // populate UIViewRoot
        try {
            ctx.getAttributes().put(IS_BUILDING_INITIAL_STATE, Boolean.TRUE);
            stateCtx.setTrackViewModifications(false);
            f.apply(ctx, view);
           
            if (f instanceof XMLFrontMatterSaver) {
                XMLFrontMatterSaver frontMatterSaver = (XMLFrontMatterSaver) f;
                String DOCTYPE = frontMatterSaver.getSavedDoctype();
                if (null != DOCTYPE) {
                    Util.saveDOCTYPEToFacesContextAttributes(DOCTYPE);
                }
                String XMLDECL = frontMatterSaver.getSavedXMLDecl();
                if (null != XMLDECL) {
                    Util.saveXMLDECLToFacesContextAttributes(XMLDECL);
                }
            }
           
            if (!stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
                reapplyDynamicActions(ctx);
            }
           
            doPostBuildActions(ctx, view);
        } finally {
View Full Code Here


    }

    
    private void doPostBuildActions(FacesContext ctx, UIViewRoot root) {
        StateContext stateCtx = StateContext.getStateContext(ctx);
//        if (stateCtx.isPartialStateSaving(ctx, root.getViewId())) {
      // lu4242            root.markInitialState();
  //      }
        stateCtx.startTrackViewModifications(ctx, root);
    }
View Full Code Here

        stateCtx.startTrackViewModifications(ctx, root);
    }

     private void markInitialState(FacesContext ctx, UIViewRoot root)
     {
         StateContext stateCtx = StateContext.getStateContext(ctx);
         if (stateCtx.isPartialStateSaving(ctx, root.getViewId())) {
             try {
                 ctx.getAttributes().put(IS_BUILDING_INITIAL_STATE, Boolean.TRUE);
                 if (!root.isTransient()) {
                     markInitialState(root);
                 }
View Full Code Here

     * modifications off and on as required. </p>
     *
     * @param context the Faces context.
     */
    private void reapplyDynamicActions(FacesContext context) {
        StateContext stateContext = StateContext.getStateContext(context);
        List<ComponentStruct> actions = stateContext.getDynamicActions();
        if (actions != null) {
            for (ComponentStruct action : actions) {
                if (ComponentStruct.REMOVE.equals(action.action)) {
                    reapplyDynamicRemove(context, action);
                }
View Full Code Here

        // no need to suppress events at that time
        UIViewRoot root = ctx.getViewRoot();
        if (root != null) {
            String viewId = root.getViewId();
            if (viewId != null) {
                StateContext stateCtx = StateContext.getStateContext(ctx);
                return stateCtx.isPartialStateSaving(ctx, viewId);
            }
        }
        return false;

    }
View Full Code Here

        popComponentFromEL(ctx, c, ccStackManager, compcompPushed);
    }

    private void adjustIndexOfDynamicChildren(FacesContext context,
            UIComponent parent) {
        StateContext stateContext = StateContext.getStateContext(context);
        if (!stateContext.hasOneOrMoreDynamicChild(parent)) {
            return;
        }

        List<UIComponent> children = parent.getChildren();
        List<UIComponent> dynamicChildren = Collections.emptyList();

        for (UIComponent cur : children) {
            if (stateContext.componentAddedDynamically(cur)) {
                if (dynamicChildren.isEmpty()) {
                    dynamicChildren = new ArrayList<UIComponent>(children.size());
                }
                dynamicChildren.add(cur);
            }
        }
       
        // First remove all the dynamic children, this puts the non-dynamic children at
        // their original position
        for (UIComponent cur : dynamicChildren) {
            int i = stateContext.getIndexOfDynamicallyAddedChildInParent(cur);
            if (-1 != i) {
                children.remove(cur);
            }
        }
       
        // Now that the non-dynamic children are in the correct position add the dynamic children
        // back in.
        for (UIComponent cur : dynamicChildren) {
            int i = stateContext.getIndexOfDynamicallyAddedChildInParent(cur);
            if (-1 != i) {
                if (i < children.size()) {
                    children.add(i, cur);
                } else {
                    children.add(cur);
View Full Code Here

        // no need to suppress events at that time
        UIViewRoot root = ctx.getViewRoot();
        if (root != null) {
            String viewId = root.getViewId();
            if (viewId != null) {
                StateContext stateCtx = StateContext.getStateContext(ctx);
                return stateCtx.isPartialStateSaving(ctx, viewId);
            }
        }
        return false;

    }
View Full Code Here

    @Override
    public StateManagementStrategy getStateManagementStrategy(FacesContext context, String viewId) {
        StateManagementStrategy result;
       
        StateContext stateCtx = StateContext.getStateContext(context);
        if (stateCtx.isPartialStateSaving(context, viewId)) {
            result = new FaceletPartialStateManagementStrategy(context);
        } else {
            result = new FaceletFullStateManagementStrategy(context);
        }
       
View Full Code Here

                throw new FacesException(ioe);
            }
        }

        UIViewRoot root = super.restoreView(context, viewId);       
        StateContext stateCtx = StateContext.getStateContext(context);
        stateCtx.startTrackViewModifications(context, root);
       
        return root;
    }
View Full Code Here

     * @throws IOException if an error occurs building the view.
     */
    @Override
    public void buildView(FacesContext ctx, UIViewRoot view)
    throws IOException {
        StateContext stateCtx = StateContext.getStateContext(ctx);
        if (Util.isViewPopulated(ctx, view)) {
            Facelet f = faceletFactory.getFacelet(view.getViewId());
            // Disable events from being intercepted by the StateContext by
            // virute of re-applying the handlers.
            try {
                stateCtx.setTrackViewModifications(false);
                f.apply(ctx, view);
                reapplyDynamicActions(ctx);
            } finally {
                stateCtx.setTrackViewModifications(true);
            }
            return;
        }

        view.setViewId(view.getViewId());

        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Building View: " + view.getViewId());
        }
        if (faceletFactory == null) {
            ApplicationAssociate associate = ApplicationAssociate.getInstance(ctx.getExternalContext());
            faceletFactory = associate.getFaceletFactory();
            assert (faceletFactory != null);
        }
        RequestStateManager.set(ctx,
                                RequestStateManager.FACELET_FACTORY,
                                faceletFactory);
        Facelet f = faceletFactory.getFacelet(view.getViewId());

        // populate UIViewRoot
        try {
            ctx.getAttributes().put(IS_BUILDING_INITIAL_STATE, Boolean.TRUE);
            stateCtx.setTrackViewModifications(false);
            f.apply(ctx, view);
           
            if (!stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
                reapplyDynamicActions(ctx);
            }
           
            doPostBuildActions(ctx, view);
        } finally {
View Full Code Here

TOP

Related Classes of com.sun.faces.context.StateContext

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.