⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 入門 22 - validator訊息檔管理 - javaworld@tw.htm

📁 struts快速入门文章
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0071)http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=619 -->
<HTML><HEAD><TITLE>入門 22 - Validator訊息檔管理 - JAVAWORLD@TW</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><!-- CONFL-BEGIN standardHeader -->
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Expires content=-1>
<SCRIPT language=javascript>  var contextPath = '/confluence';</SCRIPT>
<LINK href="入門 22 - Validator訊息檔管理 - JAVAWORLD@TW.files/main-action.css" 
type=text/css rel=stylesheet><LINK href="/confluence/images/icons/favicon.ico" 
rel="shortcut icon"><LINK href="/confluence/images/icons/favicon.png" 
type=image/png rel=icon>
<SCRIPT src="入門 22 - Validator訊息檔管理 - JAVAWORLD@TW.files/effects.js"></SCRIPT>
<!-- CONF-END standardHeader -->
<META content="MSHTML 6.00.2800.1491" name=GENERATOR></HEAD>
<BODY onload=placeFocus()>
<DIV id=Content>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD class=logocell width="60%" rowSpan=2>
      <DIV class=spacenametitle><A 
      href="http://www.javaworld.com.tw/confluence/display/opensrc"><IMG 
      src="入門 22 - Validator訊息檔管理 - JAVAWORLD@TW.files/confluence_logo.gif" 
      align=bottom border=0></A> <A 
      href="http://www.javaworld.com.tw/confluence/display/opensrc">OpenSource 
      Project</A></DIV></TD>
    <TD vAlign=top align=right width="40%">
      <TABLE cellSpacing=1 cellPadding=2 align=right bgColor=#ffffff border=0>
        <TBODY>
        <TR>
          <TD class=navItem onmouseover="this.className='navItemOver'" 
          onclick="window.document.location='/confluence/'" 
          onmouseout="this.className='navItem'" vAlign=center noWrap 
          align=middle>&nbsp;&nbsp; <A title="Go to the Confluence Dashboard" 
            accessKey=h onclick="return false" 
            href="http://www.javaworld.com.tw/confluence/"><U>H</U>OME</A> 
            &nbsp;&nbsp;</TD>
          <TD class=navItem onmouseover="this.className='navItemOver'" 
          onclick="window.document.location='/confluence/spaces/listspaces.action'" 
          onmouseout="this.className='navItem'" vAlign=center noWrap 
          align=middle>&nbsp;&nbsp; <A title="The spaces available for you" 
            accessKey=s onclick="return false" 
            href="http://www.javaworld.com.tw/confluence/spaces/listspaces.action"><U>S</U>PACES</A> 
            &nbsp;&nbsp;</TD></TR></TBODY></TABLE></TD></TR>
  <TR>
    <TD vAlign=bottom align=right><SPAN class=smalltext><A 
      href="http://www.javaworld.com.tw/confluence/login.action?os_destination=/pages/viewpage.action?pageId=619">Log 
      In</A> &nbsp; </SPAN><A 
      href="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=619&amp;decorator=printable"><IMG 
      title="View a printable version of the current page." height=16 
      alt="View a printable version of the current page." hspace=1 
      src="入門 22 - Validator訊息檔管理 - JAVAWORLD@TW.files/print_16.gif" width=16 
      align=absMiddle vspace=1 border=0></A> <A 
      href="http://confluence.atlassian.com/display/DOC"><IMG 
      title="Get help from the Confluence website." height=16 
      alt="Get help from the Confluence website." hspace=1 
      src="入門 22 - Validator訊息檔管理 - JAVAWORLD@TW.files/help_16.gif" width=16 
      align=absMiddle vspace=1 border=0></A> </TD></TR></TBODY></TABLE><!-- CONF-BEGIN breadcrumbsAndSearch -->
<DIV class=breadcrumbs width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD>&nbsp; Location: <A 
      href="http://www.javaworld.com.tw/confluence/dashboard.action">Dashboard</A> 
      &gt; <A 
      href="http://www.javaworld.com.tw/confluence/spaces/viewspacesummary.action?key=opensrc">opensrc</A> 
      &gt; <A 
      href="http://www.javaworld.com.tw/confluence/pages/listpages.action?key=opensrc">Pages</A> 
      &gt; <A 
      href="http://www.javaworld.com.tw/confluence/display/opensrc/Home">Home</A> 
      &gt; <A 
      href="http://www.javaworld.com.tw/confluence/display/opensrc/Struts">Struts</A> 
      &gt; <A 
      href="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=1958">Struts入門</A> 
      &gt; <A 
      href="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=619">入門 
      22 - Validator訊息檔管理</A> </TD>
    <FORM name=searchForm action=/confluence/dosearchsite.action 
    method=get><INPUT type=hidden value=true name=quickSearch> 
    <TD vAlign=bottom align=right width=200><A style="TEXT-DECORATION: none" 
      href="http://www.javaworld.com.tw/confluence/searchsite.action"><U>Q</U>uick 
      <U>Search</U></A>:<INPUT accessKey=q size=10 name=searchQuery.queryString><INPUT type=submit value=Go><BR><IMG height=1 
      src="入門 22 - Validator訊息檔管理 - JAVAWORLD@TW.files/spacer.gif" 
    width=200></TD></FORM></TR></TBODY></TABLE></DIV><!-- CONF-END breadcrumbsAndSearch -->
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD class=pagebody vAlign=top>
            <DIV class=pageheader><SPAN class=pagetitle>入門 22 - 
            Validator訊息檔管理</SPAN> </DIV>
            <SCRIPT language=javascript>        function toggle(id) {            var oldAttachmentVersionsBlock = document.getElementById('attachment' + id);            with (oldAttachmentVersionsBlock.style)            {                if ( display == "none" )                    display = ""                else                    display = "none"            }            var arrowIcon = document.getElementById('arrow' + id);            with (arrowIcon)            {                if (src != null && (src.indexOf('/confluence/images/icons/arrow_closed_active_16.gif') != -1 || src.indexOf('/confluence/images/icons/arrow_closing_active_16.gif') != -1))                {                    src = '/confluence/images/icons/arrow_opening_active_16.gif';                }                else                {                    src = '/confluence/images/icons/arrow_closing_active_16.gif';                }            }        }        </SCRIPT>

            <DIV class=pagesubheading>Last changed on Oct 27, 2004 by <A 
            href="http://www.javaworld.com.tw/confluence/display/~koji">koji 
            lin</A> 
            </DIV><!-- page content --> Validator框架預設使用Struts訊息資源中的key-value訊息,您可以查看struts-blank中的application.properties,當中有關於validator訊息的部份就是Validator預設使用的: 

            <DIV class=code 
            style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
            <DIV class=codeHeader 
            style="BORDER-BOTTOM-STYLE: solid"><B>application.properties</B></DIV>
            <DIV class=codeContent><PRE># -- validator -- 
errors.invalid={0} is invalid. 
errors.maxlength={0} can not be greater than {1} characters. 
errors.minlength={0} can not be less than {1} characters. 
errors.range={0} is not in the range {1} through {2}. 
errors.required={0} is required. 
errors.<SPAN class=java-object>byte</SPAN>={0} must be an <SPAN class=java-object>byte</SPAN>. 
errors.date={0} is not a date. 
errors.<SPAN class=java-object>double</SPAN>={0} must be an <SPAN class=java-object>double</SPAN>. 
errors.<SPAN class=java-object>float</SPAN>={0} must be an <SPAN class=java-object>float</SPAN>. 
errors.integer={0} must be an integer. 
errors.<SPAN class=java-object>long</SPAN>={0} must be an <SPAN class=java-object>long</SPAN>. 
errors.<SPAN class=java-object>short</SPAN>={0} must be an <SPAN class=java-object>short</SPAN>. 
errors.creditcard={0} is not a valid credit card number. 
errors.email={0} is an invalid e-mail address.</PRE></DIV></DIV><BR> Struts支援國際化訊息,Validator同樣也支援國際化訊息,您可以在&lt;formset&gt;上使用language、country等屬性來指定所要使用的國際化訊息,當然您必須為每一個國際化訊息提供對應的訊息資源檔: 

            <DIV class=code 
            style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
            <DIV class=codeHeader 
            style="BORDER-BOTTOM-STYLE: solid"><B>validation.xml</B></DIV>
            <DIV class=codeContent><PRE>&lt;formset&gt; 
        .... 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -