| Author |
getter method error handling
|
Harsha Chaitanya
Greenhorn
Joined: Jun 22, 2005
Posts: 10
|
|
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
Joined: Feb 05, 2003
Posts: 4725
|
|
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.
|
A good workman is known by his tools.
|
 |
 |
|
|
subject: getter method error handling
|
|
|