---
title: "jsf中怎样动态改变include的src地址"
author: "fourfire"
date: "2007-05-16T15:53:24Z"
tags: []
categories: ["企业架构"]
slug: "jsf-include-src"
draft: false
lastmod: "2007-05-16T15:53:24Z"
id: 80356
url: "https://fourfire.iteye.com/blog/80356"
---

我想根据一个bean里的url，动态改变include中的src，试了几次都不行。

java 代码

 

01. &lt;body style="margin:0;" bgcolor="#f4f4ea"&gt;
02. &lt;f:view&gt;
03. &lt;h:form id="form"&gt;
04. &lt;div &gt;
05. &lt;e:include id="moduleTree" src="system/module\_tree.jsp"/&gt;
06. &lt;/div&gt;
07. &lt;div &gt;
08. &lt;e:include id="mainPane" src="#{controlBean.mainPanePath}"/&gt;
09. &lt;/div&gt;
10. &lt;/h:form&gt;
11. &lt;/f:view&gt;

java 代码

 

01. public class ControlBean {
02. private String mainPanePath="org\_manager/context.jsp";
03. /\**
04. * @return the mainPanePath
05. \*/
06. public String getMainPanePath() {
07. return mainPanePath;
08. }
09. /\**
10. * @param mainPanePath the mainPanePath to set
11. \*/
12. public void setMainPanePath(String mainPanePath) {
13. this.mainPanePath = mainPanePath;
14. }
15. public void setPath(ActionEvent event) {
16. Module cell = ((Module) ((Tree) event.getSource()).getSelection());
17. if (cell.getUrl() != null && cell.getUrl().trim().length() &gt; 0) {
18. this.setMainPanePath(cell.getUrl());
19. }
20. }
21. }

tree

java 代码

 

01. &lt;e:tree id="tree-basic" model="#{moduleTreeModelBean.treeModel}"
02. rootExpanded="false"
03. onselection="#{controlBean.setPath}"
04. cellStyle="normalTreeCell"
05. hoverStyle="blueTreeCell"
06. selectedStyle="whiteTreeCell" preloadDepth="1"&gt;
07. &lt;e:treecell value="#{NODE.name}"
08. styleClass="treeCellBold"
09. icon="#{NODE.leaf?'/images/draft.jpg':'/images/trash.jpg'}"/&gt;
10. &lt;/e:tree&gt;

树上点击链接，改变另一个include的url