无法使PrimeFaces RequestContext.getCurrentInstance()。openDialog()工作

时间:2014-12-18 00:53:19

标签: jsf jsf-2 primefaces

无法使PrimeFaces RequestContext.getCurrentInstance().openDialog()正常工作。我将示例代码从primefaces展示中取出,但我从来没有打开过对话框。我在Wildfly 8.2.0.Final上运行PF 5.1。有什么想法吗?

DFView.java

@ManagedBean(name = "dfView")
public class DFView {

    public void chooseCar() {
        RequestContext.getCurrentInstance().openDialog("selectCar");
    }

    public void onCarChosen(SelectEvent event) {
        Car car = (Car) event.getObject();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Car Selected", "Id:" + car.getId());
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}

和我的dialogplay.xhtml

<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" template="/WEB-INF/templates/template.xhtml"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui">
  <ui:define name="body">
<h:form>
    <p:growl id="growl" showDetail="true" />

    <p:commandButton value="Select Car" icon="ui-icon-extlink" actionListener="#{dfView.chooseCar}">
        <p:ajax event="dialogReturn" listener="#{dfView.onCarChosen}" update="growl" />
    </p:commandButton>
</h:form>
  </ui:define>
</ui:composition>

1 个答案:

答案 0 :(得分:10)

请检查“selectCar”是faces-config中引用dialogplay.xhtml的有效导航规则。 (或使用wittakarn的解决方案,这更容易)

如果是这种情况,请检查您的faces-config是否包含对话框架配置(Primefaces 5.1用户指南中的页面519,很容易错过):

<application>
  <action-listener>
    org.primefaces.application.DialogActionListener
  </action-listener>
  <navigation-handler>
    org.primefaces.application.DialogNavigationHandler
  </navigation-handler>
  <view-handler>
    org.primefaces.application.DialogViewHandler
  </view-handler>
</application>