html:errors

來源:互聯網
上載者:User

 html:errors標籤和html:messages標籤的功能相似,所以我們放到一起來介紹。

html:errors標籤將由name屬性指定的ActionMessages、ActionErrors、String和String[]直接輸出到頁面中。

html:messages標籤將用由name屬性(注意message屬性值對它的影響)指定的ActionMessages、ActionErrors、String和String[]建立一個新的屬性和scripting變數,使用id屬性值作為名稱。

html:errors標籤和html:messages標籤的property屬性是用來為errors和messages分類的。我們可以給這兩個標籤指定property屬性,以便只顯示某一類的錯誤或訊息。

在資源檔增加了如下的內容:

# -- standard errors --
errors.header=<ul>
errors.prefix=<li>
errors.suffix=</li>
errors.footer=</ul>
error=error with none value .
error1=error1 with one value is {0} .
error2=error2 with two values are {0} , {1} .
error3=error3 with three values are {0} , {1} , {2} .
error4=error4 with four values are {0} , {1} , {2} ,{3} .
下面的程式碼範例了actionErrors的構造:

public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
  ActionErrors actionErrors = new ActionErrors();
  actionErrors.add("property1",
  new ActionMessage("error"));
  actionErrors.add("property2",
  new ActionMessage("error1","value0"));
  actionErrors.add("property2",
  new ActionMessage("error2","value0","value1"));
  actionErrors.add("property3",
  new ActionMessage("error3","value0","value1","value2"));
  actionErrors.add("property3",
  new ActionMessage("error4","value0","value1","value2","value3"));
  actionErrors.add("property4",
  new ActionMessage("error1",new Object[]{"value0"}));
  actionErrors.add("property4",
  new ActionMessage("error2",new Object[]{"value0","value1"}));
  actionErrors.add("property4",
  new ActionMessage("error3",new Object[]{"value0","value1",
    "value2"}));
  actionErrors.add("property5",
  new ActionMessage("error4",new Object[]{"value0","value1",
    "value2","value3"}));
  actionErrors.add("notBundle",
  new ActionMessage("not a bundle key",false));
  return actionErrors;

errors標籤程式碼範例:

<html:errors/>
<br/> 
<html:errors property="property4"/>
messages標籤程式碼範例:

<logic:messagesPresent>
  <ul>
  <html:messages id="message">
    <li><bean:write name="message"/></li>
  </html:messages>
  </ul>
</logic:messagesPresent>
<br/>
<logic:messagesPresent>
  <ul>
  <html:messages id="message" property="property4">
    <li><bean:write name="message"/></li>
  </html:messages>
</ul>
</logic:messagesPresent>
圖示 2. 上面的兩段程式碼範例運行結果相同,如下所示:
 

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/AWUSOFT/archive/2008/05/16/2452874.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.