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 getter method error handling Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "getter method error handling" Watch "getter method error handling" New topic
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: getter method error handling
 
Similar Threads
Changing Combo box Model
Struts combo box
f:selectitems issue in jsf
Choose what appears in h:messages
h:message rendering