【问题标题】:Action Message tag in struts2struts2中的动作消息标签
【发布时间】:2012-05-18 18:16:17
【问题描述】:

我是 struts 新手,如何在 struts2 jsp 页面中装饰动作消息和动作错误?

<s:actionmessage/>
<s:actionerror/>

【问题讨论】:

  • 你可以使用简单的主题,你可以应用你想要的css样式。

标签: struts2


【解决方案1】:

您可以使用 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;
}

【讨论】:

    【解决方案2】:

    您好,如果您希望使用此代码来装饰您的操作消息和错误消息,我正在为您的问题发布解决方案

    <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;
    }
    

    【讨论】:

      【解决方案3】:

      您应该在呈现后查看 HTML 源代码,以查看 Struts 用于呈现消息的 CSS 类和 HTML 结构。您也可以查看模板文件。

      默认情况下,struts 会按如下方式呈现每个动作消息:

      <ul>
        <li><span class="actionMessage">${message}</span></li>
      </ul>
      

      每条消息都会有一个&lt;li&gt;&lt;span class="actionMessage"&gt;${message}&lt;/span&gt;&lt;/li&gt;

      您可以为 actionMessage 创建 CSS 或更改模板文件以根据需要呈现这些。

      这些模板文件位于:

      /template/simple/actionerror.ftl
      /template/simple/actionmessage.ftl
      

      字段错误也可能对您有用:

      /template/simple/fielderror.ftl
      

      注意:如果您使用的是 xhtml 主题,这些文件可能位于模板下的该文件夹中

      【讨论】:

      • 值得记住的是,在任何 struts2 UI 标签中,您也可以添加样式、id 和类属性以用于样式设置。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 2017-09-11
      • 1970-01-01
      相关资源
      最近更新 更多