Skip to content

Instantly share code, notes, and snippets.

@CedricL46
Created February 20, 2018 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricL46/be6fe5f7f7dd3dcac412948bd1447e76 to your computer and use it in GitHub Desktop.
Save CedricL46/be6fe5f7f7dd3dcac412948bd1447e76 to your computer and use it in GitHub Desktop.
How to fix a java.lang.IllegalStateException: Cannot forward a response that is already committed on a jsf action with sendRedirect/forward in ADF
//ADF : jsf :
<h:commandButton id="myBtnId"
action="#{myBean.doLogic}"
value="click me"
type="submit"
actionListener="#{myBean.forwardAfterLogic}"/>
//ADF : myBean :
public String doLogic() {
//Add business logic that will be executed first when the button is clicked
}
public void forwardAfterLogic(ActionEvent actionEvent) {
// Add forward logic here ...
//This will be execute after doLogic() in the second part of the lifecycle
//example:
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse) ectx.getResponse();
String url = ectx.getRequestContextPath() + "/pageToRedirectTo";
try {
response.sendRedirect(url);
FacesContext.getCurrentInstance().responseComplete();
} catch (IOException e) {
//Do something and add trace
} catch (IllegalStateException il) {
//Do something and add trace
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment