It's always helpful to read the documentation, more specifically these lines (emphasis mine):
The method on which the PostConstruct annotation is applied MUST fulfill all of the following criteria - - The method MUST NOT have any parameters except in the case of EJB interceptors in which case it takes an InvocationC ontext object as defined by the EJB specification. - The return type of the method MUST be void. - The method MUST NOT throw a checked exception... (other requirements omitted)
So, at least the return type requirement is not met (we do not know whether your exceptions are checked or not, so I removed them in case they are, but in this case you do need to handle the exception in the method).
All in all, replace your method with
@PostConstruct
public void search() {
MemberDao dao=(MemberDao) Factory.getDao(ConfigReader.getConfig().getProperty("dao.member"));
members=dao.list(1, 10);
membersId=new int[members.size()];
for(int i=0;i<members.size();i++)
membersId[i]=members.get(i).getId();
}
Basing on your comment, your exception classes are checked exceptions. So you have to either introduce a try-catch block in your method, or let your exceptions inherit from RuntimeException
. If you choose the former way you can rethrow an unchecked exception like IllegalStateException
, or, for example, send a redirect in case it's not too late:
@PostConstruct
public void search() {
try {
MemberDao dao=(MemberDao) Factory.getDao(ConfigReader.getConfig().getProperty("dao.member"));
members=dao.list(1, 10);
membersId=new int[members.size()];
for(int i=0;i<members.size();i++)
membersId[i]=members.get(i).getId();
} catch(DaoImplNotFoundException dinf) {
//option one
throw new IllegalStateException("Something went wrong.");
//option two
FacesContext.getCurrentInstance().getExternalContext().redirect("/error.xhtml");
} //other exception types
}