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

落花浮王杯 提交于 2019-12-07 18:04:48

问题


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.

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

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.

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.

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>

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 ...

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.

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.


回答1:


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
  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)

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



来源:https://stackoverflow.com/questions/9618483/relative-views-in-view-states-within-a-flow-that-is-loaded-from-a-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!