5 Replies Latest reply on Apr 26, 2011 6:51 AM by Ilya Shaikovsky

    Has AjaxViewRootRenderer been deleted in richfaces 4.0?

    Xmen lin Newbie

      Why have many class removed in richfaces 4.0 ? AjaxViewRootRenderer, AjaxViewRoot......

        • 1. Has AjaxViewRootRenderer been deleted in richfaces 4.0?
          Nick Belaevski Master

          Hi Xmen,

           

          RF4 is based on JSF2 built-in features such as Ajax, resources handling, etc. So we removed number of legacy classes that are not necessary anymore.

           

          Please provide more information on why do you need those, I'll try to point to equivalents in JSF2/RF4 API that you can use.

          • 2. Re: Has AjaxViewRootRenderer been deleted in richfaces 4.0?
            Xmen lin Newbie

            Hi nick,

                Thanks to reply!  I implemented that a few features below:

            1.custom component

              

            for example:I implemented tree view combobox with UIComponentTagBase and AjaxComponentRendererBase。Tree combobox is easier to use than the rich:combobox,but UIComponentTagBase does not exist in richfaces 4.0

                  

            2.extends AjaxViewRoot

             

            When a user requests the server to automatically add the progress bar tips. and request is complete , close the progress bar. So do not need to manually add  prompt progress in many page

                     

            3.change ajaxstatemanager

             

            i used jquery modal dialog and load dialog content by jquery.load.  It should throw view restore excetion when close dialog.  so i updated ajaxstatemanager:when open dialog  ajaxstatemanager will save current view ,and when close dialog will restore view.

            ajaxstatemanager code:

             

            private void writeState(FacesContext context,

                        ResponseStateManager responseStateManager, Object[] stateArray)

                        throws IOException {

                    // Capture writed state into string.

                    ResponseWriter originalWriter = context.getResponseWriter();

                    StringWriter buff = new StringWriter(128);

                    try {

                        ResponseWriter stateResponseWriter = originalWriter

                                .cloneWithWriter(buff);

                        context.setResponseWriter(stateResponseWriter);

                        responseStateManager.writeState(context, stateArray);

                        stateResponseWriter.flush();

                        String stateString = buff.toString();

                        originalWriter.write(stateString);

                        String stateValue = getStateValue(stateString);

                        context.getExternalContext().getRequestMap().put(CAPTURED_VIEW_STATE, stateValue);

             

                        /* xmen start */

                        if (isSavingStateInClient(context)) {

                            saveAjaxState(context, stateArray);

                        }

                        /* xmen end */

             

                        if (null != stateValue) {

                        } else {

                        }

                    } finally {

                        context.setResponseWriter(originalWriter);

                    }

                }

             

            public UIViewRoot restoreView(FacesContext context, String viewId,

                        String renderKitId) {

                    UIViewRoot viewRoot = null;

                    /* xmen start */               

                    viewRoot = restoreAjaxState(context);

                    if (null != viewRoot) {

                        return viewRoot;

                    }

                    /* xmen end */

            。。。。。

             

            protected Object[] saveStateInSession(FacesContext context,

                        Object treeStructure, Object state) {

                    Object[] serializedView;

                    UIViewRoot viewRoot = context.getViewRoot();

                    StateHolder stateHolder = getStateHolder(context);

                    String id = getLogicalViewId(context);

                    stateHolder.saveState(viewRoot.getViewId(), id, new Object[] {

                            treeStructure, state });

             

                    /* xmen start */

                    saveAjaxState(context, new Object[]{treeStructure, state});

                    /* xmen end */

             

                    serializedView = new Object[]{id, null};

                    return serializedView;

                }

             

            private void saveAjaxState(FacesContext context, Object[] stateArray) {

                    if ("save".equalsIgnoreCase(context.getExternalContext()

                            .getRequestParameterMap().get("jstate"))) {

                        java.util.Stack<Object[]> stateValues = (java.util.Stack<Object[]>) context

                                .getExternalContext().getSessionMap().get("AJAX_JSTATE");

                        if (null == stateValues) {

                            stateValues = new java.util.Stack<Object[]>();

                        }

                        stateValues.push((Object[]) context.getExternalContext()

                                .getSessionMap().get("TMP_AJAX_JSATE"));

                        context.getExternalContext().getSessionMap().put("AJAX_JSTATE",

                                stateValues);

                    }

                    context.getExternalContext().getSessionMap().put("TMP_AJAX_JSATE",

                            new Object[] { context.getViewRoot().getViewId(), stateArray });

                }

             

                private UIViewRoot restoreAjaxState(FacesContext context) {

                    if ("restore".equalsIgnoreCase(context.getExternalContext()

                            .getRequestParameterMap().get("jstate"))) {

                        TreeStructureNode treeStructure = null;

                        Object[] state = null;

                        Object[] serializedView = null;

                        java.util.Stack<Object[]> stateValues = (java.util.Stack<Object[]>) context

                                .getExternalContext().getSessionMap().get("AJAX_JSTATE");

                        try {

                            Object[] stateValue = stateValues.pop();

                            String saveViewId = (String) stateValue[0];

                            serializedView = (Object[]) stateValue[1];

             

                            if (isSavingStateInClient(context)) {

                                treeStructure = (TreeStructureNode) serializedView[0];

                                state = (Object[]) serializedView[1];

                            }

                            else {

                                treeStructure = (TreeStructureNode) serializedView[0];

                                state = (Object[]) handleRestoreState(context,

                                        serializedView[1]);

                            }

             

                            UIViewRoot viewRoot = (UIViewRoot) treeStructure

                                    .restore(componentLoader);

                            viewRoot.setViewId(saveViewId);

                            viewRoot.processRestoreState(context, state[0]);

                            restoreAdditionalState(context, state[1]);

                            // context.renderResponse();

                            return viewRoot;

                        }

                        catch (Exception e) {

                            throw new FacesException("Restore view is fault!", e);

                        }

                    }

                    else

                        return null;

                }


            • 3. Re: Has AjaxViewRootRenderer been deleted in richfaces 4.0?
              Nick Belaevski Master

              1.custom component

                

              for example:I implemented tree view combobox with UIComponentTagBase and AjaxComponentRendererBase。Tree combobox is easier to use than the rich:combobox,but UIComponentTagBase does not exist in richfaces 4.0

              RichFaces 4 does not support JSF JSP pages, because they are deprecated. Use Facelets.

                     2.extends AjaxViewRoot

               

              When a user requests the server to automatically add the progress bar tips. and request is complete , close the progress bar. So do not need to manually add  prompt progress in many page

              Use PartialViewContext/ExtendedPartialViewContext for things like that.

              3.change ajaxstatemanager

               

              i used jquery modal dialog and load dialog content by jquery.load.  It should throw view restore excetion when close dialog.  so i updated ajaxstatemanager:when open dialog  ajaxstatemanager will save current view ,and when close dialog will restore view.

              ajaxstatemanager code:

              Special state manager for Ajax is not necessary anymore, so you should override standard state manager of JSF.

              • 4. Re: Has AjaxViewRootRenderer been deleted in richfaces 4.0?
                Xmen lin Newbie

                dear nick, Tks!

                     I understand your reply. so org.ajax4jsf.component.ajaxcommandbutton is deprecated,because used facelets?

                all tag's clases  are deprecated in a4j.taglib.xml?

                • 5. Has AjaxViewRootRenderer been deleted in richfaces 4.0?
                  Ilya Shaikovsky Master

                  no, taglib.xml files are facelets files so not deprecated... jsp use tld files.