动态用户界面:包括 [英] Dynamic ui:include

查看:94
本文介绍了动态用户界面:包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个问题:
https://stackoverflow.com/questions/8589315/jsf2-dynamic-template

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

但是BalusC和casperOne告诉我我写的不好,所以我试图更好地解释我的问题.
如我所写,我的项目在以下结构中:

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:

    在Web根目录3个xhtml页面中的
  • :索引,包含和欢迎;
  • 所有其他xhtml页面在WEB-INF的子文件夹jsf中.
  • in web root 3 xhtml pages: index, include and welcome;
  • all others xhtml pages in a subfolder into WEB-INF called jsf.

我认为这是一件好事,但是我使用netbeans的向导来自实体类的新JSF页面..."创建了所有页面,并且为了在此向导中使用此结构,我无法直接链接xhtml保存到jsf forlder中的页面(由向导创建),并且我创建了include.xhtml并修改了用于重定向到该页面的所有方法,正如我将在后面解释的那样,include.xhtml仅包含以下代码:

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>

正如我所说,我修改了所有方法以在LogicBean中调用包含setPageIncluded的操作方法,并返回"include.xhtml",如下所示:
PageController.java:

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:

LogicBean.java:

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

现在此代码可以很好地运行,并且我可以导航到所有页面.
只是一个问题,Bean LogicBean存储在会话中!
这意味着如果我试图同时打开一个新窗口来浏览项目的不同部分,那么我将无法执行此操作,因为LogicBean只能包含pageInclude!的单个值!

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!

我尝试使用ViewScope,但是或者我不了解它是如何工作的,在这种情况下,它是没有用的,或者我弄错了某些东西,并且它无法正常工作!
有人可以帮助我吗?

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?

我发现这个问题似乎可以帮助我: 动态ui:是否包含el-expression?
但我不知道它是否有帮助,以及如何修改c:forEach和操作方法以用于我的情况!

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!

推荐答案

您使用JEE6认证的服务器,因此可以使用CDI进行bean管理.有一个名为MyFaces CODI的CDI扩展库,其中包含Window作用域捆绑包,您可以使用它来对bean进行作用域管理,而不是使用会话作用域.这将解决您的bean范围问题.

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.

主页- http://myfaces.apache.org/extensions/cdi/

这篇关于动态用户界面:包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆