1

I wrote this question:
https://stackoverflow.com/questions/8589315/jsf2-dynamic-template

but BalusC and casperOne told that i wrote it bad so I try to explain better my problem.
As I wrote, I have my project in this structure:

  • in web root 3 xhtml pages: index, include and welcome;
  • all others xhtml pages in a subfolder into WEB-INF called jsf.

I suppose that it is a good thing, but I create all pages using the netbeans' wizard "New JSF Pages From Entity Classes..." and for using this structure with this wizard, I can't link directly the xhtml pages saved into jsf forlder, as created by wizard, and I created the include.xhtml and modify all methods for redirecting to this page, as I will explain later, the include.xhtml contains only this code:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:h="http://java.sun.com/jsf/html">


   <h:head>
   </h:head>
   <h:body>
      Utente connesso:<h:outputText value="#{userBean.cognome}"/>

      <h:outputText value="#{userBean.nome}"/>
      <br/&gr;

      <ui:include src="#{logicBean.pageIncluded}"/>

   </h:body>
</html>

As I said, I modified all methods to call action method in LogicBean that contains the setPageIncluded and return "include.xhtml" something like this:
PageController.java:

public void prepareList() {
    recreateModel();
    LogicBean l = (LogicBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("logicBean");
    l.action(url+"List.xhtml");
}

LogicBean.java:

public String action(String value) {
   setPageIncluded(value);
   return "include";
}

Now this code works quite well and I can navigate from to all pages.
There is only a problem, the bean LogicBean is stored into the session!
This means that if I tried to open a new windows for navigate different part of the project in the same time I can't do that because LogicBean can contains only a single value of pageInclude!

I tried to use the ViewScope but or I don't understand how it works, and in this case it isn't useful, or I wrong something and it doesn't work properly!
Some one can help me?

I found this question that seems could help me: dynamic ui:include with el-expression?
but I don't know if it could help and how modify the c:forEach and action method for using it for my situation!

I hope that this time I explain better my problem and, if it so, I thank you for help!

4
  • For what I read here you would like to have a state per browser tag, not per browser, right? Jan 10, 2012 at 13:21
  • @ Adrian Mitev : if you for "state" mean something like session but not shared between browser's windows or browser's tab,yes you're right! Jan 10, 2012 at 14:03
  • What app server are you using? Jan 11, 2012 at 9:10
  • @ Adrian Mitev : for now Glassfish 3.1, but it could change for JBoss (i don't know which version) why? it could help me? Jan 11, 2012 at 10:02

1 Answer 1

2

You use a JEE6 certified server, so you can use CDI for bean management. There is a CDI extension library called MyFaces CODI that has a Window scope bundle in it and you can use it to scope your beans instead of using session scope. This will solve your problem with the bean scoping.

Home page - http://myfaces.apache.org/extensions/cdi/

1
  • 1
    You have to annotate your bean with @WindowScoped when using CODI Jan 11, 2012 at 15:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.