从炽烈的客户端访问jsf bean [英] accessing jsf bean from blazeds client

查看:39
本文介绍了从炽烈的客户端访问jsf bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

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

我对SpringFactory进行了一些更改,以便可以访问给定bean的当前实例:

first of all you have to implement the FlexFactory in your own Factory:
http://livedocs.adobe.com/blazeds/1/blazeds_devguide/factory_2.html

I change the SpringFactory a little bit so you can access to the current instance of the given 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文件夹)中,您必须注册此工厂:

in the service-config.xml (WEB-INF/flex folder) you have to register this factory:

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

然后,您必须像这样在remoting-config.xml中在目的地中注册工厂:

then you have to register the factory in your destination in the remoting-config.xml like this:

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

那么BeanFactory在做什么:
当您要从Flex到Java或jee应用程序访问每个远程对象时,可以在flex中声明一个远程对象,该对象的目标为"remoteService",该对象在remoting-config.xml中配置.当您通过调用服务器端方法从Flex到Java进行访问时,beanfactory将通过FlexContext获取请求来照管您在remoting-config.xml中声明的bean的当前实例:
HttpServletRequest hsr = FlexContext.getHttpRequest();

现在,您可以通过调用
hsr.getSession().getAttribute(beanName)
获得会话并使用beanName作为实例
这仅适用于应用程序和会话Bean,并且仅当jsf在BeanFactory想要访问Bean之前实例化Bean时才起作用.

当您要将swf文件与icefaces集成时,应使用ice:outputMedia-Tag设置播放器属性为"flash"

so what is this BeanFactory doing:
when you want to access per remote from flex to java or to the jee-application, you declare a remoteobject in flex with the destination "remoteService" which is configured in the remoting-config.xml. the moment you access from flex to java by calling a server-sided-method, the beanfactory looks after the current instance of the bean you declare in the remoting-config.xml by getting the Request over the FlexContext:
HttpServletRequest hsr = FlexContext.getHttpRequest();

now you get the session and with the beanName the instance by calling
hsr.getSession().getAttribute(beanName)

this is only working with application and session beans and only if jsf instantiated the bean before the BeanFactory want to access the bean...

when you want to integrate a swf-file with icefaces you should take the ice:outputMedia-Tag an set the player-attribute to "flash"

如果您使用eclipse开发jee应用程序,并且将tomcat集成到eclipse中,则可以将flex-project属性中的服务器根文件夹设置为tomcat文件夹(flex builder):
(很抱歉没有时间使它看起来不错;))

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

if you work with eclipse to develop your jee-application and you integrate the tomcat in eclipse you can set the server root folder in the properties of your flex-project to the tomcat folder (flex builder):
(Sorry not time for making this looks good ;) )

now you can start the tomcat server directly in eclipse and you can debug on flex and java too :)

希望这会有所帮助!

这篇关于从炽烈的客户端访问jsf bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆