f:setPropertyActionListener设置空值而不是预期值 [英] f:setPropertyActionListener sets null value instead of intended value

查看:73
本文介绍了f:setPropertyActionListener设置空值而不是预期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的看法是:

<h:commandLink value="BookFlight" action="#{bookSeatController.doLoginOrCC}">
   <f:setPropertyActionListener target="#{bookSeatController.flightNumber}" 
                  value="#{flightInfoController.flight.number}" />
</h:commandLink>

我的二传手是:

public void setFlightNumber(String flightNumber) {
   this.flightNumber = flightNumber;
}

当我使用调试器时,在设置器中得到的是nullflightNumber.但是,如果我将视图更改为以下内容:

When I use the debugger I get a flightNumber of null in the setter. However, if I change the view to the following:

<h:commandLink value="BookFlight" action="#{bookSeatController.doLoginOrCC}">
   <f:setPropertyActionListener target="#{bookSeatController.flightNumber}" 
                  value="122334" />
</h:commandLink>

flightNumber属性设置为122334.这是怎么引起的,以及如何解决该问题以设置预期值而不是null?

The flightNumber property is set to 122334. How is this caused and how can I solve it to set the intended value instead of null?

推荐答案

如果#{flightInfoController.flight.number}是请求范围的,那么它在处理表单提交的请求期间必须保留与flight完全相同的flight显示表单的请求.这必须在bean的(后)构造函数中发生.

If the #{flightInfoController.flight.number} is request scoped, then it has to preserve exactly the same flight in during the request of processing the form submit as it was during the request of displaying the form. This has to happen in the bean's (post)constructor.

如果这不是一个选项,因为它取决于某些基于请求的变量,那么最好的选择是将bean放在视图范围内(但是我仍然假设您的bean设计正确,不会起作用吸气剂中的任何业务/预装工作.

If that is not an option, because it depends on some request based variables, then your best bet is to put the bean in the view scope instead (I however still assume that your bean is properly designed that it doesn't do any business/preloading job in getters).

如果不是将bean放入视图范围的选择,那么您需要将其作为一个完全有价值的请求参数传递.您可以通过<f:param>来做到这一点.

If putting the bean in the view scope is in turn not an option, then you'd need to pass it as a fullworthy request parameter instead. You can do that by <f:param>.

<h:commandLink value="BookFlight" action="#{bookSeatController.doLoginOrCC}">
   <f:param name="flightNumber" value="#{flightInfoController.flight.number}" />
</h:commandLink>

您可以让JSF在BookSeatController中通过@ManagedProperty或在当前视图中通过<f:viewParam>进行设置.

You can let JSF set it by @ManagedProperty in the BookSeatController or by <f:viewParam> in the current view.

  • How can I pass selected row to commandLink inside dataTable?
  • ViewParam vs @ManagedProperty(value = "#{param.id}")

这篇关于f:setPropertyActionListener设置空值而不是预期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆