Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Copyright (C) 2010---2013 星星(wuweixing)<349446658@qq.com>
   * 
   * This file is part of Wabacus 
   * 
   * Wabacus is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 package com.wabacus.system.inputbox;
 
 import java.util.List;
 import java.util.Map;
 
 
 public class ServerValidateBean
 {
     private AbsInputBox ownerInputbox;
 
     private String validatetype;
 
     private String servervalidateCallback;
 
     private List<ParamBeanlstParams;
 
     public ServerValidateBean(AbsInputBox owner)
     {
         this.=owner;
     }
 
     public String getValidatetype()
     {
         return ;
     }
 
     public void setValidatetype(String validatetype)
     {
         this.=validatetype;
     }
 
     public String getServervalidateCallback()
     {
         return ;
     }
 
     public void setServervalidateCallback(String servervalidateCallback)
     {
         this.=servervalidateCallback;
     }
 
     public List<ParamBeangetLstParams()
     {
         return ;
     }
 
     public void setLstParams(List<ParamBeanlstParams)
     {
         this.=lstParams;
     }
 
     public void addValidateMethod(ReportBean rbean,String methodname,String errormsg)
     {
         if(methodname==null||methodname.trim().equals("")) return;
         ParamBean paramBean=getValidateMethodParamBean(methodname,errormsg,rbean.getLstServerValidateClasses());//先从<report/>中配置的服务器端校验类中找此方法
         if(paramBean==null)
         {
             paramBean=getValidateMethodParamBean(methodname,errormsg,Config.getInstance().getLstServerValidateClasses());
         }
         if(paramBean==null)
         {
             throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"失败,在所有服务器端校验类中没有找到服务器端校验方法:"+methodname+"的定义");
         }
         if(this.==nullthis.=new ArrayList<ParamBean>();
         this..add(paramBean);
     }
 
     private ParamBean getValidateMethodParamBean(String methodname,String errormsg,List<ClasslstClassesTmp)
     {
        if(lstClassesTmp==null||lstClassesTmp.size()==0) return null;
        ParamBean paramBean=null;
        Method mTmp;
        for(Class cTmp:lstClassesTmp)
        {
            try
            {
                mTmp=cTmp.getMethod(methodname,new Class[] { ReportRequest.classString.classMap.classList.class });
            }catch(NoSuchMethodException nse)
            {
                continue;
            }
            if(mTmp==nullcontinue;
            paramBean=new ParamBean();
            paramBean.setValidateClass(cTmp);
            paramBean.setValidateMethod(mTmp);
            Object[] objArr=WabacusAssistant.getInstance().parseStringWithDynPart(errormsg);
            paramBean.setMessage((String)objArr[0]);
            paramBean.setMDynMessageParts((Map<String,String>)objArr[1]);
            break;
        }
        return paramBean;
    }
    public boolean validate(ReportRequest rrequest,String boxvalue,Map<String,StringmOtherValues,List<StringlstErrorMessages,boolean isOnBlur)
    {
        if(==null||.size()==0) return true;
        {
            return true;
        }
        boolean bolResult=true;
        for(ParamBean paramBeanTmp:this.)
        {
            lstErrorMessages.clear();
            lstErrorMessages.add(paramBeanTmp.getMessage(rrequest,boxvalue));
            if(!paramBeanTmp.validate(rrequest,boxvalue,mOtherValues,lstErrorMessages))
            {
                bolResult=false;
                break;
            }
        }
        if(!isOnBlur&&!bolResult)
        {
            StringBuffer errormsgBuf=new StringBuffer();
            for(String errormsgTmp:lstErrorMessages)
            {
                if(errormsgTmp==null||errormsgTmp.trim().equals("")) continue;
                errormsgBuf.append(errormsgTmp).append(";");
            }
            if(errormsgBuf.length()>0&&errormsgBuf.charAt(errormsgBuf.length()-1)==';'errormsgBuf.deleteCharAt(errormsgBuf.length()-1);
            if(this.!=null&&!this..trim().equals(""))
            {
                StringBuffer paramsBuf=new StringBuffer();
                paramsBuf.append("{inputboxid:\"").append(this..getOwner().getInputBoxId()).append("\"");
                paramsBuf.append(",value:\"").append(boxvalue).append("\"");
                paramsBuf.append(",errormess:\"").append(errormsgBuf.toString()).append("\"");
                paramsBuf.append(",validatetype:\"onsubmit\"");
                paramsBuf.append(",isSuccess:false");
                paramsBuf.append(",serverDataObj:{");
                if(rrequest.getMServerValidateDatas()!=null&&rrequest.getMServerValidateDatas().size()>0)
                {
                    for(Entry<String,StringentryTmp:rrequest.getMServerValidateDatas().entrySet())
                    {
                        paramsBuf.append(entryTmp.getKey()+":\""+entryTmp.getValue()+"\",");
                    }
                    if(paramsBuf.charAt(paramsBuf.length()-1)==','paramsBuf.deleteCharAt(paramsBuf.length()-1);
                }
                paramsBuf.append("}}");
                rrequest.getWResponse().addOnloadMethod(this.,paramsBuf.toString(),true,.);
            }
            if(errormsgBuf.toString().trim().equals(""))
            {
                rrequest.getWResponse().setStatecode(.);
                throw new WabacusRuntimeWarningException();
            }else
            {
                rrequest.getWResponse().getMessageCollector().warn(errormsgBuf.toString(),true,.);
            }
        }
        return bolResult;
    }
    private class ParamBean
    {
        private String message;
        private Map<String,StringmDynMessageParts;
        private Class validateClass;
        private Method validateMethod;
        public String getMessage()
        {
            return ;
        }
        public String getMessage(ReportRequest rrequest,String boxvalue)
        {
            String realmess=WabacusAssistant.getInstance().getStringValueWithDynPart(rrequest,this.,this.,"").trim();
            if(boxvalue==nullboxvalue="";
            realmess=Tools.replaceAll(realmess,"#label#",.getOwner().getLabel(rrequest));
            realmess=Tools.replaceAll(realmess,"#data#",boxvalue);
            return realmess;
        }
        public void setMessage(String message)
        {
            this.=message;
        }
        public Map<String,StringgetMDynMessageParts()
        {
            return ;
        }
        public void setMDynMessageParts(Map<String,StringdynMessageParts)
        {
            =dynMessageParts;
        }
        public Class getValidateClass()
        {
            return ;
        }
        public void setValidateClass(Class validateClass)
        {
            this.=validateClass;
        }
        public Method getValidateMethod()
        {
            return ;
        }
        public void setValidateMethod(Method validateMethod)
        {
            this.=validateMethod;
        }
        public boolean validate(ReportRequest rrequest,String boxvalue,Map<String,StringmOtherValues,List<StringlstErrorMessages)
        {
            try
            {
                return (Boolean)this..invoke(this.,new Object[] { rrequestboxvaluemOtherValueslstErrorMessages });
            }catch(Exception e)
            {
                throw new WabacusRuntimeException("对报表"+.getOwner().getReportBean().getPath()+"的输入框"
                        +.getOwner().getInputBoxId()+"的数据"+boxvalue+"进行服务器端校验时失败",e);
            }
        }
    }
New to GrepCode? Check out our FAQ X