aspose file tools*
The moose likes JSF and the fly likes suppress ConverterException messages from displaying in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "suppress ConverterException messages from displaying in browser" Watch "suppress ConverterException messages from displaying in browser" New topic
Author

suppress ConverterException messages from displaying in browser

B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
I have written a custom Converter which throws ConverterException if the conversion could not be performed. Throwing the ConverterException results in display of default message on the browser (even though I don't have h:messages on my jsf page). How do I suppress the default message from getting displayed in the browser.

regards,
Nirvan.
Karanjit Singh
Greenhorn

Joined: Oct 17, 2010
Posts: 15
Hi Nirvan

I am not very sure about this, but you can give it a try. What I think, the exception message by default taking the Id of the page. You just need to divert this exception message to any id which doesn't exist. So, it will be automatically suppressed.

If you can provide some code, it would be easier for me to fetch the solution.

Hope this Helps!

Regards

Karanjeet Singh
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
Thanks for the reply.
I am not sure about the point you made. Here is my code.

.xhtml


p: tags refer to Primefaces framework.

Converter.


Here the faces message that I am explictly generating in getAsObject(FacesContext context, UIComponent component, String value) gets displayed by the <p:messages> tag at the top of the xhtml page. But there is also another message that gets displayed at the bottom of the xhtml page when I throw the ConverterException. I want to get rid of that message.

regards,
Nirvan.
Karanjit Singh
Greenhorn

Joined: Oct 17, 2010
Posts: 15
Hi Nirvan

Just give a try to this. I think, this will surely solve your problem.

if (state == null) {
try
{
String msg = "Another User has either modified or deleted the State. " +
"Re-Initiate transaction";
FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_WARN, msg, null);
FacesContext.getCurrentInstance().addMessage(null, fmsg);
}
catch(Exception e)
{
throw new ConverterException(e);
}
} else {
return state;
}


You just need to place your code within try block and exception in catch block. Hope this Helps.

Regards

Karanjeet Singh
Karanjit Singh
Greenhorn

Joined: Oct 17, 2010
Posts: 15
Hi Nirvan

I would like to ask, about the above code, if it worked or not.

Reply asap

Karanjeet Singh
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
Sorry for not updating you, but your code will never throw ConverterException. I am not getting any exception in the try block and ConverterException is explictly thrown by me. I modified my code to look as follows. Basically, I passed the faces message to the ConverterException() constructor and now the code runs fine.

Thanks very much for your effort.

regards,
Nirvan.
Karanjit Singh
Greenhorn

Joined: Oct 17, 2010
Posts: 15
okey, thats good

Thanks for Updating.

Regards

Karanjeet Singh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: suppress ConverterException messages from displaying in browser