java - 条纹的嵌套布局问题

标签 java jakarta-ee stripes

我在条纹布局方面遇到一些问题。我将在这里给出一个测试用例:

主布局(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>

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

This is a test and this is from sub main
This is from body

而不是:

This is a test and this is from sub main
This is from the sub header component
This is from body

以上标题显示为:

"$title".

请问任何人都可以告诉我我做错了什么吗?

最佳答案

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

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

另请参阅Nested Layouts官方 Stripes 文档部分。

关于java - 条纹的嵌套布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6464545/

相关文章:

java - Flyway 检查数据库是否存在并在 Java 中建立基线

java - 在哪里寻找 Spring XML namespace 配置的确切效果?

java - 从表示层调用服务层

java - 使用 J2EE 和 Jboss 每次测试后回滚

Java/JSP 图片上传。这些图像文件放在哪里?

jsp - 如何制作 fmt :setLocale work on fmt:formatNumber with only language code in JSP?

java - 您可以将 Java EE 框架与 Google App Engine 一起使用吗?

java - Activity 泄漏了最初添加到此处的窗口(当登录数据错误时)

Java 如何比较 XML 数据与文件扩展名

java - 浏览器特定的 session 管理