Hi,
I've tried the following in my pages.xml:
<exception class="java.lang.Exception">
<redirect view-id="#{facesContext.viewRoot.viewId}">
<message>test</message>
</redirect>
</exception>
I get a null pointer exception because the viewId is null, and a 500 page error. When I debug seam around the point where the null pointer exception occurs, I see that the EL I have evaluates to null, then it attempts to load the current view ID in code exactly the same way (calling FacesContext.currentInstance().getViewRoot().getViewID()). Again it evaluates to null and hence the null pointer exception.
How do I do what I am trying to achieve, displaying errors on the current view with an error message rather than redirecting to some global error page?
Cheers
What version of Seam?
Read about how to report a bug.
version 2.0.2.sp1
Seam 2.0.2 does do FacesContext.currentInstance().getViewRoot().getViewID() (check the code) if you don't specify the view-id - I've seen people report this doesn't work before, so please file an issue in JIRA with a simple seam-gen based example that just shows the problem.
Thanks
Read about how to report a bug.
public String getViewId() {
String servletPath = ( (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest() ).getServletPath();
return servletPath.substring(0, servletPath.lastIndexOf('.')) + Pages.getSuffix();
}
and use EL that refers to your own method: #{mySeamBean.viewId}. Looking at the seam code this is what it tries to do if the viewId you supply is null as the facescontext is no longer available. However this code isn't called because it checks for null rather than an empty string.
Thanks! JBSEAM-3190
Read about how to report a bug.
Code below is not working, because facesContext is MockFacesContext and it's viewId property is null.
`
<exception class="java.lang.Exception">
<redirect view-id="#{facesContext.viewRoot.viewId}">
<message>test</message>
</redirect>
</exception>
`
Try to use this code
`
...
<redirect view-id="#{facesContext.externalContext.requestServletPath}">
...
`
it works fine.
class SomeHome extends EntityHome<Some>{
public String persist() {
try {
some stuff
}catch(Exception myException){
addFacesMessage();
return null;
}
}
}
and in page.xml
<navigation from-action="#{someHome.persist}">
<rule>
<end-conversation/>
<render view-id="/some.xhtml"/>
</rule>
</navigation>
key is to return null and then add the <rule> tag in page.xml with render view-id instead of redirect view-id .