This just to get you started on building a basic coldspring application. This topic is beaten to death everywhere else, and I’ve just posted this to do my part in cluttering the web (and to give me a starting point in learning CS). For more documentation go here.
An example of a simple Coldspring application that has a USER bean and a USERSERVICE class.
The Application.cfc file:1: <!--- Run when application starts up --->
2: <cffunction name="onApplicationStart" returnType="boolean"> 3: <cfset default_properties = structNew() />4: <cfset default_properties['default_username'] = "Anang" />
5: 6: <cfset coldspringConfig = 'config/coldspring.xml' />
7: <cfset beanFactory = CreateObject('component', 'coldspring.beans.DefaultXmlBeanFactory').init(defaultproperties=default_properties) />
8: <cfset beanFactory.loadBeans(coldspringConfig) /> 9: 10: <cfset userService = beanFactory.getBean('userService') />
11: 12: <cfreturn true />
13: </cffunction>The ColdSpring XML file:1: <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
2: <beans>3: <bean id="user" class="LearnCS.app.user.UserBean">
4: <property name="Username">5: <value>${default_username}</value>
6: </property> 7: </bean> 8: 9: <bean id="userService" class="LearnCS.app.UserService">10: <property name="user">
11: <ref bean="user"/>
12: </property> 13: </bean> 14: </beans>The User bean and UserService class1: <cfcomponent name="User Bean">
2: <cfset variables._username = "" /> 3: 4: <cffunction name="init"> 5: <cfreturn this /> 6: </cffunction> 7: 8: <cffunction access="public" returntype="String" name="getUsername">
9: <cfreturn variables._username /> 10: </cffunction> 11: 12: <cffunction access="public" returntype="void" name="setUsername">
13: <cfargument name="username" type="String" required="true" />
14: <cfset variables._username = arguments.username /> 15: </cffunction> 16: </cfcomponent> 17: 18: 19: <cfcomponent name="User Service">
20: <cfset variables._instance = structNew() /> 21: <cffunction name="init"> 22: <cfreturn this /> 23: </cffunction> 24: 25: <cffunction access="public" returntype="LearnCS.app.user.UserBean" name="getUser">
26: <cfreturn variables._instance["user"] />
27: </cffunction> 28: 29: <cffunction access="public" returntype="void" name="setUser">
30: <cfargument name="userBean" type="LearnCS.app.user.UserBean" required="true" />
31: 32: <cfset variables._instance["user"] = arguments.userBean />
33: </cffunction> 34: </cfcomponent>The usage on Index.cfm 1: <h3>Learning ColdSpring</h3> 2: <cfdump var="#userService.getUser().getUsername()#" />
1 comment:
Thanks :)
--
http://www.miriadafilms.ru/ приобрести кино
для сайта aphatak.blogspot.com
Post a Comment