Currently I’m working on building a page for inputting pricing data for different products my company handles. Pricing data is somewhat complicated, and so different forms are needed depending on what item new data is being entered for. Right now my strategy for dealing with this is to split the page into multiple forms, with an AJAX update on the next stage triggered when valid data is entered. Each form contains a ui:include pointed to a method on a controller bean, which returns a string pointing to a xhtml snippet with the appropriate form structure for the previously entered data.
<form id="stageOne"> Some content that triggers an ajax update of stageTwo </form>
<form id="stageTwo"> <ui:include src="#{controller.getStageTwo()"> </form>
And the backing bean method:
public String getStageTwo() {
switch (stageOneContent) {
case 1: return "/context-root/snippetName.xhtml";
case 2: return "/context-root/snippetName2.xhtml";
}
}
This solution feels somehow wrong to me, particularly having the controller method be responsible for knowing the exact location of all the xhtml snippets the calling page might use. I am still relatively new, and feel like I might be missing something. Is there a better way to handle this scenario?
How about just something like this?
You only need to rename
snippetName.xhtmltosnippetName1.xhtml.