Package org.apache.wicket.model

Examples of org.apache.wicket.model.IModel


   * Test that testing if a component is on the ajax response can handle if the response is
   * encoded.
   */
  public void testAssertComponentOnAjaxResponse_encoding()
  {
    final IModel labelModel = new IModel()
    {
      private static final long serialVersionUID = 1L;

      private String value;

      public Object getObject()
      {
        return value;
      }

      public void setObject(Object object)
      {
        value = (String)object;
      }

      public void detach()
      {
      }
    };

    labelModel.setObject("Label 1");
    final Label label = new Label(MockPageWithLinkAndLabel.LABEL_ID, labelModel);
    label.setOutputMarkupId(true);

    final Page page = new MockPageWithLinkAndLabel();
    AjaxLink ajaxLink = new AjaxLink(MockPageWithLinkAndLabel.LINK_ID)
    {
      private static final long serialVersionUID = 1L;

      public void onClick(AjaxRequestTarget target)
      {
        labelModel.setObject("Label which needs encoding: [] ][");
        target.addComponent(label);
      }
    };
    ajaxLink.setOutputMarkupId(true);

View Full Code Here


      throw new IllegalArgumentException("argument [tabs] cannot be null");
    }

    this.tabs = tabs;

    final IModel tabCount = new AbstractReadOnlyModel()
    {
      private static final long serialVersionUID = 1L;

      public Object getObject()
      {
View Full Code Here

   *
   * @return The model
   */
  public final IModel getModel()
  {
    IModel model = getModelImpl();
    // If model is null
    if (model == null)
    {
      // give subclass a chance to lazy-init model
      model = initModel();
View Full Code Here

   *
   * @return The backing model object
   */
  public final Object getModelObject()
  {
    final IModel model = getModel();
    if (model != null)
    {
      // Get model value for this component.
      return model.getObject();
    }
    else
    {
      return null;
    }
View Full Code Here

   * @return True if the given component's model is the same as this component's model.
   */
  public final boolean sameInnermostModel(final IModel model)
  {
    // Get the two models
    IModel thisModel = getModel();
    IModel thatModel = model;

    // If both models are non-null they could be the same
    if (thisModel != null && thatModel != null)
    {
      return getInnermostModel(thisModel) == getInnermostModel(thatModel);
View Full Code Here

   *            The model
   * @return This
   */
  public Component setModel(final IModel model)
  {
    IModel prevModel = getModelImpl();
    // Detach current model
    if (prevModel != null)
    {
      prevModel.detach();
    }

    if (prevModel instanceof IWrapModel)
    {
      prevModel = ((IWrapModel)prevModel).getWrappedModel();
View Full Code Here

   *            The object to set
   * @return This
   */
  public final Component setModelObject(final Object object)
  {
    final IModel model = getModel();

    // Check whether anything can be set at all
    if (model == null)
    {
      throw new IllegalStateException(
        "Attempt to set model object on null model of component: " + getPageRelativePath());
    }

    // Check authorization
    if (!isActionAuthorized(ENABLE))
    {
      throw new UnauthorizedActionException(this, ENABLE);
    }

    // Check whether this will result in an actual change
    if (!getModelComparator().compare(this, object))
    {
      modelChanging();
      model.setObject(object);
      modelChanged();
    }

    return this;
  }
View Full Code Here

  /**
   * Detaches the model for this component if it is detachable.
   */
  protected void detachModel()
  {
    IModel model = getModelImpl();
    if (model != null)
    {
      model.detach();
    }
    // also detach the wrapped model of a component assigned wrap (not
    // inherited)
    if (model instanceof IWrapModel && !getFlag(FLAG_INHERITABLE_MODEL))
    {
View Full Code Here

   *            The model
   * @return The innermost (most nested) model
   */
  protected final IModel getInnermostModel(final IModel model)
  {
    IModel nested = model;
    while (nested != null && nested instanceof IWrapModel)
    {
      final IModel next = ((IWrapModel)nested).getWrappedModel();
      if (nested == next)
      {
        throw new WicketRuntimeException("Model for " + nested + " is self-referential");
      }
      nested = next;
View Full Code Here

    {
      // Get model
      // Don't call the getModel() that could initialize many inbetween
      // completely useless models.
      // IModel model = current.getModel();
      IModel model = current.getModelImpl();

      if (model instanceof IWrapModel && !(model instanceof IComponentInheritedModel))
      {
        model = ((IWrapModel)model).getWrappedModel();
      }
View Full Code Here

TOP

Related Classes of org.apache.wicket.model.IModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.