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

4

1 回答 1

2

您不应该在 getter 方法中做任何业务工作,而应该在 bean 的(后)构造函数中。

例如

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;
    }

}

这也带来了业务工作不会被不必要地多次调用的优势。

于 2011-10-27T11:56:49.880 回答