Package org.apache.wicket.util.value

Examples of org.apache.wicket.util.value.Count


    // If the application wants component uses checked and
    // the response is not a redirect
    final IDebugSettings debugSettings = Application.get().getDebugSettings();
    if (debugSettings.getComponentUseCheck() && !getResponse().isRedirect())
    {
      final Count unrenderedComponents = new Count();
      final List unrenderedAutoComponents = new ArrayList();
      final StringBuffer buffer = new StringBuffer();
      renderedContainer.visitChildren(new IVisitor()
      {
        public Object component(final Component component)
        {
          // If component never rendered
          if (renderedComponents == null || !renderedComponents.contains(component))
          {
            // If auto component ...
            if (component.isAuto())
            {
              // Add to list of unrendered auto components to
              // delete below
              unrenderedAutoComponents.add(component);
            }
            else if (component.isVisibleInHierarchy())
            {
              // Increase number of unrendered components
              unrenderedComponents.increment();

              // Add to explanatory string to buffer
              buffer.append(Integer.toString(unrenderedComponents.getCount()) + ". " +
                  component + "\n");
              String metadata = (String)component
                  .getMetaData(Component.CONSTRUCTED_AT_KEY);
              if (metadata != null)
              {
                buffer.append(metadata);
              }
              metadata = (String)component.getMetaData(Component.ADDED_AT_KEY);
              if (metadata != null)
              {
                buffer.append(metadata);
              }
            }
            else
            {
              // if the component is not visible in hierarchy we
              // should not visit its children since they are also
              // not visible
              return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
            }
          }
          return CONTINUE_TRAVERSAL;
        }
      });

      // Remove any unrendered auto components since versioning couldn't
      // do it. We can't remove the component in the above visitChildren
      // callback because we're traversing the list at that time.
      for (int i = 0; i < unrenderedAutoComponents.size(); i++)
      {
        ((Component)unrenderedAutoComponents.get(i)).remove();
      }

      // Throw exception if any errors were found
      if (unrenderedComponents.getCount() > 0)
      {
        // Get rid of set
        renderedComponents = null;

        // Throw exception
View Full Code Here


    // If the application wants component uses checked and
    // the response is not a redirect
    final IDebugSettings debugSettings = Application.get().getDebugSettings();
    if (debugSettings.getComponentUseCheck() && !getResponse().isRedirect())
    {
      final Count unrenderedComponents = new Count();
      final List unrenderedAutoComponents = new ArrayList();
      final StringBuffer buffer = new StringBuffer();
      renderedContainer.visitChildren(new IVisitor()
      {
        public Object component(final Component component)
        {
          // If component never rendered
          if (renderedComponents == null || !renderedComponents.contains(component))
          {
            // If auto component ...
            if (component.isAuto())
            {
              // Add to list of unrendered auto components to
              // delete below
              unrenderedAutoComponents.add(component);
            }
            else if (component.isVisibleInHierarchy())
            {
              // Increase number of unrendered components
              unrenderedComponents.increment();

              // Add to explanatory string to buffer
              buffer.append(Integer.toString(unrenderedComponents.getCount()) + ". "
                  + component + "\n");
              String metadata = (String)component
                  .getMetaData(Component.CONSTRUCTED_AT_KEY);
              if (metadata != null)
              {
                buffer.append(metadata);
              }
              metadata = (String)component.getMetaData(Component.ADDED_AT_KEY);
              if (metadata != null)
              {
                buffer.append(metadata);
              }
            }
            else
            {
              // if the component is not visible in hierarchy we
              // should not visit its children since they are also
              // not visible
              return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
            }
          }
          return CONTINUE_TRAVERSAL;
        }
      });

      // Remove any unrendered auto components since versioning couldn't
      // do it. We can't remove the component in the above visitChildren
      // callback because we're traversing the list at that time.
      for (int i = 0; i < unrenderedAutoComponents.size(); i++)
      {
        ((Component)unrenderedAutoComponents.get(i)).remove();
      }

      // Throw exception if any errors were found
      if (unrenderedComponents.getCount() > 0)
      {
        // Get rid of set
        renderedComponents = null;

        // Throw exception
View Full Code Here

  public LinkPage()
  {
    // power to the annonymous classes!

    // first create a simple value holder object
    final Count count1 = new Count();

    // add a link which, when clicked, increases our counter when a link is clicked, its onClick
    // method is called
    Link link1 = new Link("link1")
    {
      @Override
      public void onClick()
      {
        count1.increment();
      }
    };
    add(link1);

    // add a counter label to the link so that we can display it in the body of the link
    link1.add(new Label("label1", new Model<String>()
    {
      @Override
      public String getObject()
      {
        return Integer.toString(count1.getCount());
      }
    }));

    final Count count2 = new Count();
    // Same idea as above, but now we record a state change. Note that the
    // URL will change because of this, and pressing the back button and
    // clicking the link again would revert to the older value.
    // The same thing could have been achieved by using setModelObject,
    // which implicitly registers a state change (of type
    // ComponentModelChange).
    Link linkWithStateChange = new Link("linkWithStateChange")
    {
      @Override
      public void onClick()
      {
        final int count = count2.getCount();
        count2.increment();
        addStateChange(new Change()
        {
          @Override
          public void undo()
          {
            // revert
            count2.decrement();
          }
        });
      }
    };
    add(linkWithStateChange);
    linkWithStateChange.add(new Label("label", new PropertyModel<Integer>(count2, "count")));

    // we can attach Link components to any HTML tag we want. If it is an anchor (<a href...),
    // the url to this component is put in the href attribute. For other components, a onclick
    // javascript event handler is created that triggers the round trip

    // it is of course possible to - instead of the above approach - hide as
    // much of the component as possible within a class.
    class CustomLink extends Link
    {
      final Count count2;

      /**
       * Construct.
       *
       * @param id
       */
      public CustomLink(String id)
      {
        super(id);
        count2 = new Count();
        add(new ClickCountLabel("label2", count2));
      }

      @Override
      public void onClick()
      {
        count2.increment();
      }
    }
    add(new CustomLink("link2"));

    // and if we know we are going to attach it to a <input type="button> tag, we shouldn't use
    // a label, but an AttributeModifier instead.
    class ButtonLink extends Link
    {
      final Count count3;

      /**
       * Construct.
       *
       * @param id
       */
      public ButtonLink(String id)
      {
        super(id);
        count3 = new Count();
        add(new AttributeModifier("value", new Model<String>()
        {
          @Override
          public String getObject()
          {
View Full Code Here

       * @param id
       */
      public CustomLink(String id)
      {
        super(id);
        count2 = new Count();
        add(new ClickCountLabel("label2", count2));
      }
View Full Code Here

       * @param id
       */
      public ButtonLink(String id)
      {
        super(id);
        count3 = new Count();
        add(new AttributeModifier("value", new Model<String>()
        {
          @Override
          public String getObject()
          {
View Full Code Here

  public LinkPage()
  {
    // power to the annonymous classes!

    // first create a simple value holder object
    final Count count1 = new Count();

    // add a link which, when clicked, increases our counter when a link is clicked, its onClick
    // method is called
    Link link1 = new Link("link1")
    {
      @Override
      public void onClick()
      {
        count1.increment();
      }
    };
    add(link1);

    // add a counter label to the link so that we can display it in the body of the link
    link1.add(new Label("label1", new Model<String>()
    {
      @Override
      public String getObject()
      {
        return count1.toString();
      }
    }));

    final Count count2 = new Count();
    // Same idea as above, but now we record a state change. Note that the URL will change
    // because of this, and pressing the back button and clicking the link again would revert to
    // the older value. The same thing could have been achieved by using setModelObject,
    // which implicitly registers a state change (of type ComponentModelChange).
    Link linkWithStateChange = new Link("linkWithStateChange")
    {
      @Override
      public void onClick()
      {
        count2.increment();
        addStateChange();
      }
    };
    add(linkWithStateChange);
    linkWithStateChange.add(new Label("label", new PropertyModel<Integer>(count2, "count")));

    // we can attach Link components to any HTML tag we want. If it is an anchor (<a href...),
    // the url to this component is put in the href attribute. For other components, a onclick
    // javascript event handler is created that triggers the round trip

    // it is of course possible to - instead of the above approach - hide as much of the
    // component as possible within a class.
    class CustomLink extends Link
    {
      final Count count2;

      /**
       * Construct.
       *
       * @param id
       */
      public CustomLink(String id)
      {
        super(id);
        count2 = new Count();
        add(new ClickCountLabel("label2", count2));
      }

      @Override
      public void onClick()
      {
        count2.increment();
      }
    }
    add(new CustomLink("link2"));

    // and if we know we are going to attach it to a <input type="button> tag, we shouldn't use
    // a label, but an AttributeModifier instead.
    class ButtonLink extends Link
    {
      final Count count3;

      /**
       * Construct.
       *
       * @param id
       */
      public ButtonLink(String id)
      {
        super(id);
        count3 = new Count();
        add(new AttributeModifier("value", new Model<String>()
        {
          @Override
          public String getObject()
          {
View Full Code Here

       * @param id
       */
      public CustomLink(String id)
      {
        super(id);
        count2 = new Count();
        add(new ClickCountLabel("label2", count2));
      }
View Full Code Here

       * @param id
       */
      public ButtonLink(String id)
      {
        super(id);
        count3 = new Count();
        add(new AttributeModifier("value", new Model<String>()
        {
          @Override
          public String getObject()
          {
View Full Code Here

        });
        spanLabel.setEscapeModelStrings(false);
        add(spanLabel);

        // Counter is wicket managed object.
        final Count count = new Count(); // simple counter object
        Link refresh = new Link("refresh") {
            public void onClick() {
                count.increment();
            }
        };
        refresh.add(new Label("number", new Model<String>() {
            public String getObject() {
                return Integer.toString(count.getCount());
            }
        }));
        add(refresh);

    }
View Full Code Here

        });
        spanLabel.setEscapeModelStrings(false);
        add(spanLabel);

        // Counter is wicket managed object.
        final Count count = new Count(); // simple counter object
        Link refresh = new Link("refresh") {
            public void onClick() {
                count.increment();
            }
        };
        refresh.add(new Label("number", new Model<String>() {
            public String getObject() {
                return Integer.toString(count.getCount());
            }
        }));
        add(refresh);
        conversation.begin();
    }
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.value.Count

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.