2011-06-24 57 views
1

我遇到了條紋布局的一些問題。我會給一個測試案例在這裏:條紋中的嵌套佈局問題

主要佈局(main.jsp中):

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 

<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %> 

<s:layout-definition>  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>{$title}</title> 
</head> 
<body> 
    <s:layout-component name="body"/> 
</body> 
</html> 

</s:layout-definition> 

其延伸的主管(sub_main.jsp)子佈局:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 

<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %> 

<s:layout-definition> 
    <s:layout-render name="/WEB-INF/jsp/common/main.jsp" title="${title}"> 
     <s:layout-component name="body"> 
      This is a test and this is from sub main 
      <div style="color: red; font-size: 5em;"> 
       <s:layout-component name="subheader"/> 
      </div> 
      ${body}  
     </s:layout-component> 
    </s:layout-render> 
</s:layout-definition>  

現在我下面的代碼使用子主要佈局(test.jsp的):

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 

<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %> 

<s:layout-render name="/WEB-INF/jsp/common/sub_main.jsp" title="Test Page"> 
    <s:layout-component name="subheader"> 
     This is from the sub header component 
    </s:layout-component> 
    <s:layout-component name="body"> 
     This is from body 
    </s:layout-component> 
</s:layout-render> 

但在瀏覽器中我看到以下內容:

這是一個測試,這是從子主
這是從身體

代替:

這是一個測試,這是從子主
這來自子標頭組件
這是來自機構

以上所有標題顯示爲:

「$ title」。

請任何機構可以給我一個關於我在做什麼錯誤的線索?

+0

@Keoki Zee,但這是特定於Stripes框架,不是嗎? – kaushik

+0

它是?我的道歉,我會重新標記。 – 2011-06-24 07:27:16

+0

@Kdeveloper,你有什麼想法嗎? – kaushik

回答

1

我注意到,子頭sub_main.jsp defenition的組件中,定義,我不認爲你可以嵌套組件標籤這樣。您可能想嘗試使用EL表達式代替subheader(使用:$ {subheader})。

在渲染布局組件的內容時,最好始終使用EL表達式而不是佈局組件標籤,並且只使用佈局組件來定義佈局。嵌套在佈局定義中時,不能使用佈局組件進行渲染(佈局組件的這種雙重用法是庫的設計錯誤,並導致我認爲不必要的混淆)。

另請參閱官方Stripes文檔的Nested Layouts部分。

+0

我看過那篇文章,並根據這個做了修改。現在一切正常,除了標題。有沒有什麼黑客? – kaushik

+0

您還應該將標題添加到sub_main.jsp中的佈局渲染: Kdeveloper

+0

我已編輯如你所建議的那樣(我也在這個問題中編輯過)。沒用! – kaushik