40

我正在使用 Primefaces 让我的应用程序更漂亮一些。我注意到了这一点p:commandButtonh:commandButton但工作方式不同。

p:commandButton调用该方法,没有其他任何事情发生。h:commandButton调用该方法并返回一个导航。

使用时按登录按钮后重定向时遇到问题p:commandButton。如何处理?


我确实有一个更新参数:

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

6 回答 6

53

<p:commandButton>需要以下其中一项才能正常工作:

  • update列出要重新渲染的组件的 id 的属性(对于 AJAX 请求)
  • ajax="false"进行正常的非 ajax 提交的属性。

如果您两者都没有,则该按钮默认执行 AJAX 请求而没有 UI 反馈。

<h:form>此外,当周围有一个enctype属性时,我遇到了两个选项都不起作用的问题。

于 2011-01-09T13:04:32.823 回答
31

我认为 Cagatay ment 是:

导航页面:

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

作品(重定向页面):

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

作品(重定向页面)

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

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

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

更多信息可以在 primefaces 论坛中找到,例如在这个关于导航的讨论中

我希望这有点帮助...

于 2011-05-03T10:11:01.280 回答
8

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

于 2011-01-09T17:48:31.783 回答
4

我有个类似的问题。

我正在使用 primefaces 和 primefaces mobile,当使用 <p:commandButton>ajax="false" 和 action="find.xhtml?faces-redirect=true" 时,Firefox 中的导航失败。

我可以让它在 Firefox 中也能工作的唯一方法是使用<h:commandButton>

<h:commandButton value="#{msg.find}" process="find" 
                     action="find.xhtml?faces-redirect=true" />
于 2012-07-05T13:54:41.650 回答
0

上述解决方案都不适合我。你仍然可以使用简单的 javascript

<p:commandButton onclick="window.location.href =home.xhtml"
                    style="height: 20px" type="button" title="title" icon="ui-icon-transferthick-e-w"/>
于 2018-04-25T09:59:31.483 回答
0
<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"/>

我使用命令按钮导航到个人资料页面,它对我来说工作正常。

于 2018-11-11T07:43:48.383 回答