【发布时间】:2015-06-13 04:15:32
【问题描述】:
我希望当用户未登录时,单击Add To Card 按钮后,应该会出现Login 对话框。
这里是Book.xhtml:
<h:form>
<p:commandButton value="Add To Card"
actionListener="#{booksBean.orderBook()}"
class="QtyBtn">
<f:ajax execute="@form" rendered="@form"/>
</p:commandButton>
</h:form>
这是豆子:
@Component
@Scope("session")
public class BooksBean implements Serializable {
...
public void orderBook() {
...
if (currentUser == null) { // show the login dialog
RequestContext.getCurrentInstance().openDialog("Login");
}
但是Login.xhtml 没有打开。
【问题讨论】:
-
您不应将
<f:ajax>与<p:commandButton>混用。请改用<p:ajax process="@form" update="@form"/>。如果orderBook()被调用并且指定的条件被精确地满足,那么这应该可以工作,但是这应该使用 XHTML 以更直观的方式完成。 -
@Tiny
orderBook()现在被调用,我的问题只是在打开对话框。 -
@Tiny:
<p:commandButton>已经 ajaxified。根本不需要添加<*:ajax>。 -
@Kukeltje :当需要使用
process和update列出某些特定组件时,需要它(在这种情况下,process默认为@form但update默认为@none。因此,它需要明确,因为 OP 需要更新表单)。 -
@Kukeltje :是的,不需要。
<p:commandButton>本身具有process和update属性。抱歉,我忘了考虑它们。
标签: jsf jsf-2 primefaces dialog