2014년 7월 23일 수요일

Javascript에서 callback함수를 이용해서 form의 특정 Object에 대한 validation 확인 후 특정 메시지를 alert창으로 알려준 뒤에 해당 Object에 포커싱을 두는 예제.

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">

<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>callback_sample_01</title>

<meta name="viewport" content="width=device-width; initial-scale=1.0">

<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<script type="text/javascript">
var each = function(arr, callback) {
      for(i = 0; i < arr.length; i++) {
          callback.prototype = arr[i];
          new callback(i);
      }
     
      document.getElementById('txtName').focus();
};

onload=function() {
    var test = [ { name : 'a' }, { name : 'b' }, { name : 'c' } ];

      each(test, function(index) {
          alert(index + " = " + this.name);
      });
};
</script>
</head>

<body>
<div>
<header>
<h1>callback_sample_01</h1>
</header>
<nav>
<p>
<a href="/">Home</a>
</p>
<p>
<a href="/contact">Contact</a>
<input type="text" id="txtName" name="name"/>
</p>
</nav>

<div>

</div>

<footer>
<p>
&copy; Copyright  by
</p>
</footer>
</div>
</body>
</html>

2014년 7월 8일 화요일

Spring Framework & MyBatis 3 설정

applicationContext.xml
-------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>

<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <beans:property name="maxUploadSize">
        <beans:value>20000000</beans:value>
    </beans:property>
    <beans:property name="uploadTempDir" ref="uploadDirResource" />
</beans:bean>

<beans:bean id="uploadDirResource" class="org.springframework.core.io.FileSystemResource">
    <beans:constructor-arg>
        <beans:value>D:/Temp/fileUpload/</beans:value>
    </beans:constructor-arg>
</beans:bean>
</beans:beans>


rootContext.xml
-------------------------------------------------------------
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<mvc:default-servlet-handler />
   
    <mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/*"/> 
<beans:bean id="checkInterceptor" class="com.test.LogonInterceptor"/> 
</mvc:interceptor>
</mvc:interceptors>
<context:component-scan base-package="com.test" />
<beans:bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <beans:property name="alwaysUseFullPath" value="true"/>
</beans:bean>
<beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
   <beans:property name="alwaysUseFullPath" value="true"/>
</beans:bean>

</beans:beans>


commonContext.xml
-------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
       
<!-- ========================= Properties DEFINITIONS =============================== -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/application.properties</value>
</list>
</property>
</bean>  
<!-- ========================= RESOURCE DEFINITIONS =============================== -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>

<bean id="messageSourceAccessor" class="org.springframework.context.support.MessageSourceAccessor">
<constructor-arg>
<ref local="messageSource" />
</constructor-arg>
</bean> 
</beans>


databaseContext.xml
---------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans   
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context.xsd">

<!-- bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc.xxxPool</value>
</property>
</bean-->
<context:component-scan base-package="com.test.service">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="${database.driver}"
p:url="${database.url}"
p:username="${database.username}" p:password="${database.password}" />

<!-- transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- enable component scanning (beware that this does not enable mapper scanning!) -->    
    <context:component-scan base-package="com.test.service" /> 
<!-- enable autowire -->
    <context:annotation-config />
     
<!-- enable transaction demarcation with annotations -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
    <!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.test.domain" />
<!-- property name="configLocation" value="springbook/learningtest/spring/mybatis/mybatis-config.xml" /-->
<!-- property name="mapperLocations" value="classpath:sqlmap/*-sqlmap.xml" /-->
</bean>
<!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.test.persistence" />
    </bean>
<!--
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
-->
</beans>