Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
19. Jul 2008, 13:01 CET | Link

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

7 Replies:
19. Jul 2008, 16:39 CET | Link

What version of Seam?

 

Read about how to report a bug.

19. Jul 2008, 18:40 CET | Link

version 2.0.2.sp1

20. Jul 2008, 11:23 CET | Link

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.

20. Jul 2008, 12:12 CET | Link
A work around is to have one of your own beans with the following:

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.
01. Oct 2008, 12:06 CET | Link
Hello, i had the same problem and i resolved it.

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.
01. Oct 2008, 15:27 CET | Link
I do it this way
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 .