2011-11-22 63 views
0

我在文本框中输入值(URL),当我点击下一个按钮时,运行验证是否输入的url值是否有效。输入值正在清除gsp

如果网址已经无效,那么我显示如下错误

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

一旦显示的错误,它的清除输入的数值,需要再次输入值。如何限制清除值(我认为页面正在重新加载)或限制页面再次加载。

这里是命令 -

class DeliveryMoreGamesURLCommand implements Command { 
    private static final LOG = LogFactory.getLog(DeliveryController.class) 

    def wrapperService = ApplicationHolder.application.getMainContext().getBean("wrapperService"); 
    def customerService = ApplicationHolder.application.getMainContext().getBean("customerService"); 
    def countryService = ApplicationHolder.application.getMainContext().getBean("countryService"); 
    def helperService = ApplicationHolder.application.getMainContext().getBean("helperService"); 
    def ascService = ApplicationHolder.application.getMainContext().getBean("ascService"); 

    Hashtable<String, String> countries; 

    public LinkedHashMap<String, Object> preProcess(sessionObject, params, request) { 
     Delivery delivery = (Delivery) sessionObject; 

     def customer = Customer.get(delivery.customerId); 
     def contentProvider = ContentProvider.get(delivery.contentProviderId); 
     def deployment = Deployment.get(delivery.deploymentId); 
     def operatingSystem = OperatingSystem.get(delivery.operatingSystemId); 

     countries = wrapperService.getCountries(deployment, operatingSystem); 
     def sortedCountries = countries.sort { a, b -> a.value <=> b.value }; 

     def urls = ascService.getMoreGamesUrlsPerTemplates(deployment, operatingSystem); 

     def moreGamesUrls = new Hashtable<String,String>(); 
     countries.each { country -> 
      String countryCode = countryService.getTwoLetterCountryAbbreviation(country.key); 
      String url = customerService.getMoreGamesUrl(customer, contentProvider, countryCode); 
      if ("".equals(url)) { 
       url = urls.get(country.key); 
       if (url == null) { 
        url = ""; 
       } 
      } 
      moreGamesUrls.put(country.key, url); // We need to use the existing country code if the channels are deployed with three letter country codes 
     } 

     return [command: this, countries: sortedCountries, moreGamesUrls: moreGamesUrls] 
    } 

    public LinkedHashMap<String, Object> postProcess(sessionObject, params, request) { 
     Delivery delivery = (Delivery) sessionObject; 

     def urls = params.gamesUrls; 
     LOG.debug("urls from gsp :"+urls) 
     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 []; 
       } 
      } 
     } 
     }catch (Exception ex) { 
        logger.warn("Incorrect URL is entered", ex) 
        return []; 
     } 

     def moreGamesUrls = new Hashtable<String, String>(); 
     urls.eachWithIndex { u, i -> 
      String countryCode = u.key; 
      String url = urls["${u.key}"] 
      moreGamesUrls.put(countryCode, url); 
     } 

     delivery.countries = countries; 
     delivery.moreGamesUrls = moreGamesUrls; 
     LOG.debug("moreGamesUrls after edit=${delivery.moreGamesUrls}"); 

     return null; 
    } 
} 

从命令预处理的数据将被渲染,然后点击下一步按钮后,在后处理将被调用,并为URL验证...

+0

对不起,问题不清楚。请提供更多代码:下一个按钮如何工作?视图如何呈现?你是否将输入的参数传递回来查看? – Chris

+0

用命令编辑了这个问题 – Techie

回答

0

解决了这个问题,通过实现更多的游戏作为一个全局变量(甚至在抛出错误后存储了值)