【发布时间】:2012-05-18 18:16:17
【问题描述】:
我是 struts 新手,如何在 struts2 jsp 页面中装饰动作消息和动作错误?
<s:actionmessage/>
<s:actionerror/>
【问题讨论】:
-
你可以使用简单的主题,你可以应用你想要的css样式。
标签: struts2
我是 struts 新手,如何在 struts2 jsp 页面中装饰动作消息和动作错误?
<s:actionmessage/>
<s:actionerror/>
【问题讨论】:
标签: struts2
您可以使用 css 样式以及 jquery 主题属性来装饰您的操作错误和操作消息。
<div class="error"><s:actionerror theme="jquery"/></div>
<div class="message"><s:actionmessage theme="jquery"/></div>
.message li
{
font-size: 14px;
color: #000066;
text-align: center;
list-style: none;
font-family: Trebuchet MS,sans-serif,inherit,Arial,monospace;
}
.error li
{
font-size: 14px;
color: #990000;
text-align: center;
list-style: none;
padding-right: 50px;
}
【讨论】:
您好,如果您希望使用此代码来装饰您的操作消息和错误消息,我正在为您的问题发布解决方案
<div id="sucessMsg"><s:actionerror /></div>
sucessMsg is the class that is using by struts2 internally so override this so kindly put the below code inside the css
#sucessMsg {
text-align: center;
font-weight: bolder;
color: #6A2A91;
list-style: none;
margin: auto;
}
#errorMsg {
text-align: center;
font-weight: bolder;
color: red;
list-style: none;
width: 350px;
margin: auto;
}
【讨论】:
您应该在呈现后查看 HTML 源代码,以查看 Struts 用于呈现消息的 CSS 类和 HTML 结构。您也可以查看模板文件。
默认情况下,struts 会按如下方式呈现每个动作消息:
<ul>
<li><span class="actionMessage">${message}</span></li>
</ul>
每条消息都会有一个<li><span class="actionMessage">${message}</span></li>。
您可以为 actionMessage 创建 CSS 或更改模板文件以根据需要呈现这些。
这些模板文件位于:
/template/simple/actionerror.ftl
/template/simple/actionmessage.ftl
字段错误也可能对您有用:
/template/simple/fielderror.ftl
注意:如果您使用的是 xhtml 主题,这些文件可能位于模板下的该文件夹中
【讨论】: