2011-12-01 45 views
0

我的代码显示错误的验证:如何不清除输入的输入用于验证输入的URL值将如下

try{ 
     urls.eachWithIndex { u, i -> 
      String countryCode = u.key; 
      String url = urls["${u.key}"] 
      if(url != ""){ 
      Boolean valid = helperService.isURLValid(url) 
       if(valid == false){ 
        this.errors.reject("Incorrect URL is entered for "+countries.get(countryCode)+" - please ensure to use a correct URL for More Games.") 
        return []; 
        // assert false 
        // params.gamesUrls = url 
       } 
      } 
     } 
     }catch (Exception ex) { 
        logger.warn("Incorrect URL is entered", ex) 
        return []; 
     } 

当URL验证失败时所输入的值将被清除。

如何显示错误,但不清除输入的输入(试图返回[],但是是没有用的)

这里是GSP代码...

<g:form action="wizard"> 
      <table> 
       <g:each in="${countries}" status="i" var="country"> 
        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> 
         <td><img border="0" src="/wizard/image/flags/${country.key}" alt="" /> <label for="gamesUrls.${country.key}">${country.value}</label></td> 
         <td><g:textField name="gamesUrls.${country.key}" style="width:350px" value="${moreGamesUrls.get(country.key)}" onchange="\$(this).addClassName('changed');" maxlength="255"/></td> 
         <td><input type="button" value="Revert" onClick="revertTextValue('gamesUrls.${country.key}')" /></td> 
        </tr> 
       </g:each> 
      </table> 
      <g:submitButton name="back" value="Back" /> <g:submitButton name="next" value="Confirm" /> 
+1

这是在grails?什么叫这个代码?我以前没看过这个问题吗? –

+0

是的,这是在grails中,这段代码将在groovy命令的后期执行,并将错误返回到grails – Techie

+0

http://meta.stackexchange.com/a/5235/156393 –

回答

0

我能解决这通过保持在gsp的支票

<g:if test="${moreGamesUrls.get(country.key) == null || 'User Cannot Edit this URL'.equals(moreGamesUrls?.get(country.key))}"> 
          <td><g:textField name="gamesUrls.${country.key}" style="width:350px" data-default-value="" value="" onchange="\$(this).addClassName('changed');" maxlength="255"/></td> 
         </g:if> 
         <g:else> 
          <td><g:textField name="gamesUrls.${country.key}" style="width: 350px;" data-default-value="${moreGamesUrls?.get(country?.key)}" value="${moreGamesUrls?.get(country?.key)}" onchange="\$(this).addClassName('changed');" maxlength="255"/></td> 
         </g:else>