Hi,

the easiest solution for using view configs in h:link or h:button is a application scoped bean with getters for the config:

@Named @ApplicationScoped
public class ViewConfigProvider {
  public Class<? extends ViewConfig> getHome() {
    return Pages.Home.class;
  }
}

Then you can use them without having to create any other beans:

<h:button value="Home" outcome="#{viewConfigProvider.home}" />

Best regards
Michael


Am 16.10.2011 15:32, schrieb Steven Rudolf:
Hello @all,

I have another question concerning the typesafe navigation of CODI.

I define my "view configuration" in several Pages-classes:

@Page(navigation = Page.NavigationMode.REDIRECT)
public interface Pages extends ViewConfig
{
@Page
@UseCaseName("A")
@PageBean(UseCaseBeanA.class)
public class UseCaseA implements Pages {}

// .. some more pages
}

If I want to use this typesafe navigation in my view I have the problem,
that these configuration classes are not resolvable by the EL. So for
every PageBean I can implement a getPage-method in the PageBeans like this:

@Named
@ViewAccessScoped
public class UseCaseBeanA
{
protected Class<? extends Pages> getPage()
{
return Pages.UseCaseA.class;
}

// .. some more logic
}

Now I can use it as an outcome for buttons:

<h:button value="Use Case A" outcome="#{useCaseBeanA.page}" />

So I have two problems:
1.) I think this design is error prone because of its duplicate
configuration: In the ViewConfig I define the @PageBean for a @Page and
in the getPage-method of the PageBean I define the Page for itself.
2.) If I want to link to another page (via h:link or h:button), I have
to do it like I described before. If I do so, the Bean for the linked
use case will be instantiated immediately on the page which links to it.
For one or two pages it would be no problem but if I want to do it in
the menu of my application every use case bean will be initialized
directly on the first page (and the viewAccess-beans or
conversation-beans will never be cleaned up because the menu have a
reference to them everytime).

So is there an approach where I can use the ViewConfig directly in the
links or buttons in views?

Sincerely,
Steve



Reply via email to