繁体   English   中英

无法从primefaces页面向Java bean类发送参数

[英]Unsuccessfully sending a parameter from primefaces page to java bean class

我想将一个对象作为参数从.xhtml页面发送到Java类。

我有以下素面dataGrid:

<p:dataGrid value="#{userRequestBean.userActiveRequests}" var="userActiveRequest">
            <h:panelGrid>

                <h:commandButton value="Cancel" actionListener="#{userRequestBean.cancelRequest()}">
                    <f:setPropertyActionListener target="#{userRequestBean.request}"
                            value="${userActiveRequest}" />
                </h:commandButton>

            </h:panelGrid>
        </p:dataGrid> 

在我的豆子里,我有:

@ManagedBean(name = "userRequestBean")
@SessionScoped
public class UserRequestBean implements Serializable {
    private TRequest request = new TRequest(); // plus get and set methods

    public void cancelRequest (){
        System.out.println("Author name: " + request.geId());
    }
}

但是当我按下按钮时,它让我感到NullPointerException。 任何想法我怎么能意识到这一点? 提前致谢!

 <h:commandButton value="Cancel" actionListener="#{userRequestBean.cancelRequest()}">
                    <f:setPropertyActionListener target="#{userRequestBean.request}"
                            value="${userActiveRequest}" />
                </h:commandButton>

为什么要使用standard-jsf commandButton而不是Primefaces按钮。

使其用作:

 <p:commandButton value="Cancel" action="#{userRequestBean.cancelRequest()}">
                    <f:setPropertyActionListener target="#{userRequestBean.request}"
                            value="${userActiveRequest}" />
                </p:commandButton>

我们做了什么 ?

  • 更改为Primefaces commandButton
  • 使用action而不是actionListenerActionListener方法应将ActionEvent作为parameter )。

我希望以上帮助。

尝试使用@ViewScoped而不是@SessionScoped。 您还必须为托管bean的request属性创建getter和setter。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM