JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » AJAX討論區 » Java 與 Ajax  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 DWR init.parameter 問題
roytsang





發文: 620
積分: 1
於 2009-01-16 22:34 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的java class 是這樣的:
1
2
3
4
5
6
7
8
public MyClass(int parameter)
{
......
   public void m1()
   {
      .........
   }
}


請問如何用javascript call 這個constructor 呢?
因為不知道如何用javascript new 這個class ,所以在javascript 裡面
call MyClass.m1()出現error.


reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
koji

秒速5センチメートル

站長

發文: 8415
積分: 19
於 2009-01-16 23:43 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你給的code會不會有點怪?

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:DWR init.parameter 問題 [Re:roytsang]
roytsang





發文: 620
積分: 1
於 2009-01-17 13:02 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
為什麼有點怪呢?

reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
koji

秒速5センチメートル

站長

發文: 8415
積分: 19
於 2009-01-17 13:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你這是java code?
可以這樣寫嗎?
光編譯就過不了吧?

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:DWR init.parameter 問題 [Re:roytsang]
roytsang





發文: 620
積分: 1
於 2009-01-17 13:30 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
或者我這樣問,我有個class程式如下:
1
2
3
4
5
6
7
8
9
10
11
12
public class MyClass 
{
 public MyClass(int parameter)
 {
   ......(略)
 }
 public String getResult()
   {
      .........(略)
      return result;
   }
}


現在想經由dwr 用javascript call MyClass.getResult(),
請問要如何做呢?
dwr.xml 要怎樣設定呢?


roytsang edited on 2009-01-17 13:49
reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
ethan_victory





發文: 49
積分: 0
於 2009-01-17 14:01 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr//dwr20.dtd">
<dwr>
  <allow>
    <create creator="new" javascript="MyClass(請自定...)">
      <param name="class" value="MyClass(這個要package+class name喔)"/>
    </create>
  </allow>
</dwr>


reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
roytsang





發文: 620
積分: 1
於 2009-01-17 21:07 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
這樣的設定不行呀。

reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
kebin_liu

雲端決策系統

版主

發文: 1861
積分: 11
於 2009-01-17 21:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
先把這三篇看過再來。
http://www.javaworld.com.tw/jute/post/view?bid=49&id=165881&sty=1&tpg=1&age=0
http://www.javaworld.com.tw/jute/post/view?bid=49&id=166425&sty=1&tpg=2&age=0
http://www.javaworld.com.tw/jute/post/view?bid=49&id=167679&sty=1&tpg=1&age=0


reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
roytsang





發文: 620
積分: 1
於 2009-01-18 16:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
好!我放棄,我改程式:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class MyClass 
{
  public MyClass()
  {
    this(123);
  }
  public MyClass(int parameter)
  {
    ......(略)
  }
  public String getResult()
  {
    .........(略)
    return "456";
  }
}

跟著執行以下的web page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
  <title>第一個DWR程式</title>
  <script type='text/javascript' src='dwr/interface/MyClass.js'></script>
  <script type='text/javascript' src='dwr/engine.js'></script>
  <script type='text/javascript' src='dwr/util.js'></script>
</head>
<body>
<input id="user" type="text" />
<input type='button' value='哈囉' onclick='hello();' /> 
<div id="result"></div>
<script language="javascript">
function hello() {
    MyClass.getResult(callback);
    alert(dwr.util.getValue("result"));
}
 
function callback(msg) {
   dwr.util.setValue('result', msg);
}
</script>
</body>
</html>

"456" 當然成功地在DIV內顯示出來,可是在執行alert 時,alert 出來的值竟然是什麼都沒有,請問究竟發生什麼問題呢?
我只是想讀回MyClass.getResult()這個METHOD的RETURN VALUE 罷了,搞了半天仍然不成。


reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
kebin_liu

雲端決策系統

版主

發文: 1861
積分: 11
於 2009-01-18 21:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你根本沒搞懂什麼是非同步,看這篇。
http://directwebremoting.org/dwr/browser/engine/options

非同步時,callback不知道什麼時候會發生,所以緊接在後的
alert(dwr.util.getValue("result"));
不一定會在callback之後才顯示(通常一定比callback快),此時顯示的當然是原值。


reply to postreply to post
作者 Re:DWR init.parameter 問題 [Re:roytsang]
roytsang





發文: 620
積分: 1
於 2009-01-19 07:50 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
那我該知怎樣做了。

reply to postreply to post
» JWorld@TW »  AJAX討論區 » Java 與 Ajax

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8