从jar文件加载的流中处于视图状态的相对视图 [英] Relative views in view-states within a flow that is loaded from a jar-file

查看:108
本文介绍了从jar文件加载的流中处于视图状态的相对视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用JSF的Spring Web Flow有一个疑问:如何让Spring Web Flow能够从罐子中的jar加载诸如 view ="pages/view.xhtml" 之类的相对视图. Tomcat Web应用程序的类路径?经过Google的一些研究后,我认为Web Flow不支持此功能.

I have a question regarding Spring Web Flow with JSF: How can I teach Spring Web Flow to be able to load relative views like view="pages/view.xhtml" from a jar in the classpath of a tomcat webapp? After some research via google I think, that Web Flow does not support this constellation out of the box.

也许有一些背景,以帮助理解我的问题: -在多个F​​lowRegistries中注册流(我通过实现一个自定义实现解决了这个问题,该实现在Spring Context中找到所有flowRegistries) -流可以作为文件资源驻留在类路径之外,也可以驻留在类路径中的jar中,即文件资源流位于 WEB-INF/conf 中的某个位置,并且它们在jar文件中的相同位置. -流定义中的视图相对于流定义文件进行了处理

Maybe some context, to help understanding my question: - Flows are registered in multiple FlowRegistries (I solved this problem by implementing a custom implementation, which finds all flowRegistries in the Spring Context) - Flows can reside either as file resource outside the classpath or within a jar in the classpath, i.e. file ressource flows are located somewhere in WEB-INF/conf and they are at the same position within the jar files. - Views in the flow definitions are adressed relatively to the flow-definition-file

现在您可能会问一个问题,为什么我们有两个星座,流可以驻留在哪里.目前,我们正在尝试从一大堆webapp模块中提取模块,这些模块包含属于某个域的所有功能.该方法是将所有与之相关的工件捆绑在一个项目中,该项目可以以jar的形式构建,然后添加到webapp中.

Now you might ask the question why we have both constellations, where the flows can reside. At the moment we are trying to extract from a big bunch of a webapp modules that contain all functionality belonging to a certain domain. The approach is to bundle all artifacts relevant there within a single project that can be built as jar and added to the webapp then.

虽然在不知道我们的配置文件位于哪里的情况下为每个jar加载Spring Bean没问题,但是Web Flow会引起一些问题.

While it is no problem to load the Spring beans for each jar without knowing where our configuration files are located, the Web Flow causes some problems.

第一个问题是,flowRegistry是一个整体,如果不事先做一些事情就无法将其拆分.此问题通过自定义流注册表解决.

The first problem was, that the flowRegistry is a monolith that cannot be split without doing something before hand. This problem is solved by a custom flow registry.

但是现在我遇到第二个问题:在视图状态中,我们相对于流定义引用页面,如

But now I came to a second problem: Within view states we reference the pages relatively to the flow definition, like described in the documentation:

<view-state id="some-id" view="pages/somepage.xhtml"> ... </view-state>

现在,当我进入这种视图状态时,Web流会引发异常,这表明不支持这种方式:

Now, when I enter such a view state, web flow throws an exception, which tells me that this way is not supported:

A ContextResource is required to get relative view paths within this context;
the resource was ...

谷歌搜索提出了这种可能的解决方案: 罐中Webflow的解决方法

Googling around brought up this possible solution: workaround for webflows in jars

但是此解决方法无法正常工作,因为我的多个流注册表都存在问题.

But this workaround is not working as it has a problem with my multiple flow registries.

另一种选择可能是不将所有东西都放进罐子里,但是我不确定这是否是一个更好的主意.可能具有可以从jar中的类路径加载的所有内容,而其余的都可以作为已定义结构中的纯文件加载.

Another option might be to not put everything into the jar, but I am not sure if that is a better idea. Likely have everything that can be loaded from classpath in the jar and the rest as pure files in a defined structure.

有什么想法吗?非常感谢您的努力和提示.

Any ideas? Thank you very much for your efforts and hints.

推荐答案

经过数小时的尝试和调试应用程序以解决问题的目的,我自己找到了一个略有不同的解决方案.

I found a slight different solution by myself after several hours of trying and debugging my application on how to accomplish the goal of the question.

  1. 要更改的第一件事是由于servlet API规范的变化而从Tomcat 6升级到Tomcat 7,这使我能够通过稍作修改来解决我的问题
  2. 我从视图状态中的相对引用切换为绝对寻址
  3. 我更改了jar文件的目录结构以适应较新的servlet API:JSF或Spring Webflow所需的所有文件资源都必须放置在META-INF/resources中(请参阅
  1. first thing to change was to advance from Tomcat 6 to Tomcat 7 because of a change in the servlet API spec, that enabled me to solve my problem with slight modifications
  2. I switched from relative referencing in view states to absolute addressing
  3. I changed the directory structure of my jar file to fit to the newer servlet API: all file resources needed for JSF or Spring Webflow needed to be placed in META-INF/resources (see Javadoc of ServletContext look for the method getResource, it specifies what I needed)

这三个步骤使我能够将Web流及其资源完全打包到jar文件中.

These three steps enabled me to completely pack webflows and their resources in jar-files.

这篇关于从jar文件加载的流中处于视图状态的相对视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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