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

com.github.persapiens.jsfboot.annotations.ViewScope Maven / Gradle / Ivy

//
// Copyright described at LICENSE.txt
//
package com.github.persapiens.jsfboot.annotations;

import java.util.Map;

import javax.faces.context.FacesContext;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

/**
 * Implementation of view scope
 */
public class ViewScope implements Scope
{
    @Override
    public Object get( String name, ObjectFactory objectFactory )
    {
        Map viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();

        if ( viewMap.containsKey( name ) )
        {
            return viewMap.get( name );
        }
        else
        {
            Object object = objectFactory.getObject();
            viewMap.put( name, object );

            return object;
        }
    }

    @Override
    public Object remove( String name )
    {
        return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove( name );
    }

    @Override
    public String getConversationId()
    {
        return null;
    }

    @Override
    public void registerDestructionCallback( String name, Runnable callback )
    {
        //Not supported
    }

    @Override
    public Object resolveContextualObject( String key )
    {
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy