SFD2008 in GuiZhou University Eddan

Wednesday Apr 22, 2009

          There are some steps to use Spring label library.

          1、down load library:spring-form.tld,spring.tld.you can down these files from Spring official page:http://www.springsource.org/download,then put them under the direction of /WEB-INF.

          2、Configure lable lib 

          Write following configure into web.xml file bewteen element of <web-app> and </web-app>:

   <jsp-config>
        <taglib>
            <taglib-uri>/spring</taglib-uri>
            <taglib-location>/WEB-INF/spring.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/spring-form</taglib-uri>
            <taglib-location>/WEB-INF/spring-form.tld</taglib-location>
        </taglib>
    </jsp-config>

           3、configure Spring resource lib

           write following context into applicationContext.xml file.

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename">
            <value>com.demo.spring.resources.ApplicationResources</value>
        </property>
    </bean>

           u should pls pay attention to the value element .eg :com.demo.spring.resources.ApplicationResources,all your properties will be created under com.demo.spring.resources,and your properties will named begin as ApplicationResources,if you don't do as this rule ,IDE will show error message:No message found under code 'register.page.title' for locale 'zh_CN' when you run your project.

          4、configure resource files

         u can create ApplicationResources.properties,ApplicationResources_zh_CN.properties,ApplicationResources_en.properties under page com.demo.spring.resources.

       eg.ApplicationResources.properties file content:

#login.jsp
login.page.title=Login Window
login.page.username=Username
login.page.password=Password
login.page.login=Login
login.page.register=Register

#register.jsp
register.page.title=Register Window
register.page.username=Username
register.page.password1=Password
register.page.password2=Confirm Password
register.page.email=Email
register.page.register=Register
register.page.back=Back

#welcome.jsp
welcome.page.title=Login is successful!
welcome.page.username=Welcome,
welcome.page.logout=Logout

      Resource file's name have a format:"default resource file name"+"_country"+"_language.properties",default resource file name is the value u defined in applicationContext.xml ,such as ths eg we defined  is ApplicationResources

     5、label words in u jsp page

     eg.login.jsp

     firstly ,add <%@taglib prefix="spring" uri="/spring" %> into your jsp page,be careful,/spring is the direction u defined in web.xml as step 1.

    secondly,add label for jsp.as blowing:

    <form name="form1" action="login.do" method="POST">
            <table border="1" width="200">
                    <tr>
                        <td colspan="2"><spring:message code="login.page.title" /></td>
                    </tr>
                    <tr>
                        <td><spring:message code="login.page.username" /></td>
                        <td><input type="text" name="username" size="10"></td>
                    </tr>
                    <tr>
                        <td><spring:message code="login.page.password" /></td>
                        <td><input type="password" name="password" size="10"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submit" value='<spring:message code="login.page.login" />'>
                            <a href="register.do?method=init"><spring:message code="login.page.register" /></a>
                        </td>
                    </tr>
            </table>

           In this eg,i use <spring:message>label.There are also three labels:<spring:hasBindErrors>,<spring:bind>,<spring:transform> in lable library.

Reference:《开发者突击:java web主流框架整合开发 j2ee+Structs+Hibernate+Spring》 刘中兵编著  ,电子工业出版社

          There are some steps to use Spring label library.

          1、down load library:spring-form.tld,spring.tld.you can down these files from Spring official page:http://www.springsource.org/download,then put them under the direction of /WEB-INF.

          2、Configure lable lib 

          Write following configure into web.xml file bewteen element of <web-app> and </web-app>:

   <jsp-config>
        <taglib>
            <taglib-uri>/spring</taglib-uri>
            <taglib-location>/WEB-INF/spring.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/spring-form</taglib-uri>
            <taglib-location>/WEB-INF/spring-form.tld</taglib-location>
        </taglib>
    </jsp-config>

           3、configure Spring resource lib

           write following context into applicationContext.xml file.

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename">
            <value>com.demo.spring.resources.ApplicationResources</value>
        </property>
    </bean>

           u should pls pay attention of the value element .eg :com.demo.spring.resources.ApplicationResources,all your properties will be created under com.demo.spring.resources,and your properties will named begin as ApplicationResources,if you don't do as this rule ,IDE will show error message:No message found under code 'register.page.title' for locale 'zh_CN' when you run your project.

          4、configure resource files

         u can create ApplicationResources.properties,ApplicationResources_zh_CN.properties,ApplicationResources_en.properties under page com.demo.spring.resources.

       eg.ApplicationResources.properties file content:

#login.jsp
login.page.title=Login Window
login.page.username=Username
login.page.password=Password
login.page.login=Login
login.page.register=Register

#register.jsp
register.page.title=Register Window
register.page.username=Username
register.page.password1=Password
register.page.password2=Confirm Password
register.page.email=Email
register.page.register=Register
register.page.back=Back

#welcome.jsp
welcome.page.title=Login is successful!
welcome.page.username=Welcome,
welcome.page.logout=Logout

      Resource file's name have a format:"default resource file name"+"_country"+"_language.properties",default resource file name is the value u defined in applicationContext.xml ,such as ths eg we defined  is ApplicationResources

     5、label words in u jsp page

     eg.login.jsp

     firstly ,add <%@taglib prefix="spring" uri="/spring" %> in your jsp page,be careful,/spring is the direction u defined in web.xml as step 1.

    secondly,add label for jsp.as blowing:

    <form name="form1" action="login.do" method="POST">
            <table border="1" width="200">
                    <tr>
                        <td colspan="2"><spring:message code="login.page.title" /></td>
                    </tr>
                    <tr>
                        <td><spring:message code="login.page.username" /></td>
                        <td><input type="text" name="username" size="10"></td>
                    </tr>
                    <tr>
                        <td><spring:message code="login.page.password" /></td>
                        <td><input type="password" name="password" size="10"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submit" value='<spring:message code="login.page.login" />'>
                            <a href="register.do?method=init"><spring:message code="login.page.register" /></a>
                        </td>
                    </tr>
            </table>

           In this eg,i use <spring:message>label.There are also three labels:<spring:hasBindErrors>,<spring:bind>,<spring:transform> in lable library.

Reference:《开发者突击:java web主流框架整合开发 j2ee+Structs+Hibernate+Spring》 刘中兵编著  ,电子工业出版社

Friday Apr 17, 2009

    There is a good image which directly shows Spring Integration Model .

    

     Open netbeans,choose new "project--javaWeb",then click "next" twice,at the last step,select "Spring Web MVC" frame.Now,a simple spring frame has been built in your netbeans IDE.

     This time ,i practise to develop a login demo.First of all , build a jsp page named login.jsp and write following code in this page.

    <body>
        <form name="form1" action="login.do" method="POST">
            <table border="1" width="200">
                    <tr>
                        <td colspan="2">登录窗口</td>
                    </tr>
                    <tr>
                        <td>用户名</td>
                        <td><input type="text" name="username" size="10"></td>
                    </tr>
                    <tr>
                        <td>密码</td>
                        <td><input type="password" name="password" size="10"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submit" value="登录"><a href="register.do?method=init">注册新用户</a></td>
                    </tr>
            </table>

        </form>
    </body>

   besides,create a form class which is a orginal JavaBean class and contains relative variable  of  login.jsp.

public class LoginForm {
    private String username;
    private String password;

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    } 
}

     For the more,create a new login control named LoginAction.java .

 protected ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response,Object command,BindException errors) throws Exception{
        LoginForm loginForm=(LoginForm)command;

        if(isValid(loginForm)){
            request.getSession().setAttribute(Constants.USERNAME_KEY,loginForm.getUsername());
            return new ModelAndView(getSuccessView());
        }else{
            Map modle=errors.getModel();
            modle.put("loginForm", loginForm);
            return new ModelAndView(getFormView(),modle);
        }
    }

    private boolean isValid(LoginForm loginForm) {
        if(loginForm.getUsername().equals("admin") || loginForm.getPassword().equals("admin")){
            return true;
        }else{
            return false;
        }
    }

 At last,configure controller mapping and controller.

   controller mapping

<bean id="loginMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/login.do">loginAction</prop>
            </props>
        </property>
    </bean>

controller

    <bean id="loginAction"
    class="com.demo.spring.actions.LoginAction">
        <property name="commandClass">
            <value>com.demo.spring.forms.LoginForm</value>
        </property>
        <!-- return the failure page -->
        <property name="formView">
            <value>login</value>
        </property>
        <!--return the success page-->
        <property name="successView">
            <value>welcome</value>
        </property>
    </bean>

    Enjoy your spring tour~~

   Reference:

http://www.ibm.com/developerworks/cn/java/wa-spring1/spring_framework.gif

《开发者突击:java web主流框架整合开发 j2ee+Structs+Hibernate+Spring》 刘中兵编著  ,电子工业出版社

  

Thursday Apr 16, 2009

Today(Apr.15th),i hold a techtalk about JavaFX.

Before i start event formally,i let some students to play games which were developed by JavaFX.
Because a great of audiences have never heard JavaFX ,i showed a demo which can open and close QingMingShangHe image slowly and let them take questions to listen my lecture. When entering lecture formally,firstly,i introduced what is JavaFX and why we choose to use JavaFX .Then,i told audience how to develop the demo i played at the beginning of the event which attracted attendances' mind most. Lastly,i told them JavaFX competition rule .

The audience joined in our activity spanned from graduate students in grade three to freshman. After this activity over ,some of them copied my demo and intend to take part in this competition.
Lastly ,i will thanks Joey Shen's help,his demo emailed to me is the most highlights of my events. Thanks workers from Federation of GuiZhou University Corporate Union who report our event ,Thanks again!

Below is an agenda for the event at GuiZhou University:
19:00 – 19:40 , wei guan
JavaFX introduction and demo show
19:40 – 19:50, wei guan
JavaFX competition intrduce and OSUM introduction
19:50 -- 20:10, wei guan
Q & A

During the first session,i sent pens,Tshirts and opensolaris's CDs and minibooks to audiences by asking questions. After the last session,I sent left gifts to them.

Saturday Apr 11, 2009

   On Apr.10th,i held a meeting to discuss two problems.

  One was the activities' themes from Apr. to Jun.After talking together with some memebers in our association,we decided to hold a lecture of "JavaFX" in Apr.,two salon respectively "Sunspot" in May and "Web" in Jun.

  The other was how to expand propaganda in our shool.some people suggested to post posters in their first floor of dormitory ,and the others advised to post activity information in every classes's QQ group.