Tapestry 验证用户名

DocSourceDAO代码:

 

  1. package com.jbcom.support.cms.dao;
  2. import com.jbcom.platform.spring.IBaseDao;
  3. /**
  4.  * DocSource数据访问对象
  5.  * @author Administrator
  6.  *
  7.  */
  8. public interface DocSourceDAO extends IBaseDao {
  9.         public String getHQL_All();
  10.         public String getHQL_RowCount();
  11.      /**
  12.      * 判断来源名称是否重复
  13.      * @param docSourceId--来源标示
  14.      * @param name--来源名称
  15.      * @return T--重复 F--不重复 
  16.      */
  17.     public boolean isNameExist(String docSourceId, String name);
  18.     /**
  19.      * 添加来源时判断来源名称是否重复
  20.      * @param name--来源名称
  21.      * @return isNameExist("0", name)方法的结果
  22.      */
  23.     public boolean isNameExist(String name);
  24. }

 

 

 

DocSourceDAOImpl代码:

 

  1. package com.jbcom.support.cms.dao.impl;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.jbcom.platform.spring.BaseDaoImpl;
  5. import com.jbcom.support.cms.dao.DocSourceDAO;
  6. import com.jbcom.support.cms.hbm.DocSourceHBM;
  7. /**
  8.  * DocSource数据访问对象
  9.  * @author Administrator
  10.  *
  11.  */
  12. public class DocSourceDAOImpl extends BaseDaoImpl implements DocSourceDAO {
  13.     public String getHQL_All() {
  14.         return "from DocSourceHBM docSourceHBM";
  15.     }
  16.     public String getHQL_RowCount() {
  17.         return "select count(*) from DocSourceHBM docSourceHBM";
  18.     }
  19.     protected Class getPersistentClass() {
  20.         return DocSourceHBM.class;
  21.     }
  22.     
  23.     /**
  24.      * 判断来源名称是否重复
  25.      * @param docSourceId--来源标示
  26.      * @param name--来源名称
  27.      * @return T--重复 F--不重复 
  28.      */
  29.     public boolean isNameExist(String docSourceId,String name){
  30.         List docSource ;
  31.         docSource = new ArrayList();
  32.         boolean reasult = false;
  33.         if(!docSource.equals("0"))
  34.             docSource = findWithHQL("FROM DocSourceHBM docSourceHBM where docSourceHBM.docSourceId<>'"
  35.                     + docSourceId
  36.                     + "' and docSourceHBM.name='"
  37.                     + name + "'");
  38.         else
  39.             docSource = findWithHQL("FROM DocSourceHBM docSourceHBM where docSourceHBM.name='"+name+"'");
  40.         
  41.         if (docSource.size() != 0)
  42.             reasult = true;
  43.             
  44.         return reasult;
  45.     }
  46.     
  47.     /**
  48.      * 添加来源时判断来源名称是否重复
  49.      * @param name--来源名称
  50.      * @return isNameExist("0", name)方法的结果
  51.      */
  52.     public boolean isNameExist(String name){
  53.         return isNameExist("0", name);
  54.     }
  55. }

 

 

 

DocSourceEdit代码:

 

  1. package com.jbcom.support.cms.pages;
  2. import org.apache.tapestry.IRequestCycle;
  3. import org.apache.tapestry.valid.IValidationDelegate;
  4. import org.apache.tapestry.valid.ValidationConstraint;
  5. import com.jbcom.support.cms.dao.DocSourceDAO;
  6. import com.jbcom.support.cms.hbm.DocSourceHBM;
  7. import com.jbcom.support.cms.html.DocmentPage;
  8. import com.jbcom.support.tapestry.Visit;
  9. /**
  10.  * 新增和修改来源
  11.  * 
  12.  * @author Administrator 
  13.  */
  14. public abstract class DocSourceEdit extends DocmentPage {
  15.     // 设定DAO类
  16.     public abstract DocSourceDAO getDocSourceDAO();
  17.     // 具体操作对象
  18.     public abstract DocSourceHBM getDocSourceHBM();
  19.     public abstract void setDocSourceHBM(DocSourceHBM docSourceHBM);
  20.     /**
  21.      * 来源信息的保存
  22.      * @param cycle
  23.      */
  24.     public void save(IRequestCycle cycle) {
  25.         IValidationDelegate validationDelegate = (IValidationDelegate) getBeans()
  26.                 .getBean("delegate");
  27.         doValit(validationDelegate);        
  28.         if (validationDelegate.getHasErrors()){         
  29.             return;
  30.         }
  31.         
  32.         DocSourceDAO dao = getDocSourceDAO();       
  33.         // 写入创建人
  34.         getDocSourceHBM().setUser(((Visit)getVisit()).getLoginUser());
  35.         dao.save(getDocSourceHBM());        
  36.         // 返回列表页
  37.         DocSourceList nextPage = (DocSourceList) cycle.getPage("DocSourceList");
  38.         cycle.activate(nextPage);
  39.     }
  40.     /**
  41.      * 检验有效性
  42.      * @param validationDelegate
  43.      */
  44.     private void doValit(IValidationDelegate validationDelegate) {
  45.         if (validationDelegate.getHasErrors())
  46.             return;
  47.         DocSourceDAO docSourceDAO = getDocSourceDAO();
  48.         String errorMessage = "";
  49.         
  50.         // 来源名称为空
  51.         if (getDocSourceHBM().getName() == null
  52.                 || getDocSourceHBM().getName().trim().equals("")) {
  53.             errorMessage = "请填写名称,名称不能为空!";
  54.             validationDelegate.record(errorMessage,
  55.                     ValidationConstraint.CONSISTENCY);
  56.             return;
  57.         }
  58.         
  59.         // 来源名称重复
  60.         boolean reasult;
  61.         if(getDocSourceHBM().getDocSourceId()==null)
  62.             reasult = docSourceDAO.isNameExist(getDocSourceHBM().getName());
  63.         else
  64.             reasult = docSourceDAO.isNameExist(getDocSourceHBM().getDocSourceId(),getDocSourceHBM().getName());
  65.         if(reasult){
  66.             errorMessage = "该名称已经被使用,请使用一个有效的名称!";
  67.             validationDelegate.record(errorMessage,
  68.                     ValidationConstraint.CONSISTENCY);
  69.             return;
  70.         }
  71.         // 标题过长
  72.         if(getDocSourceHBM().getName().length() >= 50)
  73.         {
  74.             errorMessage = "名称过长!";
  75.             validationDelegate.record(errorMessage,
  76.                     ValidationConstraint.CONSISTENCY);
  77.             return;
  78.         }
  79.         // 描述过长
  80.         
  81.         if(getDocSourceHBM().getDescription()!=null){
  82.         if(getDocSourceHBM().getDescription().length() >= 50)       
  83.         {
  84.             errorMessage = "描述过长!";
  85.             validationDelegate.record(errorMessage,
  86.                     ValidationConstraint.CONSISTENCY);
  87.             return;
  88.         }
  89.         }
  90.         
  91.         // 来源链接地址为空
  92.         if(getDocSourceHBM().getLink()==null ||getDocSourceHBM().getLink()=="" ){
  93.             errorMessage = "请输入来源的链接地址!";
  94.             validationDelegate.record(errorMessage,
  95.                     ValidationConstraint.CONSISTENCY);
  96.             return;
  97.         }
  98.         // 链接过长
  99.         if(getDocSourceHBM().getLink().length() >= 50)
  100.         {
  101.             errorMessage = "链接过长!";
  102.             validationDelegate.record(errorMessage,
  103.                     ValidationConstraint.CONSISTENCY);
  104.             return;
  105.         }
  106.     }
  107.     
  108. }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值