Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jsf 2 - ExternalContext.dispatch() not working

On p:ajax call,listener invokes method which contains

     FacesContext.getCurrentInstance().getExternalContext().dispatch("/uri.jsf");  

doesn't work. Ive set a break point on the line and it remains at the same point on execution.It doesn't move forward, I ve got to restart server to run the application again.

    FacesContext.getCurrentInstance().getExternalContext().redirect("/uri.jsf");

redirection works perfectly fine. But i want page forward which is dispatch to navigate to another page.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The ExternalContext#dispatch() does not support ajax requests. It causes JSF to render the HTML output of the given resource which can't be understood by the JavaScript ajax engine. The ajax request has to return a special XML response which can be understood by the JavaScript ajax engine.

The ExternalContext#redirect() supports ajax requests. It will automatically return a special XML response instructing the JavaScript ajax engine to invoke a window.location call on the given URL (you can find an XML example in this answer).

You have 2 options:

  1. Make it a non-ajax request.
  2. Perform a normal JSF navigation.

Making a non-ajax request is most likely not an option for <p:ajax>. In that case, performing a normal navigation is really your only option.

FacesContext context = FacesContext.getCurrentInstance();
context.getApplication().getNavigationHandler().handleNavigation(context, null, "/uri.jsf");

It will in case of ajax requests automatically force an render="@all" with the new content.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...