电话号码:在JSF 2 setPropertyActionListener:的commandButton不执行˚F [英] p:commandButton doesn't execute f:setPropertyActionListener in JSF 2

查看:192
本文介绍了电话号码:在JSF 2 setPropertyActionListener:的commandButton不执行˚F的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我JSF2和PrimeFaces工作,我想转到另一个页面,这个按钮:

I work with JSF2 and PrimeFaces and I want to go to another page with this button:

<p:column>
    <h:commandButton action="userCommand" value="list of commands" >
        <f:setPropertyActionListener value="#{car}" target="#{userController.u1}" />  
    </h:commandButton>
</p:column>

在目标页面我使用 userController.u1 的一些信息,但&LT; F:setPropertyActionListener&GT; 标签似乎并没有被执行。

On the target page I use some information from userController.u1, but the <f:setPropertyActionListener> tag doesn't seem to be executed.

我从而得到以下异常:

java.lang.NullPointerException

在回应阿尔扬,感谢您的详细答复,但我认为是已经实例化的另一种方法来做到这一点,而是采用了新的managedBean正如我在我的问题一样,我用一个(sessionScoped)和然后我把它叫做新构造检索值,

In response to Arjan, thank you for your detailed response, but I think there is another method to do this, instead of using a new managedBean as I did in my question, I use one (sessionScoped) that is already instantiated and then I called it in the new constructor to retrieve the value,

你怎么找到这个解决方案?你能帮我从新managedBean的构造函数中调用其他managedBean?

How do you find this solution? Can you help me to call the other managedBean from the constructor of the new managedBean?

由于我测试的:

  ELContext elContext = context.getELContext();
    Application application = context.getApplication();
    String userid = (String) application.evaluateValueExpressionGet(context,
            "#{userBean.userid}", String.class);

但我有背景的问题。你有什么想法?

but I have a problem with "context". Do you have any idea?

推荐答案

这取决于你如何设置为相应的导航规则 userCommand 和/或<范围code> UserController的如果这是要在所有的工作。

It depends on how you setup the corresponding navigation rule for userCommand and/or the scope of userController if this is going to work at all.

动作监听器设置在bean导航发生前的值。如果导航导致重定向发生,那么这个bean必须在一个范围内,这重定向后可用。而无需添加任何额外的范围,这将是应用范围和会话范围。

The action listener sets a value in the bean before navigation happens. If the navigation causes a redirect to happen, then the bean must be in a scope that's available after this redirect. Without having added any additional scopes, this would be the application scope and session scope.

如果这个bean是请求范围或视图范围内,你的价值就会在对应的请求绿豆重定向发生之前设置。重定向后到新的一页新的请求完成,因此新的请求范围或新的视图范围内启动。这意味着你的价值将会丢失。

If the bean was in request scope or view scope, your value would be set in the bean corresponding to the request before the redirect took place. After the redirect a new request to a new page is done, and hence a new request scope or new view scope starts. This means your value will be lost.

使用应用程序范围或会话范围将在理论上解决这个问题,但你会遇到大问题,如果您的应用程序有多个用户(很有可能),或者如果一个用户有多个窗口/选项卡中打开。

Using the application scope or session scope would theoretically fix this, but you would run into major problems if your application had multiple users (very likely) or if a single user has multiple windows/tabs open.

如果您的导航规则的的使用重定向,它实际上应该工作。现在的问题是,你会从患上一URL背后的问题:在浏览器的地址栏中仍然会显示旧的页面

In case your navigation rule does not use a redirect, it should actually work. The problem now is that you'll be suffering from the "one URL behind problem": the address bar of the browser will still show the old page.

因为你没有真正执行任何动作,只是想去一个新的页面,更好的方法是使用直接链接到该页面的&LT; H:按钮&GT; &LT; H:链接&GT; 并提供如果说汽车作为一个参数

Since you're not really executing any action and just want to go to a new page, a better approach is to link directly to that page using an <h:button> or <h:link> and provide the If of said car as a parameter.

这将发出一个GET请求,其中有一个是可收藏的额外好处。如果你在做后重定向的东西,它也将开始有更好的表现。在目标页面,你就必须要ppared的参数转换回到车里实例$ P $。为此,您可以使用&LT; F:。viewParam&GT; 标签

This will issue a GET request, which has the additional benefit of being bookmarkable. If you were doing the Post-Redirect thing, it will also initially perform better. On the target page, you do have to be prepared to convert the parameter back into the car instance. For this you can use the <f:viewParam> tag.

举例链接:

<p:column>
    <h:button outcome="userCommand" value="list of commands">
        <f:param name="car_id" value="#{car.id}"/>
    </h:Button>
</p:column>

举例目标页面:

<f:metadata>
    <f:viewParam name="car_id" value="#{userController.u1}" converter="#{carConverter}" />    
</f:metadata>

有关这方面的一个工作示例请参见<一个href=\"http://$c$c.google.com/p/javaee6-crud-example/source/browse/WebContent/index.xhtml?name=default\"相对=nofollow>的index.xhtml 和<一个href=\"http://$c$c.google.com/p/javaee6-crud-example/source/browse/WebContent/user_edit.xhtml?name=default\"相对=nofollow> user_edit.xhtml 在这个例如CRUD应用程序。

For a working example of this see index.xhtml and user_edit.xhtml in this example CRUD application.

这篇关于电话号码:在JSF 2 setPropertyActionListener:的commandButton不执行˚F的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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