简体   繁体   English

PrimeFaces commandButton 不导航或更新

[英]PrimeFaces commandButton doesn't navigate or update

I'am using Primefaces to make my app a little bit more beautiful.我正在使用 Primefaces 使我的应用程序更漂亮一点。 I noticed that p:commandButton and h:commandButton don't work the same way.我注意到p:commandButtonh:commandButton工作方式不同。

The p:commandButton calls the method and nothing else hapens. p:commandButton调用该方法并且没有其他事情发生。 The h:commandButton calls the method and returns a navigation. h:commandButton调用该方法并返回导航。

I have got trouble with redirecting after pressing the login button when using p:commandButton .使用p:commandButton时按下登录按钮后重定向时遇到问题。 How to deal with that?怎么处理?


I do have an update parameter:我确实有一个更新参数:

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

<p:commandButton> needs one of the following to work correctly: <p:commandButton>需要以下其中一项才能正常工作:

  • the update attribute to list id's of components to re-render (for AJAX requests)用于列出要重新呈现的组件 ID 的update属性(对于 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.如果两者都没有,则该按钮默认会执行没有 UI 反馈的 AJAX 请求。

Additionally, I've had problems with neither option working when the surrounding <h:form> had an enctype attribute.此外,当周围的<h:form>具有enctype属性时,我遇到了两个选项都不起作用的问题。

I think what Cagatay ment was:我认为 Cagatay ment 是:

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更多信息可以在 primefaces 论坛中找到,例如在这个关于导航的讨论中

I hope that helped a bit...我希望这有点帮助...

如果您正在进行导航并且请求是使用 ajax 完成的,则必须使用重定向。

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".我正在使用 primefaces 和 primefaces mobile,并且在使用<p:commandButton>和 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>

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

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"/>
<h:commandButton 
                             styleClass="btn btn-primary-active upgrade" data-dismiss="modal" 
                             value="Upgrade Account" 
                             action="profile.do?faces-redirect=true&amp;tab=plan" 
                             oncomplete="$('#freeGiftModal').hide();" process="@this" partialSubmit="true" immediate="true"/>

I used the commandbutton to navigate to profile page, and its working fine for me.我使用命令按钮导航到个人资料页面,它对我来说工作正常。

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

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