从 blazeds 客户端访问 jsf bean

发布于 2024-08-23 14:55:55 字数 146 浏览 8 评论 0原文

  • 如何从 blazeds 客户端访问 jsf 托管 bean(例如,icefaces)?
  • 是否也可以共享相同的会话信息? (例如,如果我有一个带有 jsf/icefaces 组件和 swf 客户端的页面 - 他们可以使用相同的会话吗?)
  • How can I access a jsf managed bean (say, icefaces) from a blazeds client?
  • Will it be possible to share the same session information also ? (for eg, if I have a page with a jsf/icefaces component and a swf client - can they use the same session?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉栀 2024-08-30 14:55:55

首先,您必须在自己的工厂中实现 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应用程序访问每个远程时,您可以在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”,

如果您使用eclipse来开发jee应用程序并且将tomcat集成到eclipse中,您可以将 Flex 项目属性中的服务器根文件夹设置为 tomcat 文件夹(flex 构建器):
替代文本
(抱歉,没时间让这看起来不错;))

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

希望这会有所帮助!

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;
        }
    }
}}

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

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

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>

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"

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):
alt text
(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 :)

hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文