Is it possible to place the JSF flow folder somewhere else than the root of the application?

StackOverflow https://stackoverflow.com/questions/23342150

  •  11-07-2023
  •  | 
  •  

Question

Is it possible to place the JSF flow folder somewhere else than the root of the application like... in WEB-INF folder? Or somehow to forbid direct access to the pages in it?

Was it helpful?

Solution

I solved this one myself.

A JSF flow definition can be done in 2 ways:

  • with configuration file: flowname-flow.xml
  • with configuration class: flowname.java

The first one can only define a flow-name, with the location defaulting to the root folder.

The second can define a location deeper in your folder structure.

Configuration file example: testflow.flow.xml

Only the id="testFlow" can be added to the definition, and not the path. This defaults to testFlow/testFlow.xhtml for the first page.

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
    <flow-definition id="testFlow">
        <flow-return id="returnFromTestFlow">
            <from-outcome>#{testFlow.returnValue}</from-outcome>
        </flow-return>
    </flow-definition>
</faces-config>

Configuration class example: TestFlow.java

Add the fully qualified path to the view node within this flow.

public class TestFlow implements Serializable {

    private static final long serialVersionUID = 1L;

    @Produces
    @FlowDefinition
    public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {

        String flowId = "testFlow";
        flowBuilder.id("", flowId);
        flowBuilder.viewNode(flowId, 
                "/other/location/flow/" + flowId + ".xhtml").
                markAsStartNode();
        flowBuilder.viewNode("testFlow2", "/other/location/flow/testFlow2.xhtml");
        flowBuilder.viewNode("testFlow3", "/other/location/flow/testFlow3.xhtml");
        ...

That's all folks!

OTHER TIPS

You can always create folders inside the root folder to store your pages. To restrict client access, for example, you can put all admin-related pages into a folder called admin. Then, you can restrict user access by using the account type after they've logged in. This can be done easily using a Servlet. One thing to note is that you should never put normal pages and template clients inside the WEB-INF folder.

For your information:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top