报表参数值校验

阅读(478) 标签: iparamchecker, paramcheckclass,

背景说明:

访问报表有时需要验证参数值中是否含有某些特殊字符或者是想要通过限定参数名来实现对部分参数的验证,为满足这类需求润乾报表提供了访问报表时对参数值的校验功能。使用该功能后,访问有参数的报表时则会自动对参数进行验证。

 

代码示例:

package api;

 

import com.raqsoft.report.util.IParamChecker;

/*

 * 验证报表参数的实现类

 * 用户可以自定义验证,然后通过WEB-INF/raqsoftConfig.xml配置来加载到项目中

 */

public class DisabledCharChecker implements IParamChecker{

/*

   * @paramName 验证的参数名

   * @inputValue 验证的参数值

   */

  public boolean check(String paramName, String inputValue) {

    … …

    if(inputValue == null || inputValue.length() == 0){

      return true;

    }

    for(int i = 0; i < disabledCharArr.length; i++){

      if(inputValue.indexOf(disabledCharArr[i]) >= 0){

        this.cause = "Sorry,校验未通过," + paramName + "参数中含有以下字符:" + disabledCharArr[i];

        return false;

      }

    }

    return true;

  }

 

  /*

   * 验证的返回信息

   */

  public String getCause() {

    … …

    String tmp = this.cause;

    return tmp;

  }

  … ...

}

注意:

实现润乾报表提供的com.raqsoft.report.util.IparamChecker接口后,需在WEB-INF/raqsoftConfig.xml中添加paramCheckClass属性配置,属性值为类路径:

<Server>

  … …

  <property name="paramCheckClass" value="api.DisabledCharChecker"/>

</Server>

参考文件:DisabledCharChecker.java