PrimeFaces commandButton不导航或更新。

时间:2022-03-04 17:21:20

I'am using Primefaces to make my app a little bit more beautiful. I noticed that p:commandButton and h:commandButton don't work the same way.

我使用的是黄金脸,让我的应用程序更漂亮一些。我注意到p:commandButton和h:commandButton的工作方式不一样。

The p:commandButton calls the method and nothing else hapens. The h:commandButton calls the method and returns a navigation.

命令按钮调用这个方法,其他的都没有。命令按钮调用该方法并返回一个导航。

I have got trouble with redirecting after pressing the login button when using p:commandButton. How to deal with that?

当使用p:commandButton时,按下登录按钮后,我就遇到了重定向的麻烦。如何应对呢?


I do have an update parameter:

我有一个更新参数:

<p:commandButton value="Login" action="#{login.login}" type="submit" update="msgs" />

5 个解决方案

#1


50  

<p:commandButton> needs one of the following to work correctly:

需要以下其中一个正确工作: 命令按钮>

  • the update attribute to list id's of components to re-render (for AJAX requests)
  • 更新属性列表id的组件以重新呈现(对于AJAX请求)
  • the attribute ajax="false" to make a normal, non-ajax submit.
  • 属性ajax="false",使其正常,非ajax提交。

If you have neither, the button does per default an AJAX request with no UI feedback.

如果没有,则该按钮默认为AJAX请求,没有UI反馈。

Additionally, I've had problems with neither option working when the surrounding <h:form> had an enctype attribute.

另外,当周围的

有一个enctype属性时,我在两个选项中都没有问题。

#2


27  

I think what Cagatay ment was:

我认为Cagatay是:

Does not navigate the page:

不浏览网页:

<p:commandButton action="home.xhtml" value="Go Home"/>

Works (redirects the page):

作品(重定向页面):

<p:commandButton action="home.xhtml?faces-redirect=true" value="Go Home"/>

Works (redirects the page)

作品(重定向页面)

<p:commandButton action="home?faces-redirect=true" value="Go Home"/>

if .xhtml is your default postfix defined in web.xml:

如果.xhtml是在web.xml中定义的默认后缀。

<context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

More info can be found in the primefaces forum, for example in this discussion about navigation

更多的信息可以在黄金面论坛找到,例如在关于导航的讨论中。

I hope that helped a bit...

我希望这能有所帮助……

#3


8  

You must use redirect if you are doing navigation and request is done with ajax.

如果您正在使用ajax进行导航和请求,则必须使用重定向。

#4


5  

I am having a similar problem.

我也有类似的问题。

I am using primefaces and primefaces mobile and the navigation fails in Firefox when using <p:commandButton> with ajax="false" and action="find.xhtml?faces-redirect=true".

当使用 和ajax="false"和action="find.xhtml?faces-redirect=true"时,我使用的是黄金脸和黄金脸移动,以及在Firefox中导航失败。

The only way I could make it work also in Firefox was by using <h:commandButton>:

我唯一能让它在Firefox中运行的方法是使用 :

<h:commandButton value="#{msg.find}" process="find" 
                     action="find.xhtml?faces-redirect=true" />

#5


0  

none of the above solution worked for me. You can still go for simple javascript

以上解决方案对我都不起作用。您仍然可以使用简单的javascript。

<p:commandButton onclick="window.location.href =home.xhtml"
                    style="height: 20px" type="button" title="title" icon="ui-icon-transferthick-e-w"/>

#1


50  

<p:commandButton> needs one of the following to work correctly:

需要以下其中一个正确工作: 命令按钮>

  • the update attribute to list id's of components to re-render (for AJAX requests)
  • 更新属性列表id的组件以重新呈现(对于AJAX请求)
  • the attribute ajax="false" to make a normal, non-ajax submit.
  • 属性ajax="false",使其正常,非ajax提交。

If you have neither, the button does per default an AJAX request with no UI feedback.

如果没有,则该按钮默认为AJAX请求,没有UI反馈。

Additionally, I've had problems with neither option working when the surrounding <h:form> had an enctype attribute.

另外,当周围的

有一个enctype属性时,我在两个选项中都没有问题。

#2


27  

I think what Cagatay ment was:

我认为Cagatay是:

Does not navigate the page:

不浏览网页:

<p:commandButton action="home.xhtml" value="Go Home"/>

Works (redirects the page):

作品(重定向页面):

<p:commandButton action="home.xhtml?faces-redirect=true" value="Go Home"/>

Works (redirects the page)

作品(重定向页面)

<p:commandButton action="home?faces-redirect=true" value="Go Home"/>

if .xhtml is your default postfix defined in web.xml:

如果.xhtml是在web.xml中定义的默认后缀。

<context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

More info can be found in the primefaces forum, for example in this discussion about navigation

更多的信息可以在黄金面论坛找到,例如在关于导航的讨论中。

I hope that helped a bit...

我希望这能有所帮助……

#3


8  

You must use redirect if you are doing navigation and request is done with ajax.

如果您正在使用ajax进行导航和请求,则必须使用重定向。

#4


5  

I am having a similar problem.

我也有类似的问题。

I am using primefaces and primefaces mobile and the navigation fails in Firefox when using <p:commandButton> with ajax="false" and action="find.xhtml?faces-redirect=true".

当使用 和ajax="false"和action="find.xhtml?faces-redirect=true"时,我使用的是黄金脸和黄金脸移动,以及在Firefox中导航失败。

The only way I could make it work also in Firefox was by using <h:commandButton>:

我唯一能让它在Firefox中运行的方法是使用 :

<h:commandButton value="#{msg.find}" process="find" 
                     action="find.xhtml?faces-redirect=true" />

#5


0  

none of the above solution worked for me. You can still go for simple javascript

以上解决方案对我都不起作用。您仍然可以使用简单的javascript。

<p:commandButton onclick="window.location.href =home.xhtml"
                    style="height: 20px" type="button" title="title" icon="ui-icon-transferthick-e-w"/>