Struts 2与AJAX(第二部分)(六)

42 篇文章 0 订阅

接着新建tree-close.ftl文件,内容和原版的一样,如下所示:

<#if parameters.label?exists></div></#if></div>清单11 src/template/realajax/tree-close.ftl

再下来就应该是将theme应用到<s:tree />,如下代码所示:

<%@ page language="java" contentType="text/html; charset=utf-8"
     pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!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">
    <head>
        <title>Struts 2 AJAX - More Tree</title>
        <s:head theme="ajax" debug="true" />
        <script type="text/javascript">
        /* <![CDATA[ */
            function treeNodeSelected(arg) {
                 alert(arg.source.title + ' selected');
             }
                
             dojo.addOnLoad(function() {                
                var t = dojo.widget.byId('appFiles');                
                var s = t.selector;                
                 dojo.event.connect(s, 'select', 'treeNodeSelected');
             });    
        /* ]]> */    
        </script>
    </head>
    <body>
        <h2>
             AJAX Tree Example
        </h2>
        <div style="float:left; margin-right: 50px;">
            <s:tree id="appFiles" theme="realajax" rootNode="root"
                 nodeTitleProperty="name" nodeIdProperty="id"
                 childCollectionProperty="children" value="absolutePath" />
        </div>
    </body>
</html>清单12 WebContent/AjaxTreeTheme.jsp

上述代码中<s:tree />的用法,除了theme改为“realajax”和多了value="absolutePath"外,几乎和静态树中的一样。

为了不影响前一个例子,我们为该JSP文件配置类型相同的Action,如下代码所示:

        <action name="AjaxTreeTheme" class="tutorial.AjaxTreeAction">
            <result>AjaxTreeTheme.jsp</result>
            <result name="ajax" type="freemarker">AjaxTree.ftl</result>
        </action>清单13 src/struts.xml配置片段

发布运行应用程序,在浏览器地址栏中键入http://localhost:8080/Struts2_Ajax2/AjaxTreeTheme.action,结果如图2所示。

总结

通过上述例子,大家知道Struts 2 的AJAX 标志是基于Dojo控件开发的,所以如果大家希望熟练地使用这些标志,最好去了解一下Dojo。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值