How to decide whether FeedbackPanel is visible or not after IModel.load()?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to decide whether FeedbackPanel is visible or not after IModel.load()?

alex.espunto
I've a ContentPanel with a FeedbackPanel and a table (DataView). The ContentPanel pulls the model in the constructor. If an error occurs durring the service call an error message is written in the ContentPanels feedbackMessageModel. Dependent whether an error occurs or not the FeedbackPanel (and border) will or won't be visible. The corresponding code is displayed below.

My problem is that the onConfigure-method of the FeedbackPanel is processed before the load-method of the ComponentAwareModel is called. When the onConfigure-method decides whether the FeedbackPanel is visible or not, there are no errors. Only after this the model-load-method is called and errorhandling happens.

Is there a way to keep the model within the DataView and decide nevertheless in the onConfigure-method about the Feedback-Panels visibility?

public class UserOverviewPanel{
  @SpringBean
  private UserService userService;
  IModel model = new ComponentAwareModel<List<UserHeaderDto>>(this) {
    protected List<UserHeaderDto> loadService() {
      return userService.getAllUsersForHeaderView();
    }
  };
  DataView<UserHeaderDto> dataView = new DataView<UserHeaderDto>("userRow", new
    ModelDataProvider<UserHeaderDto>(model)) {
    public void populateItem(final Item<UserHeaderDto> item) {
      UserHeaderDto user = item.getModelObject();
      item.setModel(new CompoundPropertyModel<UserHeaderDto>(user));
      item.add(new Label("id"));
      ...
    }
  }
  add(dataView);
  add(new FeedbackPanel(){
    protected void onConfigure() {
      List<FeedbackMessage> feedbackMsgs = feedback.getFeedbackMessagesModel().getObject();
      if (feedbackMsgs != null && feedbackMsgs.size() > 0) {
        this.setVisibilityAllowed(true);
      } else {
        this.setVisibilityAllowed(false);
      }
      super.onConfigure();
    }
  }
}

public class ComponentAwareModel<T> extends LoadableDetachableModel<T> {
  private Component comp;
  public ComponentAwareModel(Component comp) {
    this.comp = comp;
  }
  protected T load() {
    try{
      return callService();
    }
    catch(Exception ex){
      comp.error(ex.getMessage());
      return null;
    }
  }
};