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>

但在浏览器中,我看到以下内容:

这是一个测试,这是来自 sub main
这是来自 body

代替:

这是一个测试,这是来自 sub main
这是来自 sub header 组件
这是来自 body

最重要的是标题显示为:

“$标题”。

请任何人都可以给我一个关于我做错了什么的线索?

4

1 回答 1

1

我注意到subheader是在sub_main.jsp定义的主体组件中定义的,我认为您不能像这样嵌套组件标签。您可能想尝试对子标题使用 EL 表达式(使用:${subheader})。

在渲染布局组件的内容时,最好始终使用 EL 表达式而不是布局组件标签,并且只使用布局组件来定义布局。嵌套在布局定义中时,您不能使用布局组件进行渲染(布局组件的这种双重使用是库的设计错误,在我看来会导致不必要的混淆)。

另请参阅 Stripes 官方文档的嵌套布局部分。

于 2011-06-24T09:56:02.323 回答