【问题标题】:Default Command not work默认命令不起作用
【发布时间】:2014-03-02 20:27:53
【问题描述】:

Hej 我的登录表单有问题。 在表单中我有 2 个动作:

<p:commandButton id="newUserButton" action="newUser" immediate="true" icon="ui->icon-plus" value="Zarejestruj się" />
<p:commandButton id="submitButton" action="confirmSignIn" update="logPanelGrid,messages" icon="ui-icon-check" value="Zaloguj się" />

当我在键盘上按 Enter 时,我想自动选择第二个动作“confirmSignIn”

当我点击进入应用程序执行操作“newUser”

我尝试使用默认命令。

我添加了一些类:

package org.primefaces.examples.view;

public class DefaultCommandBean 
{  

    private String btn;

public DefaultCommandBean(String btn) {
        this.btn = btn;
    }

public String getBtn() {  
    return btn;  
}  

public void setBtn(String btn) {  
    this.btn = btn;  
}  

}

我在 xhtml 中添加了一些行:

<p:defaultCommand target="#{defaultCommandBean.btn}" />

当我重新启动 tomcat 时,我得到:

SEVERE: Error Rendering View[/WEB-INF/flows/main/welcome.xhtml]
java.lang.IllegalArgumentException: ""

谁能知道哪里有问题?我不知道;/

【问题讨论】:

    标签: jsf jakarta-ee primefaces


    【解决方案1】:

    首先:您的action 属性需要一个EL 表达式。而不是

    <p:commandButton ... action="newUser" ... />
    <p:commandButton ... action="confirmSignIn" ... />
    
    
    <p:commandButton ... action="#{yourBean.newUser}" ... />
    <p:commandButton ... action="#{yourBean.confirmSignIn}" ... />
    

    yourBean 需要newUserconfirmSignIn 方法。

    其次:检查DefaultCommandBean中String btn的值,是newUserButtonsubmitButton的值吗?

    【讨论】:

    • 谢谢回答我已经用其他方式修复它。我将添加到 xhtml 的线女巫更改为: 并且它的工作正常:)
    • 使用硬编码的目标字符串,您不能在运行时更改defaultCommand。我以为这就是你想要的。
    • 现在写我只想针对 2 个动作中的 1 个。但是谢谢你的建议,当我的项目长大时,我会需要它 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    相关资源
    最近更新 更多