Wicket
  1. Wicket
  2. WICKET-4491

isVisible() and determineVisibility() don't work as expected on component in BorderBodyContainer

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Not A Problem
    • Affects Version/s: 6.0.0-beta1
    • Fix Version/s: None
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      Ubuntu 12.04, java7

      Description

      I have an application that has a foldable left bar (somewhat like jQuery's accordeon). The menu-panels are implemented as Borders; see the next fragment. The problem I have is that components that are placed in this border do not correctly reflect the visibily of the bodycontainer -> if the bodycontainer is invisible, I expect the component inside that container to be invisible as well.

      I need this, as the component in the container acts as EventSink. I use events to notify the component to dynamically update itself by ajax. But when the event is passed and the component is invisible, there is no outputMarkupId and I get an Wicket Ajax Error (this is correct behaviour).

      public class AjaxToggleLinkBorder extends Border
      {

      private static final long serialVersionUID = -5801550490420643837L;
      protected boolean bodyVisible = false;

      final public boolean isBodyVisible()

      { return bodyVisible; }

      final public void setBodyVisible( final boolean isBodyVisible )

      { this.bodyVisible = isBodyVisible; getBodyContainer().setVisible( isBodyVisible() ); }

      public AjaxToggleLinkBorder( final String id, final IModel linkText )
      {
      super( id );
      setBodyVisible( isBodyVisible() );

      setOutputMarkupId( true );

      final AjaxFallbackLink<Void> link = new AjaxFallbackLink<Void>( "link" )
      {
      private static final long serialVersionUID = 3540373588573135540L;

      @Override
      public void onClick( final AjaxRequestTarget target )

      { setBodyVisible( !isBodyVisible() ); target.add( AjaxToggleLinkBorder.this ); }

      };
      link.add( new Label( "label", linkText ) );
      addToBorder( link );
      }
      }

      I add components line this:

      final Border infoBorder = new AjaxToggleLinkBorder( "infoBorder", new Model<String>( "Info" ) );
      infoBorder.getBodyContainer().add( new AmountLabel( "total", tp.newTotalModel() ) );
      infoBorder.getBodyContainer().add( new Label( "numberOfTransactions", tp.newSizeModel() )
      {
      @Override
      public void onEvent( final IEvent<?> event )
      {
      super.onEvent( event );

      // check if this is a counter update event and if so repaint self
      if ( event.getPayload() instanceof CategoryUpdate )
      {
      final CategoryUpdate update = (CategoryUpdate) event.getPayload();
      final boolean isVisible = this.determineVisibility();
      if ( update.getTarget() != null && isVisible )

      { update.getTarget().add( this ); }

      }
      }

      } );

      The boolean isVisible is true, while the bodycontainer is not.

      1. wicketborder.zip
        10 kB
        Rob Audenaerde

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        1h 38m 1 Martin Grigorov 10/Apr/12 14:23
        Hide
        Rob Audenaerde added a comment - - edited

        Oh I should have refreshed.

        I see I was mistaken by assuming detemineVisible() would take all visibility checks into account.

        Show
        Rob Audenaerde added a comment - - edited Oh I should have refreshed. I see I was mistaken by assuming detemineVisible() would take all visibility checks into account.
        Rob Audenaerde made changes -
        Attachment wicketborder.zip [ 12522100 ]
        Hide
        Rob Audenaerde added a comment -

        the quickstart

        Show
        Rob Audenaerde added a comment - the quickstart
        Martin Grigorov made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Not A Problem [ 8 ]
        Hide
        Martin Grigorov added a comment -

        Re-counting the braces I see now that you override Label's #onEvent() and its isVisible() is not the same as bodyContainer's #isVisible().
        You may either check Label#isVisibleInHierarchy() or check "inforBorder.getBodyContainer().isVisible()"

        Show
        Martin Grigorov added a comment - Re-counting the braces I see now that you override Label's #onEvent() and its isVisible() is not the same as bodyContainer's #isVisible(). You may either check Label#isVisibleInHierarchy() or check "inforBorder.getBodyContainer().isVisible()"
        Hide
        Martin Grigorov added a comment -

        Hi,

        Is the following actually a valid code ?

        {@code}
        infoBorder.getBodyContainer().add( new Label( "numberOfTransactions", tp.newSizeModel() )
        {
        @Override
        public void onEvent( final IEvent<?> event ) {@code}

        Which #onEvent() is being overridden ?
        Please attach a quickstart that demonstrates the problem.

        Show
        Martin Grigorov added a comment - Hi, Is the following actually a valid code ? {@code} infoBorder.getBodyContainer().add( new Label( "numberOfTransactions", tp.newSizeModel() ) { @Override public void onEvent( final IEvent<?> event ) {@code} Which #onEvent() is being overridden ? Please attach a quickstart that demonstrates the problem.
        Rob Audenaerde created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Rob Audenaerde
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development