1

I have a (IBM)jsf 1.2 application where i try to show errors at the top of the page using a faces managed bean, my problem is if an error is created in one of a component getter and i write it to the faces managed bean (error bean),the errorbean is not rendered properly and the reason is the jsf calls the getter of the error bean before the other component that is writing to the error bean.

so how can i force jsf to rerender the whole page again or specify which competent to be rendered firs.

Thanks

1 Answers1

2

You should not do any business job in a getter method, but rather in the (post)constructor of the bean.

E.g.

public class Bean {

    private List<Entity> entities;

    @EJB
    private EntityService entityService;

    @PostConstruct
    public void init() {
        try {
            entities = entityService.list();
        } catch (Exception e) {
            String message = String format("Failed to retrieve entities: %s", e.getMessage());
            FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null);
            FacesContext.getCurrentInstance().addMessage(null, facesMessage);
            e.printStackTrace();
        }
    }

    public List<Entity> getEntities() {
        return entities;
    }

}

This also gives the advantage that the business job isn't unnecessarily called multiple times.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555