File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Checking for error messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Checking for error messages" Watch "Checking for error messages" New topic
Author

Checking for error messages

Mike Halford
Ranch Hand

Joined: Jul 13, 2005
Posts: 31
Hi,
I've tried using


To redirect to an error page if a ValidationException is thrown. This doesn't seem to work. So I want to check for any error messages on the page and then redirect the page. In Struts (ahh, those were the days, it all seemed so intuitive and less geeky ;)) I'd use - is there a Faces equivalent ?

[ March 26, 2007: Message edited by: Mike Halford ]
[ March 26, 2007: Message edited by: Mike Halford ]
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Originally posted by Mike Halford:
Hi,
I've tried using


To redirect to an error page if a ValidationException is thrown. This doesn't seem to work. So I want to check for any error messages on the page and then redirect the page. In Struts (ahh, those were the days, it all seemed so intuitive and less geeky ;)) I'd use - is there a Faces equivalent ?

[ March 26, 2007: Message edited by: Mike Halford ]

[ March 26, 2007: Message edited by: Mike Halford ]


In JSF this is the way i would do it

The First Step would be to write a custom Validator for any component you feel might throw errors




<validator>
<validator-id>TextValidator</validator-id>
<validator-class>com.javaranch.TextValidator</validator-class>
</validator>


write the validator Class


package com.javaranch;


import javax.faces.application.Application;
import javax.faces.application.NavigationHandler;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;


public class TextValidator implements Validator {
public void validate(FacesContext context, UIComponent component,
Object value) {

if(Condition) {
Application application=context.getApplication();
NavigationHandler navigation=application.getNavigationHandler();
navigation.handleNavigation(context,null,"error");//go to error page
}
}// end validate method
}

In the JSF page include your validator


<h:inputSecret rendered="true" required="true" redisplay="false" id="Password" >
<f:validator validatorId="TextValidator"/>
</h:inputSecret>
Mike Halford
Ranch Hand

Joined: Jul 13, 2005
Posts: 31
Thanks ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking for error messages
 
Similar Threads
configuring error pages in DD
error page in web.xml
How to handle JSP exceptions declaratively
Websphere v6.1 question
IBM Http Server : Unable to redirect to custom error page