Search code examples
jsfdirectoryfaces-flow

How to place a JSF flow in a subfolder?


I'm introducing a JSF Faces flow into my application. This works, following the oracle documentation. But, only in the root folder.

Is it possible to place the JSF flow folder in a sub folder, else that root?

I can't get this working. That's all folks!


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!