On 7/22/05, Duncan Krebs <[EMAIL PROTECTED]> wrote:
>
>
>
> Hi,
>
> I'm trying to integrate MyFaces into an in-house web framework and have a
> couple of grey areas that I'm trying to think through.
>
>
>
> Building JSF pages without JSP and taglibs.
>
> Lets say I want to dynamically build a JSF form and the controls that should
> be included in the form are defined at runtime, instead of a typical java
> bean. The idea I have is to dynamically build a JSF form all in code and
> then be able to reuse it throughout the life of the form. The first thing I
> need to figure out is what API would I use to directly instantiate stuff
> like, <h:form><f:inputText> etc. directly in code without using the
> associated Taglibs. Is this possible?
One approach you might consider is to just build up the component tree
in a JSF view programmatically, using the child access APIs that are
built directly into the components. Something like this snippet:
FacesContext context = ...;
UIViewRoot viewRoot = new UIViewRoot();
viewRoot.setViewId("/foo");
UIForm form = new UIForm();
form.setId("form1");
viewRoot.getChildren().add(form);
UIOutput label1 = new UIOutput();
label1.setValue("Username:");
form.getChildren().add(label1);
UIInput username = new UIInput();
username.setId("username");
username.setValueBinding("value", ...);
form.getChildren().add(username);
If you look at what an IDE for building Swing dialogs does to persist
the choices you make, it will often be generated code that looks a lot
like this.
Another option would be to use something like the Clay plug-in in
Shale, which (among other things) lets you compose the overall view
out of reusable subtrees of components defined in an XML structure (or
with a Tapestry-like separation of component definitions from the raw
HTML markup).
>
>
>
> Using JSF behind another controller.
>
> I currently have a controller that is responsible for serving all requests
> and its specific to an existing framework that I still want to use. However
> I also want to use JSF!. The way I see myself wanting to integrate this is
> like this: I have my overall page broken down into 4 sections, for the sake
> of this example lets say each section is its own jsp page. Now lets say that
> I know one of these pages is a JSF page, I would usually get a
> RequestDispatcher off the ServletContext to get the jsp output but in this
> case it has to go through the JSF controller. What could I do? Or more
> generally is it even possible to put the JSF controller behind another
> controller?
The closest I have come to this is putting JSF's in *front* of the
other controller, instead of behind it. That's the way that the
Struts-Faces integration library works. The idea is to let JSF handle
all the events that are typically UI related by itself (open a tree
node and redisplay, for example), and then map application level
events (like a submit button being pressed) to the corresponding
mechanism in the framework behind it.
That being said, any architecture like this with competing front
controllers is going to end up being clumsy, and will always leave you
with decisions about which framework's facilities to use for
overlapping functionality (like navigation or validation, for
example). This is why I'm currently focused on Shale instead -- it
assumes JSF exists, and uses the extension points built in to JSF's
lifecycle to add any other facilities I want. You might see if you
can link your existing controller's facilities that way instead.
>
>
>
> Any comments or thoughts would be greatly appreciated as I'm having a tough
> time finding my answers on the web.
>
Craig McClanahan