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

» JWorld@TW » Web Framework » Struts  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 請教各位先進們struts2的extends ActionSupport問題...
ethan_victory





發文: 49
積分: 0
於 2008-12-11 15:20 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
小弟在做doubleselect的練習.
在url中直接輸入accountitem.action,為的是讓execute()被執行,而將所要的資料做好,以利jsp中doubleselect來使用.

如果我沒extends ActionSupport,那麼AccountItemAction-validation.xml就起不了作用,雖然,畫面顯示我預期要的結果..


若extends AciontSupport後,一run了其url,就做了validation, 且execute()沒有進去


小弟,希望此個案可以, 1.進入action中的某個method, initial doubleselect要的資料
2.forward到jsp後,做CRUD功能,要validate.....
3.doubleselect可以同一行!!(平行顯示! google不到,所以來這兒請教請教)

不知那位先進,可否提供意見....感恩

AccountItemAction-validation.xml        
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE validators PUBLIC
        "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
        "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
 
<validators>
  <field name="accountItem.name">
    <field-validator type="requiredstring" short-circuit="true">
      <message>accountItem.name required</message>
    </field-validator>
  </field>
</validators>


AccountItemAction.java (沒extends ActionSupport)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package tw.self.struts2.action;
 
import java.util.*;
 
import com.opensymphony.xwork2.ActionSupport;
 
import tw.self.hibernate.pojo.*;
import tw.self.service.manager.impl.*;
 
public class AccountItemAction{
  private AccountItemManager accountItemManager;
  private AccountSubitemManager accountSubitemManager;
  private String itemKey;
  private String subitemKey;
  private List accountItemList;
  private List accountSubitemList;
  private AccountItem accountItem;
  private AccountSubitem accountSubitem;
  private Map accountSubitemMap;
  
  public String execute(){
    accountItemList = accountItemManager.findAll();
    //accountSubitemList = accountSubitemManager.findAll();
    accountSubitemMap = new HashMap();
    for(int i=0; i < accountItemList.size(); i++){
      accountItem = (AccountItem)accountItemList.get(i);
      accountSubitemList = accountSubitemManager.findByAccountItemId(accountItem.getId());
      if( accountSubitemList.size()>0){
        accountSubitemMap.put(accountItem.getId(), accountSubitemList);    
      }
    }
    return "input";
  }
  
  public String addItem(){
    accountItemManager.save(accountItem);
    return "none";
  }
  
  public String deleteItem(){
    accountItemManager.delete(Integer.valueOf(itemKey));
    return "none";
  }
  public String updateItem(){
    accountItem.setId(Integer.valueOf(itemKey));
    accountItemManager.update(accountItem);
    return "none";
  }
  
 
  public String addSubitem(){
    accountSubitem.setAccountItemId(Integer.valueOf(itemKey));
    accountSubitemManager.save(accountSubitem);
    return "none";
  }
 
  public String deleteSubitem(){
    accountSubitemManager.delete(Integer.valueOf(subitemKey));
    return "none";
  }
  public String updateSubitem(){
    accountSubitem.setId(Integer.valueOf(subitemKey));
    accountSubitemManager.update(accountSubitem);
    return "none";
  }
  
  public void setAccountItemManager(AccountItemManager accountItemManager) {
    this.accountItemManager = accountItemManager;
  }
 
  public void setAccountSubitemManager(AccountSubitemManager accountSubitemManager) {
    this.accountSubitemManager = accountSubitemManager;
  }
 
  public List getAccountItemList() {
    return accountItemList;
  }
 
  public void setAccountItemList(List accountItemList) {
    this.accountItemList = accountItemList;
  }
 
  public List getAccountSubitemList() {
    return accountSubitemList;
  }
 
  public AccountItem getAccountItem() {
    return accountItem;
  }
 
  public AccountSubitem getaccountSubitem() {
    return accountSubitem;
  }
 
  public String getItemKey() {
    return itemKey;
  }
 
  public void setSubitemKey(String subitemKey) {
    this.subitemKey = subitemKey;
  }
 
  public Map getAccountSubitemMap() {
    return accountSubitemMap;
  }
}


accountitem.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <script type="text/javascript">
      function selItemChange(){
      alert(document.getElementById("accountItemList").selectedIndex);
        var index = document.getElementById("accountItemList").selectedIndex;
        var flag = '0';
        if(index==-1){
          flag = '1';
        }
        if(flag=='1'){
          document.getElementById("updateItem").disabled=true;
          document.getElementById("deleteItem").disabled=true;
        }else{
          document.getElementById("updateItem").disabled=false;
          document.getElementById("deleteItem").disabled=false;
        }
      }
      function alterItemConfirm(){
        var index = document.getElementById("accountItemList").selectedIndex;
        document.getElementById("itemKey").value = document.getElementById("accountItemList")[index].value;
        if(confirm("alter data confirm? y/n")==true){
          return true;
        }
        return false;
      }
      
      function addSubitemConfirm(){
        var index = document.getElementById("accountItemList").selectedIndex;
        if(index==-1){
          alert('select an item first!');
          return false;
        }
        document.getElementById("itemKey").value = document.getElementById("accountItemList")[index].value;
        return true;
      }
      
    </script>
  </head>
  <body>
    <s:fielderror />
    <s:form action="accountitem" theme="simple">
      <s:hidden name="itemKey" id="itemKey"></s:hidden>
      <s:textfield name="accountItem.name"></s:textfield>
      <s:submit value="add" id="addItem" method="addItem" />
      <s:submit value="update" id="updateItem" method="updateItem"
        disabled="true" onclick="return alterItemConfirm();" />
      <s:submit value="delete" id="deleteItem" method="deleteItem"
        disabled="true" onclick="return alterItemConfirm();" />
 
      <s:hidden name="subitemKey" id="subitemKey"></s:hidden>
      <s:textfield name="accountSubitem.name"></s:textfield>
      <s:submit value="add" id="addSubitem" method="addSubitem"
        onclick="return addSubitemConfirm();" />
      <s:submit value="update" id="updateSubitem" method="updateSubitem"
        disabled="true" onclick="return alterSubitemConfirm();" />
      <s:submit value="delete" id="deleteSubitem" method="deleteSubitem"
        disabled="true" onclick="return alterSubitemConfirm();" />
      <br>
      <br>
      <s:doubleselect name="accountItemList" list="accountItemList"
        doubleName="accountSubitemList"
        doubleList="accountSubitemMap.get(id)" listValue="name"
        doubleListKey="id" doubleListValue="name" listKey="id"
        doubleSize="5" size="5" labelposition="left"
        cssStyle="float:lefttry" doubleCssStyle="float:lefttry" />
    </s:form>
  </body>
</html>


ethan_victory edited on 2008-12-11 15:25
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1087 請教各位先進們struts2的extends ActionSupport問題... ethan_victory 7289 2008-12-11 15:20
913 Re:請教各位先進們struts2的extends ActionSupport問題... prins 1825 2008-12-15 12:14
» JWorld@TW »  Web Framework » Struts

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8