hk2000c技术专栏

技术源于哲学,哲学来源于生活 关心生活,关注健康,关心他人

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  111 随笔 :: 1 文章 :: 28 评论 :: 0 Trackbacks

#

改进了spring 的校验机制

重写了几个类,使得应用程序更加自由,可以自定义formName,不用绑定pojo名字。

posted @ 2007-10-26 18:35 hk2000c 阅读(217) | 评论 (0)编辑 收藏

BaseCommandController extends AbstractController extends WebContentGenerator WebContentGenerator extends WebApplicationObjectSupport extends ApplicationObjectSupport implements ApplicationContextAware 

/**
  * Subclasses can override this for custom initialization behavior.
  * Gets called by <code>setApplicationContext</code> after setting the context instance.
  * <p>Note: Does </i>not</i> get called on reinitialization of the context
  * but rather just on first initialization of this object's context reference.
  * @throws ApplicationContextException in case of initialization errors
  * @throws BeansException if thrown by ApplicationContext methods
  * @see #setApplicationContext
  */
 protected void initApplicationContext() throws BeansException {
 }

愿意为子类可以把初始化bean 动作放入此方法,可以自定义一些动作。

我们再来看看调用
public final void setApplicationContext(ApplicationContext context) throws BeansException {
  if (context == null && !isContextRequired()) {
   // Reset internal context state.
   this.applicationContext = null;
   this.messageSourceAccessor = null;
  }
  else if (this.applicationContext == null) {
   // Initialize with passed-in context.
   if (!requiredContextClass().isInstance(context)) {
    throw new ApplicationContextException(
      "Invalid application context: needs to be of type [" + requiredContextClass().getName() + "]");
   }
   this.applicationContext = context;
   this.messageSourceAccessor = new MessageSourceAccessor(context);
   initApplicationContext();
  }
  else {
   // Ignore reinitialization if same context passed in.
   if (this.applicationContext != context) {
    throw new ApplicationContextException(
      "Cannot reinitialize with different application context: current one is [" +
      this.applicationContext + "], passed-in one is [" + context + "]");
   }
  }
 }

可以看到由 ApplicationObjectSupport  的 setApplicationContext 方法调用
而此方法为 ApplicationContextAware 的唯一接口方法,

public interface ApplicationContextAware {
 
 /**
  * Set the ApplicationContext that this object runs in.
  * Normally this call will be used to initialize the object.
  * <p>Invoked after population of normal bean properties but before an init callback such
  * as {@link org.springframework.beans.factory.InitializingBean#afterPropertiesSet()}
  * or a custom init-method. Invoked after {@link ResourceLoaderAware#setResourceLoader},
  * {@link ApplicationEventPublisherAware#setApplicationEventPublisher} and
  * {@link MessageSourceAware}, if applicable.
  * @param applicationContext the ApplicationContext object to be used by this object
  * @throws ApplicationContextException in case of context initialization errors
  * @throws BeansException if thrown by application context methods
  * @see org.springframework.beans.factory.BeanInitializationException
  */
 void setApplicationContext(ApplicationContext applicationContext) throws BeansException;

}

此方法被 ApplicationContextAwareProcessor 的 postProcessBeforeInitialization  调用
ApplicationContextAwareProcessor implements BeanPostProcessor 
 public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
  if (bean instanceof ResourceLoaderAware) {
   ((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
  }
  if (bean instanceof ApplicationEventPublisherAware) {
   ((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
  }
  if (bean instanceof MessageSourceAware) {
   ((MessageSourceAware) bean).setMessageSource(this.applicationContext);
  }
  if (bean instanceof ApplicationContextAware) {
   ((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
  }
  return bean;
 }



posted @ 2007-10-26 01:12 hk2000c 阅读(602) | 评论 (0)编辑 收藏

以 BaseCommandController 为例
protected void initApplicationContext() {
  if (this.validators != null) {
   for (int i = 0; i < this.validators.length; i++) {
    if (this.commandClass != null && !this.validators[i].supports(this.commandClass))
     throw new IllegalArgumentException("Validator [" + this.validators[i] +
       "] does not support command class [" +
       this.commandClass.getName() + "]");
   }
  }
 }

子类配置如下

 <bean id="addNewsController" class="AddNewsController" scope="request">
        <property name="formView" value="/management/news/addNews"/>
        <property name="validator" ref="beanValidator"/>
        <property name="successView" value="forward:/management/news/newsList.html"/>
        <property name="commandClass" value="News"/>
        <property name="commandName" value="news"/>
    </bean>

public final void setValidator(Validator validator) {
  this.validators = new Validator[] {validator};
 }

设置Validator数组

在初始化的时候,检验 是否支持command 类型
this.validators[i].supports(this.commandClass)

此support 为 org.springframework.validation.Validator 的所有 实现类的 方法,检验支持检验类的动作。


举例 配置
 <bean id="beanValidator" class="org.springmodules.validation.commons.DefaultBeanValidator">
        <property name="validatorFactory" ref="validatorFactory"/>
    </bean>

DefaultBeanValidator extends AbstractBeanValidator implements Validator

再看实现方法

   /**
     * Checks if the validatorFactory is configured to handle this class.  Will
     * convert the class into a form name, suitable for commons validator.
     *
     * @return <code>true</code> if the validatorFactory supports the class,
     *         or <code>false</code> if not
     * @see #getFormName(Class)
     */
    public boolean supports(Class clazz) {
        boolean canSupport = validatorFactory.hasRulesForBean(getFormName(clazz), getLocale());
        if (log.isDebugEnabled()) {
            log.debug("validatorFactory " + (canSupport ? "does" : "does not")
                + " support class " + clazz + " with form name " + getFormName(clazz));
        }
        return canSupport;
    }

检验是否支持输入类

另一个方法
 /**
     * If <code>useFullyQualifiedClassName</code> is false (default value), this function returns a
     * string containing the uncapitalized, short name for the given class
     * (e.g. myBean for the class com.domain.test.MyBean). Otherwise, it  returns the value
     * returned by <code>Class.getName()</code>.
     *
     * @param cls <code>Class</code> of the bean to be validated.
     * @return the bean name.
     */
    protected String getFormName(Class cls) {
        return (this.useFullyQualifiedClassName) ? cls.getName() : Introspector.decapitalize(ClassUtils.getShortName(cls));
    }
 Introspector.decapitalize(ClassUtils.getShortName(cls) 获得按照西班牙命名法的form 名

这个方法本意是获得以类名为formName 的所有校验配置。

实际上有一个重大的设计缺陷






posted @ 2007-10-26 00:48 hk2000c 阅读(1835) | 评论 (0)编辑 收藏

看了一档第1财经的节目,做的是携程创始人之一现任CEO 范敏的创业故事。说的是携程是当初由4位创业者创建的网络为平台的旅游订房公司,从当初的小小企业,到现在在线订房的龙头老大。
其中那位CEO说了这句话挺有意思:只有IT和传统业务完美结合的时候,才能发挥出巨大的能量,从而创业成功。想当初,e龙和中青旅,一个是纯IT公司,一个是实力强劲的老牌旅游,携程能够从这两家当中找缝隙绝非易事。如今携程拥有全国最大的call center 就可以说明这点,IT企业或者传统企业要想做大,要想创业成功,必须把两者完美结合起来,淘宝,大众点评网,等一系列大众熟知的网站,都能说明这点。光搞IT或者传统企业没有好好实行信息化拓展自己的业务的话,是没有很好的发展的,无数开了关,关了开的IT公司或者其他相类似的企业,都是这样的。

现在转到说一碗乌冬面的故事。那位CEO有次去了日本,到一家小店里面吃了碗乌冬面,感到吃了这里的乌冬面后,其他地方都不叫乌冬面,太好吃了。但是看这家店不大,就和店主攀谈,为什么不全国连锁式的开分店呢。店主回答他说,他们家几代人就是专研乌冬面的,做一件事情就要把它做到最好极致,他们是非常谨慎的开每家分店,只有保证分店的味道100%保证后才能开下一家。
现在讲究快节奏,创新的时代,这种精神尤其值得借鉴。仔细想,生活也好,工作也好,创业也好。把一件事情做到尚可,很容易,做到好,又去掉一半人,做到很好,又少一半,到最后,做到极致的人,寥寥无几。我想,只要自己认准一个目标,坚持到底,把他做到极致。我想也许成功也许会对你打开一道缝隙。


 

posted @ 2007-10-25 23:06 hk2000c 阅读(348) | 评论 (0)编辑 收藏

还要增加command 的记忆功能,主要是为了表单验证失败以后,在服务器端控制表单内容不丢失问题。

posted @ 2007-10-25 17:01 hk2000c 阅读(243) | 评论 (0)编辑 收藏

茫茫大海,一望无际,又是永无止境的黑夜。
此时此刻,我抱着一块仅有的木板,在这黑海中浮浮沉沉。
不知道哪里是个头。
有时候,突然回想,算了,沉了吧,也算挣扎过了,就这么沉了吧。
可人偏偏不死心,不到木板全碎了,是不甘心的。


posted @ 2007-10-25 16:44 hk2000c 阅读(239) | 评论 (0)编辑 收藏

超烂的commons validatro 和 spring module 结合后,感觉很差,决定改造 commons validator ,  因为只能和form name 以及 spring pojo 或者 dto name 绑定,所以非常不方便,在尝试改进校验代码。


posted @ 2007-10-25 16:31 hk2000c 阅读(329) | 评论 (1)编辑 收藏

登录页面有很多习惯性的操作,比如打开页面,焦点在要输入的文本框;按TAB键,光标会按一定的顺序切换;输入完毕,压下回车等等,你也可以轻松实现,看下面页面的一个例子:

<HTML>
<HEAD>
<TITLE> 登录页面 </TITLE>

<script language="javascript" event="onkeydown" for="document"> 
<!--
if(event.keyCode==13) 

  document.all('TBUTTON').click(); 
}
-->
</script> 

</HEAD>
<BODY ONLOAD="window.document.forms[0].USERNAME.focus();">
<FORM ACTION="" NAME="TEST" METHOD="POST">
用户名:<INPUT TYPE="TEXT" NAME="USERNAME" tabindex="1"><BR>
密&nbsp&nbsp码:<INPUT TYPE="TEXT" NAME="PASSWORD" tabindex="2"><BR>
<INPUT TYPE="BUTTON" NAME="TBUTTON" VALUE="回车" onclick="alert('已经点击!!');" tabindex="3">
</FORM>
</BODY>
</HTML>

其中脚本部分,是相应回车键的,TBUTTON为相应的按钮名称;
BODY中ONLOAD为打开页面时加载操作,在此确定焦点所在,USERNAME为相应的控件名称;
各个控件中tabindex为TAB顺序。 



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1342882

posted @ 2007-06-28 10:02 hk2000c 阅读(5707) | 评论 (0)编辑 收藏

Today, I design an e-commerce system data diagram. Beacause of I using hibernate and XDoclet, I use the Class diagram instead of Data structure and ERP diagram. My strategy in J2EE system design is to clear the bussiness logic first, and design POJOs and their relations, finally, implement it with mature 3 or more tier web architecture.


posted @ 2007-02-27 18:25 hk2000c 阅读(257) | 评论 (0)编辑 收藏

完成的包括网站Menu,花了很大的工夫才把他整合到Struts Menu当中去。不过仍然在FF和Opera中有部分背景缺失,留待以后解决。
网站favicon完成,网上生成的。使用fw不行。
接下去的任务就是完成基础CMS系统以及撰写推广计划。
准备推出网站整站设计开发,企业在线形象策划,企业客户Royalty管理,企业在线服务推广等项目。
终于向着理念前进了。
感觉很累,前一阵每天工作到凌晨4点,今天要好好睡觉了。

posted @ 2007-02-25 15:07 hk2000c 阅读(157) | 评论 (0)编辑 收藏

仅列出标题
共11页: First 上一页 3 4 5 6 7 8 9 10 11 下一页