从blazeds客户端访问jsf bean

时间:2010-03-02 07:41:16

标签: jsf blazeds

  • 如何从blazeds客户端访问jsf托管bean(比如icefaces)?
  • 是否可以共享相同的会话信息? (例如,如果我有一个带有jsf / icefaces组件和swf客户端的页面 - 他们可以使用相同的会话吗?)

1 个答案:

答案 0 :(得分:0)

首先,您必须在自己的工厂中实施FlexFactory:
http://livedocs.adobe.com/blazeds/1/blazeds_devguide/factory_2.html

我稍微更改了SpringFactory,以便您可以访问给定bean的当前实例:

public class BeanFactory implements FlexFactory {

private static final String SOURCE = "source";

public void initialize(String id, ConfigMap configMap) {}

public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {
    BeanFactoryInstance instance = new BeanFactoryInstance(this, id, properties);
    instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));
    return instance;
}

public Object lookup(FactoryInstance inst) {
    BeanFactoryInstance factoryInstance = (BeanFactoryInstance) inst;
    return factoryInstance.lookup();
} 

static class BeanFactoryInstance extends FactoryInstance {
    BeanFactoryInstance(BeanFactory factory, String id, ConfigMap properties) {
        super(factory, id, properties);
    }

    public String toString() {
        return "BeanFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope();
    }

    public Object lookup() {
        HttpServletRequest hsr = FlexContext.getHttpRequest();
        String beanName = getSource();

        try
        {
            Object o = hsr.getSession().getAttribute(beanName);
            return o;
        }
        catch (Exception e)
        {
            ServiceException se = new ServiceException();
            String msg = "Java Bean '" + beanName + "' does not exist.";
            se.setMessage(msg);
            se.setRootCause(e);
            se.setDetails(msg);
            se.setCode("Server.Processing");
            throw se;
        }
    }
}}

在service-config.xml(WEB-INF / flex文件夹)中,您必须注册此工厂:

<factories>
    <factory id="beanFactory" class="packageName.BeanFactory"/>
</factories>

然后你必须在remoting-config.xml中的目的地注册工厂,如下所示:

<destination id="remoteService">
        <properties>
            <factory>beanFactory</factory>
            <source>beanName</source>
            <scope>session</scope>
        </properties>
 </destination>

那么这个BeanFactory在做什么:
当你想要从flex到java或jee-application访问每个远程时,你在flex中声明一个远程对象,其目标是“remoteService”,它在remoting-config.xml中配置。通过调用服务器端方法从flex访问java的那一刻,beanfactory通过获取FlexContext上的Request来查看你在remoting-config.xml中声明的bean的当前实例:
HttpServletRequest hsr = FlexContext.getHttpRequest();

现在通过调用
hsr.getSession()获取会话并使用beanName实例.getAttribute(beanName)

这只适用于应用程序和会话bean,并且只有在BeanFactory想要访问bean之前jsf实例化bean ...
当你想要将一个swf文件与icefaces集成时,你应该采取冰:outputMedia-Tag将player-attribute设置为“flash”

如果您使用eclipse开发jee-application并在eclipse中集成tomcat,则可以将flex-project属性中的服务器根文件夹设置为tomcat文件夹(flex builder):
alt text (抱歉没时间让这看起来不错;))

现在你可以直接在eclipse中启动tomcat服务器了,你也可以在flex和java上调试:)

希望这有帮助!