简体   繁体   English

从jar文件加载的流中的视图状态中的相对视图

[英]Relative views in view-states within a flow that is loaded from a jar-file

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? 我有一个关于使用JSF的Spring Web Flow的问题:我如何教Spring Web Flow能够从tomcat webapp的类路径中的jar加载view =“pages / view.xhtml”之类的相对视图? After some research via google I think, that Web Flow does not support this constellation out of the box. 经过谷歌的一些研究后我认为,Web Flow并不支持这个开箱即用的星座。

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, ie file ressource flows are located somewhere in WEB-INF/conf and they are at the same position within the jar files. 也许是一些上下文,以帮助理解我的问题: - 流程在多个FlowRegistries中注册(我通过实现自定义实现解决了这个问题,该实现在Spring上下文中查找所有flowRegistries) - 流可以作为文件资源驻留在类路径之外或者在类路径中的jar,即文件资源流位于WEB-INF / conf中的某个位置,它们位于jar文件中的相同位置。 - Views in the flow definitions are adressed relatively to the flow-definition-file - 流定义中的视图相对于流定义文件进行了处理

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. 目前,我们正在尝试从包含属于某个域的所有功能的大量webapp模块中提取。 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并随后添加到webapp中。

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. 虽然在不知道配置文件所在位置的情况下为每个jar加载Spring bean没有问题,但Web Flow会导致一些问题。

The first problem was, that the flowRegistry is a monolith that cannot be split without doing something before hand. 第一个问题是,flowRegistry是一个整体,如果不事先做一些事情就无法拆分。 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>

Now, when I enter such a view state, web flow throws an exception, which tells me that this way is not supported: 现在,当我进入这样的视图状态时,Web流会抛出一个异常,告诉我这种方式不受支持:

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

Googling around brought up this possible solution: workaround for webflows in jars 谷歌搜索提出了这个可能的解决方案: 罐子里的webflows的解决方法

But this workaround is not working as it has a problem with my multiple flow registries. 但是这种解决方法不起作用,因为它对我的多个流注册表有问题。

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. 可能拥有可以从jar中的类路径加载的所有内容,其余部分作为定义结构中的纯文件。

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. 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 要改变的第一件事是从Tomcat 6升级到Tomcat 7,因为servlet API规范发生了变化,这使我能够稍微修改一下来解决我的问题
  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) 我更改了我的jar文件的目录结构以适应更新的servlet API:需要将JSF或Spring Webflow所需的所有文件资源放在META-INF / resources中(参见ServletContext的Javadoc查找方法getResource,它指定了什么我需要)

These three steps enabled me to completely pack webflows and their resources in jar-files. 这三个步骤使我能够将jarflow及其资源完全打包在jar文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM