webx学习笔记——在项目里新增一个页面

<span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; background-color: rgb(255, 255, 255);">WEBX是阿里巴巴的部框架,“就是把页面与Service之间的一些Servlet等公共的东西抽象出,提供相的服务以提高发效率(《接口之Webx介》—何晓峰 )”,可以看出,webx和统的servlet-action模式的HettpServlet基,其中的公用的抽象整理后,得到一个量的web发框架。</span>

由于项目需要,进行学习webx,先是看了一天的文档webx开发指南 ,还是一头雾水,然后就在网上查找资料,可是网上的大部分讲的也不是很清楚,于是就自己动手写了个hellworld,



package com.alibaba.webx.tutorial1.app2.module.screen.hi;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.dataresolver.Param;

public class Hi {
	public void execute(@Param("name") String name, Context context) {
        context.put("name", name);
    }
}


首先default.vm:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
#showHead ("My Simple Webx Application")
</head>

<body #bodyAttributes ()>

$screen_placeholder

<hr/>
<p>[<a href="$app2Link.setTarget("index")">Home</a>] [<a href="$app2Link">Dev Home</a>]</p>

</body>
</html>
其次hi.vm:

$page.setTitle("Hello, $name")
<p>Hello, $name!</p>

在就是app2/form.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:p="http://www.springframework.org/schema/p"
             xmlns:services="http://www.alibaba.com/schema/services"
             xmlns:fm-conditions="http://www.alibaba.com/schema/services/form/conditions"
             xmlns:fm-validators="http://www.alibaba.com/schema/services/form/validators"
             xsi:schemaLocation="
                 http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
                 http://www.alibaba.com/schema/services/form/conditions http://localhost:8080/schema/services-form-conditions.xsd
                 http://www.alibaba.com/schema/services/form/validators http://localhost:8080/schema/services-form-validators.xsd
                 http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
             ">

    <services:form postOnlyByDefault="true">
        <!--
          - ===============================================
          - 用来检查csrf token。
          - ===============================================
         -->
        <group name="csrfCheck">
            <field name="csrfToken">
                <fm-validators:csrf-validator>
                    <message>提交的数据已过期</message>
                </fm-validators:csrf-validator>
            </field>
        </group>
        <!--
          - ===============================================
          - Simple form
          - ===============================================
         -->
        <group name="register" extends="csrfCheck">
            <field name="name" displayName="你的名字">
                <fm-validators:required-validator>
                    <message>必须填写 ${displayName}</message>
                </fm-validators:required-validator>
            </field>
        </group>
    </services:form>

</beans:beans>

webx-app2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Webx Sub Context Configuration.  -->
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:p="http://www.springframework.org/schema/p"
             xmlns:services="http://www.alibaba.com/schema/services"
             xmlns:ml-adapters="http://www.alibaba.com/schema/services/module-loader/adapters"
             xmlns:ml-factories="http://www.alibaba.com/schema/services/module-loader/factories"
             xsi:schemaLocation="
                 http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
                 http://www.alibaba.com/schema/services/module-loader/adapters http://localhost:8080/schema/services-module-loader-adapters.xsd
                 http://www.alibaba.com/schema/services/module-loader/factories http://localhost:8080/schema/services-module-loader-factories.xsd
                 http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
             ">

    <!-- 支持${xxx}替换。 -->
    <services:property-placeholder>
        <property key="component">app2</property>
    </services:property-placeholder>

    <!-- 共享配置。 -->
    <beans:import resource="common/webx-component-and-root.xml" />
    <beans:import resource="common/webx-component.xml" />

    <!-- 执行管道。 -->
    <beans:import resource="common/pipeline.xml" />
    
    <!-- 表单验证。 -->
    <beans:import resource="app2/form.xml" />
    
    <!-- 装载模块。 -->
    <services:module-loader>
        <ml-factories:class-modules>
            <search-packages type="$1" packages="com.alibaba.webx.tutorial1.app2.module.*" />
        </ml-factories:class-modules>
    </services:module-loader>

</beans:beans>

uri.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:p="http://www.springframework.org/schema/p"
             xmlns:services="http://www.alibaba.com/schema/services"
             xmlns:uris="http://www.alibaba.com/schema/services/uris"
             xmlns:uri-interceptors="http://www.alibaba.com/schema/services/uris/interceptors"
             xsi:schemaLocation="
                 http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
                 http://www.alibaba.com/schema/services/uris http://localhost:8080/schema/services-uris.xsd
                 http://www.alibaba.com/schema/services/uris/interceptors http://localhost:8080/schema/services-uris-interceptors.xsd
                 http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
             ">

    <services:uris>
        <uris:uri id="server" requestAware="true" />

 		<uris:servlet-uri id="testServer" requestAware="true">
        	<servletPath>/</servletPath>
        </uris:servlet-uri>
        
        
        <uris:turbine-uri id="app1Link" exposed="true" extends="testServer">
            <componentPath>/</componentPath>
        </uris:turbine-uri>

        <uris:turbine-content-uri id="app1Content" exposed="true" extends="app1Link" />
        
        <uris:turbine-uri id="app2Link" exposed="true" extends="testServer">
            <componentPath>/</componentPath>
        </uris:turbine-uri>

        <uris:turbine-content-uri id="app2Content" exposed="true" extends="app2Link" />
        
     

    </services:uris>

</beans:beans>

这样你的helloworld就可以出来了,访问的链接是:http://localhost:8080/tutorial1/app2/hi/Hi.vm?name=%E5%88%98%E7%84%95%E8%B6%85



有问题一起可以进行交流:[email protected]





你可能感兴趣的:(webx学习笔记——在项目里新增一个页面)