六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 45|回复: 0

sx:submit 详解

[复制链接]

升级  20%

2

主题

2

主题

2

主题

童生

Rank: 1

积分
10
 楼主| 发表于 2013-1-23 02:14:22 | 显示全部楼层 |阅读模式
1.引入struts2-dojo-plugin-2.1.8.1.jar

2.代码说明
    下面是struts文档中的代码:
 
 
<%@ taglib prefix="s" uri="/struts-tags" %><%@ taglib prefix="sx" uri="/struts-dojo-tags" %><html><head>    <title>Ajax Examples</title>    <sx:head /></head>    加载dojo标签库和加载dojo的js库
 
 
 
<s:form id="form" action="AjaxTest">     <input type="textbox" name="data">     <sx:submit /></s:form> 
    简单的例子
 
<script type="text/javascript">dojo.event.topic.subscribe("/before", function(event, widget){    alert('inside a topic event. before request');    //event: set event.cancel = true; , to cancel request    //widget: widget that published the topic});</script><sx:submit beforeNotifyTopics="/before" /> 
    加载上面这一段,则submit按钮按下之后,先执行alert,然后才会提交 。
    一般来讲submit都是和事件(onclick)关联的,如果终止提交动作,则使用

event.cancel = true;    例如我们通常会对页面内容做个前台的校验,如果校验同过才提交到后台,
    我们可以在上面的topic(/before)中加入校验的代码,如果发现错误就可以
    用event.cancel = true;终止程序执行。
 
 
 
<script type="text/javascript">dojo.event.topic.subscribe("/after", function(data, request, widget){    alert('inside a topic event. after request');    //data : text returned from request(the html)    //request: XMLHttpRequest object    //widget: widget that published the topic});</script><sx:submit afterNotifyTopics="/after"/> 
 
    加载上面这一段,则submit按钮按下,response收到之后才会执行alert。
    这里的request我的理解是中间页面提交request。
 
 
 
3. 注意点、问题点
   总是提示dojo的对象没有定义
   试一下 http://mydomain/struts/dojo/struts_dojo.js
   是不是打得开,如果不行估计要想点办法了。。。。。 对策正在调查中 :(
 
 
 
 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表