Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

suppress ConverterException messages from displaying in browser

 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nirvan

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

Reply asap

Karanjeet Singh
 
B Nirvan
Ranch Hand
Posts: 82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okey, thats good

Thanks for Updating.

Regards

Karanjeet Singh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic