Can't get PrimeFaces RequestContext.getCurrentInstance().openDialog() to work

烈酒焚心 提交于 2019-12-23 10:52:41

问题


Can't get PrimeFaces RequestContext.getCurrentInstance().openDialog() to work. I lifted the example code right out of the primefaces showcase, but I never get a dialog to open up. I'm using PF 5.1 running on Wildfly 8.2.0.Final. Any ideas what's up?

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);
    }
}

and my 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:


Please check "selectCar" is a valid Navigation Rule in your faces-config which references dialogplay.xhtml. (or use wittakarn's solution, which is easier)

If that is the Case, check that your faces-config contains the Dialog Framework Configuration (Page 519 in the Primefaces 5.1 Users Guid, it's easy to miss):

<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>


来源:https://stackoverflow.com/questions/27537499/cant-get-primefaces-requestcontext-getcurrentinstance-opendialog-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!