论坛首页 Java企业应用论坛

关于webwqrk2中form提交是点击哪个提交按钮的判定

浏览 8608 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2004-07-14  
moxie 写道
引用

if(isCommand("logon"){}
if(isCommand("edit")){}

这样确实蛮直观的,但下面的做法也不错:
public class MyAction extends ActionSupport { 

    /** 
     * Action implementation 
     * 
     * Sets the message according to which button was pressed. 
     **/ 
    public String execute(); { 
        if (buttonOnePressed); { 
            message="You pressed the first button"; 
        } else if (buttonTwoPressed); { 
            message="You pressed the second button"; 
        } else { 
            return ERROR; 
        } 
        return SUCCES; 
    } 

    // Input parameters 
    private boolean buttonOnePressed=false; 
    private boolean buttonTwoPressed=false; 

    public void setButtonOnePressed(); { 
        this.buttonOnePressed = true; 
    } 


    public void setButtonTwoPressed(); { 
        this.buttonTwoPressed = true; 
    } 

    // Output parameters 

    private String message; 
    public String getMessage(); { 
        return message; 
    } 
}


但是这样的做法在最新的webwork2中用不了啊!
因为我的button /submit按钮value不可能是true or false啊
0 请登录后投票
   发表时间:2004-07-14  
引用

但是这样的做法在最新的webwork2中用不了啊!
因为我的button /submit按钮value不可能是true or false啊

它不会影响的button /submit按钮value,你的value是任何值都可以。注意:
public void setButtonOnePressed(); { 
        this.buttonOnePressed = true; 
    } 


    public void setButtonTwoPressed(); { 
        this.buttonTwoPressed = true; 
    } 


0 请登录后投票
   发表时间:2004-07-14  
哦,对!
这样也可行
这在我们谈论的是不同名字的时候是可以,如果是判断多个名字相同的submit,就不能用这样的方法来进行判断了.
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics