• Post Reply Bookmark Topic Watch Topic
  • New Topic

getter method error handling  RSS feed

 
Harsha Chaitanya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i have <f:selectitem value="#{bean.details}" >

and backing bean has a getter method

public String getDetails() {
try{
/// get details may throw exceptions
}catch(Exception e){
FacesMessage facesMsg =new FacesMessage (FacesMessage.SEVERITY_ERROR ,"",e.getMessage());
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}
}

UI is not showing the exception messages. how can i show the exceptions on the screen

Through googling i found that we should not have dao access code in getter method. but i dont know where to move it. using the validator or action listener doesnot make any sense. further the combo box is populated based on other combo box. so i think i cant move this to constructor

can you please help me on this. any pointers to this will be helpful
regards,
Harsha
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new FacesMessage (FacesMessage.SEVERITY_ERROR ,"",e.getMessage());

You are setting your message summary to empty string. I believe the summary is the value that typically gets displayed.

Data access code is often best in its own special class called a DAO. You can see it in context of other J2EE patterns here and you can find more information about it by clicking on Data Access Object (DAO) in the chart. You don't have to use all of the other patterns in the chart to use DAOs in your application.

If you have an incredibly simple application, maybe creating DAO classes won't be incredibly beneficial. In most cases, however, the benefits through improved maintenance and separation of concerns makes using DAOs worth it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!