/**
 * 
 */
package org.ajax4jsf.portlet.application;

import javax.faces.application.StateManager;
import javax.faces.context.FacesContext;

import org.ajax4jsf.application.AjaxStateManager;

/**
 * @author asmirnov
 *
 */
public class PortalStateManager extends AjaxStateManager {
    
    /**
     * 
     */
    public PortalStateManager(StateManager parentStateManager) {
	super(parentStateManager);
    }


    protected SerializedView saveStateInSession(FacesContext context,
    		Object treeStructure, Object state) {
    	PortletViewState windowState = PortletStateHolder.getInstance(context).getWindowState(context);
    	windowState.setTreeStructure(treeStructure);
    	windowState.setComponentsState(state);
//    	windowState.setViewRoot(context.getViewRoot());
    	String viewId = context.getViewRoot().getViewId();
		windowState.setViewId(viewId);
    	return new SerializedView(viewId,null);
    }
    
    protected Object[] restoreStateFromSession(FacesContext context,
    		String viewId, String renderKitId) {
    	Object[] state = new Object[2];
    	PortletViewState windowState = PortletStateHolder.getInstance(context).getWindowState(context);
    	state[0]=windowState.getTreeStructure();
    	state[1]=windowState.getComponentsState();
    	return state;
    }
    
    public boolean isSavingStateInClient(FacesContext context) {
    	// Client side view saving is not applicable for portal.
    	return false;
    }
    
    
}
