All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sakaiproject.jsf2.component.FlowStateComponent Maven / Gradle / Ivy

Go to download

This is the Maven project for the custom JSF 2 widgets. The widgets and the resources projects are closely tied together. These widgets will be deployed as a jar file containing Sakai JSF 2 widgets (components). Web applications can include this jar in order to use the Sakai JSF 2 widgets in a JSF tool.

There is a newer version: 23.3
Show newest version
/**
 * Copyright (c) 2003-2021 The Apereo Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             http://opensource.org/licenses/ecl2
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sakaiproject.jsf2.component;

import java.io.IOException;

import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

import lombok.extern.slf4j.Slf4j;

import org.sakaiproject.jsf2.model.PhaseAware;

/**
 * This JSF UI component lets backing beans track the request life cycle and
 * save their state within the component tree itself. (These two aspects could
 * be separated with a "saveState" Boolean attribute if we ever need to let
 * a session-scoped bean track the request life cycle.)
 *
 * Like the MyFaces x:saveState tag, this passes the bean's state from request
 * to request without use of session scope. That in turn enables request-thread
 * functionality such as "what if?" scenarios and multiple active
 * application views from a single session.
 *
 * 

* Usage: * * <sakaix:flowState bean="#{phaseAwareBean}" /> * * should be placed in the JSP file before any other bean references are made. * *

* The bean must implement the PhaseAware interface and be serializable. * Any non-transient fields in the bean will be saved and restored from this component. */ @Slf4j public class FlowStateComponent extends UIComponentBase { public static final String COMPONENT_TYPE = "org.sakaiproject.FlowState"; public PhaseAware getBean() { PhaseAware bean = null; ValueBinding vb = getValueBinding("bean"); if (vb != null) { bean = (PhaseAware) vb.getValue(getFacesContext()); } if (log.isDebugEnabled()) log.debug("getBean " + bean); return bean; } public Object saveState(FacesContext context) { PhaseAware bean = getBean(); if (log.isDebugEnabled()) log.debug("saveState " + bean); Object values[] = new Object[2]; values[0] = super.saveState(context); values[1] = bean; return ((Object)values); } public void restoreState(FacesContext context, Object state) { if (log.isDebugEnabled()) log.debug("restoreState " + state); Object values[] = (Object[])state; super.restoreState(context, values[0]); PhaseAware bean = (PhaseAware)values[1]; ValueBinding vb = getValueBinding("bean"); if (vb != null) { vb.setValue(context, bean); } } public void processRestoreState(FacesContext context, Object state) { if (log.isDebugEnabled()) log.debug("processRestoreState " + getBean()); super.processRestoreState(context, state); } public void processDecodes(FacesContext context) { if (log.isDebugEnabled()) log.debug("processDecodes " + getBean()); super.processDecodes(context); } public void processValidators(FacesContext context) { PhaseAware bean = getBean(); if (log.isDebugEnabled()) log.debug("processValidators " + bean); super.processValidators(context); bean.endProcessValidators(); } public void processUpdates(FacesContext context) { PhaseAware bean = getBean(); if (log.isDebugEnabled()) log.debug("processUpdates " + bean); super.processUpdates(context); bean.endProcessUpdates(); } public void encodeBegin(FacesContext context) throws IOException { PhaseAware bean = getBean(); if (log.isDebugEnabled()) log.debug("encodeBegin " + bean); bean.startRenderResponse(); super.encodeBegin(context); } public String getFamily() { if (log.isDebugEnabled()) log.debug("getFamily " + getBean()); return "javax.faces.Data"; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy