Created
February 20, 2018 08:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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