I'm assuming that, being generated in the this event registration code
happens for all components that are added explicitly, but not for any
components that are added dynamically by me.

That assumption is wrong. Wicket will handle all event registration code 
automagically.
Updating a parent container via AjaxRequestHandler is sufficient.

Please create a quickstart if you think you've found a bug.

Best regards
Sven


On 01/21/2014 09:29 AM, Yoav Stern wrote:
My scenario: on an ajax event I replace a webmarkupContainer with one of my
components which have some wicket IBehaviorListener.

The problem is that this replace happen due to Ajax request, and the
behavior gets listed on don ready:

Wicket.Event.add(window, "domready", function(event) {
Wicket.Ajax.get({'u': 'some/url', 'c': 'linkId', 'e':'click'}));
   // ... more event registrations and onDomReady scripts
}

I'm assuming that, being generated in the this event registration code
happens for all components that are added explicitly, but not for any
components that are added dynamically by me.

How can I call the new container with the Ajax behaviors or change the
current implementation so the wicket Ajax behaviors would be called?


To be more precise I have a table with a filter which rendered by replacing
web markup container with this TableWithFilter. This scenario happens on
Ajax so when the page loaded by the first time the TableWithFilter does not
exist, it will appear on screen due to Ajax request that will occur

TableWithFilter contains AbstractFilterPanel which has a org.apache.wicket.
ajax.markup.html.form.AjaxButton which render the table by Ajax the button



/**
  * @author yoav stern
  *
  * @since Jun 24, 2013
  */
package com.betamedia.tp.backoffice.components.utils.absractfilter;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.injection.Injector;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.validation.IFormValidator;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.string.Strings;

import com.betamedia.common.logging.Log;
import com.betamedia.common.logging.LogFactory;
  import com.betamedia.common.search.criteria.SearchCriteria;
import com.betamedia.common.utils.BeanUtils;
import com.betamedia.tp.backoffice.components.grid.BMDefaultDataGrid;
import com.betamedia.tp.backoffice.utils.GridViewType;

public abstract class AbstractFilterPanel extends Panel {

private static final long serialVersionUID = 1L;
  private static final String SUBMIT_FILLTER_FORM = "submit_fillter_form";
  private static final String FORM = "form";
  protected Map<String, String> filterCritriaMap;
  @SuppressWarnings("unused")
  protected static final Log log = LogFactory.getLog();
  protected BMDefaultDataGrid tableTorender;

@SuppressWarnings("rawtypes")
  private SearchCriteria searchCriteria;
  @SuppressWarnings("rawtypes")
  private SearchCriteria preDefinedSearchCriteria;

protected final FeedbackPanel feedbackPanel;
  protected Form<Void> form;
  protected AjaxButton applyBtn;

public AbstractFilterPanel(String id, IModel<?> model, BMDefaultDataGrid
toRender, SearchCriteria searchCriteriaIn, FeedbackPanel feed) {
  super(id, model);
  this.tableTorender = toRender;
  this.setSearchCriteria(searchCriteriaIn);
  this.feedbackPanel = feed;

}

public AbstractFilterPanel(String id, BMDefaultDataGrid toRender,
SearchCriteria searchCriteriaIn, FeedbackPanel feed) {
  super(id);
  this.tableTorender = toRender;
  this.setSearchCriteria(searchCriteriaIn);
  this.feedbackPanel = feed;

}

public AbstractFilterPanel(String id, BMDefaultDataGrid toRender,
SearchCriteria searchCriteriaIn, FeedbackPanel feed,
  Map<String, String> fillterByList) {
  this(id, toRender, searchCriteriaIn, feed);
  this.filterCritriaMap = fillterByList;
  setFilterToModel();
  }

  /**
  * @param id
   * @param model
  * @param toRender
   * @param searchCriteriaIn
   * @param feed
  * @param fillterByList
   */
public AbstractFilterPanel(String id, IModel<?> model, BMDefaultDataGrid
toRender, SearchCriteria searchCriteriaIn, FeedbackPanel feed,
  Map<String, String> fillterByList) {
  this(id, model, toRender, searchCriteriaIn, feed);
  this.filterCritriaMap = fillterByList;
  setFilterToModel();

}

/**
  * @param fillterByList
   */
protected void setFilterToModel() {
  Object defaultModelObject = getDefaultModelObject();
  if (filterCritriaMap != null && !filterCritriaMap.isEmpty()) {
  Iterator<Entry<String, String>> it = filterCritriaMap.entrySet().iterator(
);
  while (it.hasNext()) {
  Map.Entry<String, String> pairs = it.next();
  insertLastPagePropertyToFilterModel(defaultModelObject, pairs);
  }
}
onFillterSubmited();
  if (getPreDefinedSearchCriteria() != null) {
  getSearchCriteria().and(getPreDefinedSearchCriteria());
  }
}

/**
   * this function decide how to insert property value to model , in most
   * cases would not be @override , unless the property which is string is an
   * instance in the model and therefore should be handled otherwise
   *
  * @param defaultModelObject
   * @param pairs
  */
  protected void insertLastPagePropertyToFilterModel(Object
defaultModelObject, Map.Entry<String, String> pairs) {
  BeanUtils.setProperty(defaultModelObject, pairs.getKey(), pairs.getValue(
));
  }

protected void init() {
  Injector.get().inject(this);
  setOutputMarkupId(true);
  form = new ExpendedForm(FORM);
  form.setOutputMarkupId(true);
  form.setMarkupId("fillter-form");
  add(form);
  form.add(new IFormValidator() {

private static final long serialVersionUID = 1L;

@Override
public void validate(Form<?> form) {
  String err = formValidation();
  if (!Strings.isEmpty(err)) {
  form.error(err);
  }
}

@Override
  public FormComponent<?>[] getDependentFormComponents() {
  return null;
  }
});
  form.add(doSubmit(tableTorender));
  }

  /**
  * @return
   */
protected String getInputToClearIds() {

return "";
  }

  /**
  * @param toRender
   * @return doSubmit button
   */
private AjaxButton doSubmit(final BMDefaultDataGrid toRender) {
  applyBtn = new AjaxButton(SUBMIT_FILLTER_FORM, form) {
  private static final long serialVersionUID = 1L;

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
  getSearchCriteria().clear();
  onFillterSubmited();
  if (getPreDefinedSearchCriteria() != null) {
  getSearchCriteria().and(getPreDefinedSearchCriteria());
  }
toRender.resetSelectedItems();
  target.add(toRender);
  toRender.resetCurrentPage();
  target.add(feedbackPanel);
  }

@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
  target.add(feedbackPanel);
  }

@Override
public boolean isEnabled() {
  return super.isEnabled() && isApplyBtnEnabled();

}

};
  applyBtn.setOutputMarkupId(true);
  return applyBtn;
  }

  /**
  * this method will be called when filter is submitted
   */

  public abstract void onFillterSubmited();

/**
   * this method will be called when on clear is submitted
  */
  public abstract void onClearSubmited();

protected boolean isClearVisible() {
  return true;
  }

protected String formValidation() {
  return null;
  }

private class ExpendedForm extends Form {

private static final long serialVersionUID = 1L;

public ExpendedForm(String id) {
  super(id);

}

@Override
public void renderHead(IHeaderResponse response) {
  super.renderHead(response);
  }

  }

protected boolean isApplyBtnEnabled() {
  return true;
  }

public SearchCriteria getPreDefinedSearchCriteria() {
  return preDefinedSearchCriteria;
  }

  public void setPreDefinedSearchCriteria(SearchCriteria
preDefinedSearchCriteria) {
  this.preDefinedSearchCriteria = preDefinedSearchCriteria;
  }

  /**
  * turn when coming from entity inVisibility the id of the entity came from
   *
  * @param cameFromGridView
   */
public void turnFilterCameFromInvisable(GridViewType cameFromGridView) {
  throw new UnsupportedOperationException("this filter does not suppo");
  }

  public SearchCriteria getSearchCriteria() {
  return searchCriteria;
  }

  public void setSearchCriteria(SearchCriteria searchCriteria) {
  this.searchCriteria = searchCriteria;
  }

}


and i do this also in order to make this filter showen :

public abstract class ShowHidePanel extends Panel {

private static final long serialVersionUID = 1L;
private boolean firstTimeLazyClicked = true;
  private WebMarkupContainer fatherContainer;
  private WebMarkupContainer lazySon;
  private boolean shouldExpend = false;
  private AjaxLink btn;
  private String showName;
  private String hideName;

public ShowHidePanel(String id, String hideName, String showName) {
  super(id);
  this.showName = showName;
  this.hideName = hideName;
  init();
  }

private void init() {
  fatherContainer = new WebMarkupContainer("fatherContainer");
  if (getId().equals("Audit_List")) {
  fatherContainer.add(new AttributeAppender("class", " audit_list"));
  }

add(new Label("ui-isopener", Model.of(showName)));
add(fatherContainer);
  lazySon = new WebMarkupContainer(getChildName());

fatherContainer.add(lazySon);
  fatherContainer.setOutputMarkupId(true);
  lazySon.setOutputMarkupId(true);
  fatherContainer.setOutputMarkupPlaceholderTag(true);
  lazySon.setOutputMarkupPlaceholderTag(true);

btn = new AjaxLink<Void>("panelOpener") {

private static final long serialVersionUID = 1L;

  @Override
public void onClick(AjaxRequestTarget target) {
  if (firstTimeLazyClicked) {
  final Component lazyContainer = getLazyContainer();
  lazySon.replaceWith(lazyContainer);
  fatherContainer.add(new AttributeAppender("class", " panel-opened"));
  btn.getParent().add((new AttributeAppender("class", " data-was-loaded")));
  btn.add((new AttributeAppender("class", " panel-is-opened ")));

/*i tried it now, according to sven meir suggestion , target.add(filter.
getForm()); but does not work ...
  final AbstractFilterPanel filter = ((TableWithFilter) lazyContainer).
getFilter();
  if (filter != null) {
  target.add(filter.getForm());
  }*/
}
firstTimeLazyClicked = false;
  shouldExpend = false;
}

};
btn.add(new AttributeAppender("value", getShowName()));
  btn.setOutputMarkupId(true);

Label linkLabel = new Label("linkLabel", new
AbstractReadOnlyModel<String>() {
  private static final long serialVersionUID = 1L;

  @Override
  public String getObject() {
  return getShowName();
  };
});
btn.add(linkLabel);
  new Label("hideName", new AbstractReadOnlyModel<String>() {
  private static final long serialVersionUID = 1L;

  @Override
  public String getObject() {
  return getShowName();
  };

});

// fatherContainer.add(hide);
  add(btn);
  new Label("showName", new AbstractReadOnlyModel<String>() {
  private static final long serialVersionUID = 1L;

  @Override
  public String getObject() {
  return getHideName();
  };
});
}

public String getChildName() {
  return "childName";
  }

@Override
public void renderHead(IHeaderResponse response) {
  super.renderHead(response);
  if (shouldExpend) {
  response.render(OnDomReadyHeaderItem.forScript("autoopen();"));
  shouldExpend = false;
}
  }

public abstract Component getLazyContainer();

protected String getShowName() {
  return showName;
  };

protected String getHideName() {

return hideName;
  }

public void setHideName(String hideName) {
  this.hideName = hideName;
  }

public void setShowName(String showName) {
  this.showName = showName;
  }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to