Hi again, folks,

On Sep 14, 2005, at 11:32, Ihab Awad wrote:
... I tried overriding ViewHandler methods renderView and restoreView to *not* call the state saving mechanism. The result is that I can run my app without UIComponent methods processSaveState or processRestoreState ever being called, which is what I want. ... Hence my question: do you folks see any problems with this approach?

Nobody replied yet, so I thought I'd add some more details of my code. Below are selected portions of my ViewHandler. This is based on the example from Hans Bergsten's JSF book. Again, any comments re this approach, especially regarding portability or possible problems with future JSF implementations, would be appreciated. Peace, -- Ihab

public class CustomViewHandler extends ViewHandler {

    private static final String SMD_VIEW_ID = "/smdMainView";

    private final ViewHandler origViewHandler;
private final Map<String, UIViewRoot> smdViews = new HashMap<String, UIViewRoot>();

    public CustomViewHandler(ViewHandler origViewHandler) {
        this.origViewHandler = origViewHandler;
    }

    public UIViewRoot createView(FacesContext context, String viewId) {
        if (isSMDView(viewId)) {
            UIViewRoot view = customCreateView(context, viewId);
            smdViews.put(viewId, view);
            return view;
        } else {
            return origViewHandler.createView(context, viewId);
        }
    }

public void renderView(FacesContext context, UIViewRoot viewToRender)
        throws IOException
    {
        if (isSMDView(viewToRender)) {
            setupResponseWriter(context);
            /**** NOTE NO STATE SAVING ****/
            context.getResponseWriter().startDocument();
            renderResponse(context, viewToRender);
            context.getResponseWriter().endDocument();
        } else {
            origViewHandler.renderView(context, viewToRender);
        }
    }

public UIViewRoot restoreView(FacesContext context, String viewId) {
        if (isSMDView(viewId)) {
            /**** NOTE NO STATE RESTORATION ****/
            return smdViews.get(viewId);
        } else {
            return origViewHandler.restoreView(context, viewId);
        }
    }

    private boolean isSMDView(String viewId) {
        return viewId.startsWith(SMD_VIEW_ID);
    }

    private boolean isSMDView(UIViewRoot view) {
        return isSMDView(view.getViewId());
    }

private UIViewRoot customCreateView(FacesContext context, String viewId) {

        UIViewRoot result = new UIViewRoot();

        result.setViewId(viewId);
        result.setRenderKitId(calculateRenderKitId(context));
        result.setLocale(calculateLocale(context));

        /**** NOTE CREATING INSTANCE OF MY OWN CLASS ****/
        SMDRootViewPanel rootViewPanel = new SMDRootViewPanel();
        rootViewPanel.initialize();
        result.getChildren().add(rootViewPanel);

        return result;
    }

}


Reply via email to