views:

218

answers:

3

I've got a web application that I need to be able to configure parts of from a JSF page. So for example, imagine my application was split into several smaller parts each with a folder/file structure like below:

/partname
    /config
        config.xhtml
    /template
        generaltemplate.xhtml
    search.xhtml
    results.xhtml

Search.xhtml & results.xhtml both use the template file, generaltemplate.xhtml. This generaltemplate has an to include the contents of config.xhtml. The plan is to put all shared configuration into this page so that the applications can access it. But I'm having trouble doing this.

If i create the variables using <c:set> in the config.xhtml, then they seem to only be accessible from that config page. Previously I would have just changed the scope on <c:set> to request and ny problem would be solved. But as JSF works in a different way, I know that scope in this case is useless.

Does anyone have any suggestions for how I am going to be able to create all my config in this one page and then be able to access it throughout my application?

This app is written using Seam so using something from Seam could be an option.

A: 

Seam is a Model-View-Controller (MVC) framework. The view is implemented using JSF pages. Configuration is part of the model and should not be put in pages.

To implemented proper layering I suggest you put your configuration in some kind of globally accessible bean (instantiated by Seam, probably populated from a .properties file) which you reference in your JSF pages.

Kees de Kooter
A: 

I don't know how much refactoring would be involved but you could create a configuration bean which would be scoped appropriately, then use the c:set tags to set your configuration bean. Then, later on in your page, you can use the configuration bean rather than directly accessing the variables.

Drew
A: 

Assuming you can use facelets, for the c:set issue:

In your template:

...
<html ...
    xmlns:ui="http://java.sun.com/jsf/facelets"
...
<body>
    <ui:param name="testParam" value="Test" />

    <ui:insert name="test">
    </ui:insert>
...

In this case the value of the ui:param can be used as a variable to be used in pages using the template.

Pages using template:

...
<html ...
    xmlns:ui="http://java.sun.com/jsf/facelets"
...
<body>
<ui:composition template="/WEB-INF/templates/template.xhtml">
    <ui:define name="test">
<h:outputText value="#{testParam}" />
...

With that said, I can think of a very few instances where this should actually be used. Unless your hands are tied, values should come from application/session scoped beans.

Edit:

I apologize for not double checking earlier, as I was extremely busy and used the first answer that came to mind, however, I verified using a c:set in place of the ui:param would work equally as well using the previous defined set up. So, in the template, you could have instead of . This would mean you would also have to include xmlns:c="http://java.sun.com/jstl/core", which I am sure you already have.

codeape