[ 
https://issues.apache.org/jira/browse/WICKET-3422?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Joonas Hämäläinen updated WICKET-3422:
--------------------------------------

    Description: 
<b>Problem:</b>

    The amount of boilerplate code needed to create partitions of a web page 
that take their
    visibility setting from a controlling component. 

        "Changing the visibility of a child component in Ajax callback method 
will not affect the entire 
        enclosure but just the child component itself. This is because only the 
child component is added
        to the AjaxRequestTarget."
        - https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html


<b>Solution:</b>

    1. 'Inline' Enclosure tags, implemented as an attribute that can be 
attached to an arbitrary html tag.
        Works just like a regular Enclosure, but is Ajax ready.
    2. When handling Ajax requests, Inline Enclosures that are controlled by 
Components already in the Ajax 
        request target are automatically added to the Ajax request target.


Example:

    Below we have an ajax link: 'toggleLink' that is used to 
    toggle the visibility of the component 'label1'. Since the 
    label1 component happens to be the controlling child component
    of the enclosure, the visibility of the whole enclosure is toggled 
    at the same time.

    Html:
    -----
        <a href="#" wicket:id="toggleLink">Toggle visibility</a>

        <div wicket:enclosure="child:label1">
            The visibility of this text is also toggled.
            <div wicket:id="label1">Test</div>
        </div>

    Here we have the 'inline' Enclosure tag:
        <div wicket:enclosure="child:label1">
    Notice that no boilerplate code for this is necessary on the
    Java side. The tag can be an arbitrary html tag (but cannot 
    simultaneously be another wicket tag, like WebMarkupContainer). 
    If it does not yet have a wicket id (as in this example), a 
    page-unique id will be generated for it (ex. inlineEnclosure-0). 
    The handling of the child id attribute is identical to the handling 
    of child id:s in traditional Wicket Enclosure tags.

    On Java side we only need to introduce the child object and some kind 
    of control for the toggling of the visibility of the child object.
    Here an ajax link is used. When user clicks the link, the visibility
    of the entire Enclosure is toggled. Developer must also remember to 
    set the outputmarkupId=true for the label, as usual for Ajaxified code. 
    Nothing else is needed, the patch handles everything from here.

    Java:
    -----
      private Label label1 = new Label("label1", "Test Label 1");
      private AjaxLink<Void> toggleLink;

      public MinimalAjaxEnclosurePage()
      {
            toggleLink = new AjaxLink<Void>("toggleLink"){
                  @Override
                  public void onClick(AjaxRequestTarget target)
                  {
                        label1.setVisible(!label1.isVisible());
                        target.addComponent(label1);
                  }
                  
            };
            add(toggleLink);
            label1.setOutputMarkupId(true);
            add(label1);
      }        


Testing:

    The patch can be tested with the new unit tests in
        src/test/java/org/apache/wicket/markup/html/internal
        - InlineEnclosureTest has tests for rendering of Inline enclosures in 
various situations:
                - chooses the correct child, whether or not child id is set
                - reuses existing wicket:id
                - works when nested with other inline Enclosures or traditional 
Wicket Enclosure tags
        - AjaxEnclosureTest has tests for toggling visibility of Inline 
enclosures by toggling 
          the visibility of their controllers in Ajax requests:
                - only the correct child controls the enclosure, even when 
child id is not set
                - works with nested inline enclosures


Changes to Wicket code:

    - EnclosureHandler:
            - Enhanced state handling to enable recognizing the end tags of 
inline enclosures.
                - this also covers some border cases of handling enclosures 
without explicitly
                  designated child id:s.
            - recognizes inline enclosures by their attribute 
(wicket:enclosure) and gives them 
              a page-unique id. The id is also written directly to the 
underlying Xml-tag which 
              causes a warning.
    - EnclosureResolver:
            - recognizes an inline Enclosure tag and creates an Enclosure 
instance for it
    - Enclosure:
            - has a flag and a getter to recognize the 'inline' Enclosure 
instances
            - implements onAfterRenderChildren, notifying child objects stored 
in the onComponentTagBody phase
            - new method: updateVisibility(), used in Ajax calls to update the 
visibility of the enclosure with the 
              visibility of it's controlling child object
            - new method: getChildId(), used in Ajax calls to get the child's 
id so it can be compared to the id of components
              added to the Ajax target
    - MarkupContainer
            - prevented removing inline Enclosures at the time of detach. 
    - WebApplication:
            - newAjaxRequestTarget: Adds a new listener: AjaxEnclosureListener
    - AjaxEnclosureListener (new class) (implementing 
AjaxRequestTarget.IListener)
            - onBeforeRespond: searches the Page for those inline Enclosures 
that have their 
              child controllers added to Ajax Request target, and adds them to 
the target as well.
                - Also sets these values to the found Enclosures to help with 
ajax updates:
                    - setOutputMarkupPlaceholderTag=true  
                    - setMarkupId=[id generated in EnclosureHandler]        
    - New tests:
        - src/test/java/org/apache/wicket/markup/html/internal:
            - AjaxEnclosurePage_*.html / .java   : test pages for 
AjaxEnclosureTests.java
            - InlineEnclosurePage_*.html / .java : test pages for 
InlineEnclosureTest.java

    - DefaultMarkupCacheKeyProvider: (Fixed a bug?)
            - Added a missing dot prefixing the file-extension.
            - Not directly related to the issue, but many wicket unit tests 
were failing without this change.
              


Thanks for support:
    Martin Makundi
    Igor Vaynberg
    Jeremy Thomerson  

  was:
Problem:

    The amount of boilerplate code needed to create partitions of a web page 
that take their
    visibility setting from a controlling component. 

        "Changing the visibility of a child component in Ajax callback method 
will not affect the entire 
        enclosure but just the child component itself. This is because only the 
child component is added
        to the AjaxRequestTarget."
        - https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html


Solution:

    1. 'Inline' Enclosure tags, implemented as an attribute that can be 
attached to an arbitrary html tag.
        Works just like a regular Enclosure, but is Ajax ready.
    2. When handling Ajax requests, Inline Enclosures that are controlled by 
Components already in the Ajax 
        request target are automatically added to the Ajax request target.


Example:

    Below we have an ajax link: 'toggleLink' that is used to 
    toggle the visibility of the component 'label1'. Since the 
    label1 component happens to be the controlling child component
    of the enclosure, the visibility of the whole enclosure is toggled 
    at the same time.

    Html:
    -----
        <a href="#" wicket:id="toggleLink">Toggle visibility</a>

        <div wicket:enclosure="child:label1">
            The visibility of this text is also toggled.
            <div wicket:id="label1">Test</div>
        </div>

    Here we have the 'inline' Enclosure tag:
        <div wicket:enclosure="child:label1">
    Notice that no boilerplate code for this is necessary on the
    Java side. The tag can be an arbitrary html tag (but cannot 
    simultaneously be another wicket tag, like WebMarkupContainer). 
    If it does not yet have a wicket id (as in this example), a 
    page-unique id will be generated for it (ex. inlineEnclosure-0). 
    The handling of the child id attribute is identical to the handling 
    of child id:s in traditional Wicket Enclosure tags.

    On Java side we only need to introduce the child object and some kind 
    of control for the toggling of the visibility of the child object.
    Here an ajax link is used. When user clicks the link, the visibility
    of the entire Enclosure is toggled. Developer must also remember to 
    set the outputmarkupId=true for the label, as usual for Ajaxified code. 
    Nothing else is needed, the patch handles everything from here.

    Java:
    -----
      private Label label1 = new Label("label1", "Test Label 1");
      private AjaxLink<Void> toggleLink;

      public MinimalAjaxEnclosurePage()
      {
            toggleLink = new AjaxLink<Void>("toggleLink"){
                  @Override
                  public void onClick(AjaxRequestTarget target)
                  {
                        label1.setVisible(!label1.isVisible());
                        target.addComponent(label1);
                  }
                  
            };
            add(toggleLink);
            label1.setOutputMarkupId(true);
            add(label1);
      }        


Testing:

    The patch can be tested with the new unit tests in
        src/test/java/org/apache/wicket/markup/html/internal
        - InlineEnclosureTest has tests for rendering of Inline enclosures in 
various situations:
                - chooses the correct child, whether or not child id is set
                - reuses existing wicket:id
                - works when nested with other inline Enclosures or traditional 
Wicket Enclosure tags
        - AjaxEnclosureTest has tests for toggling visibility of Inline 
enclosures by toggling 
          the visibility of their controllers in Ajax requests:
                - only the correct child controls the enclosure, even when 
child id is not set
                - works with nested inline enclosures


Changes to Wicket code:

    - EnclosureHandler:
            - Enhanced state handling to enable recognizing the end tags of 
inline enclosures.
                - this also covers some border cases of handling enclosures 
without explicitly
                  designated child id:s.
            - recognizes inline enclosures by their attribute 
(wicket:enclosure) and gives them 
              a page-unique id. The id is also written directly to the 
underlying Xml-tag which 
              causes a warning.
    - EnclosureResolver:
            - recognizes an inline Enclosure tag and creates an Enclosure 
instance for it
    - Enclosure:
            - has a flag and a getter to recognize the 'inline' Enclosure 
instances
            - implements onAfterRenderChildren, notifying child objects stored 
in the onComponentTagBody phase
            - new method: updateVisibility(), used in Ajax calls to update the 
visibility of the enclosure with the 
              visibility of it's controlling child object
            - new method: getChildId(), used in Ajax calls to get the child's 
id so it can be compared to the id of components
              added to the Ajax target
    - MarkupContainer
            - prevented removing inline Enclosures at the time of detach. 
    - WebApplication:
            - newAjaxRequestTarget: Adds a new listener: AjaxEnclosureListener
    - AjaxEnclosureListener (new class) (implementing 
AjaxRequestTarget.IListener)
            - onBeforeRespond: searches the Page for those inline Enclosures 
that have their 
              child controllers added to Ajax Request target, and adds them to 
the target as well.
                - Also sets these values to the found Enclosures to help with 
ajax updates:
                    - setOutputMarkupPlaceholderTag=true  
                    - setMarkupId=[id generated in EnclosureHandler]        
    - New tests:
        - src/test/java/org/apache/wicket/markup/html/internal:
            - AjaxEnclosurePage_*.html / .java   : test pages for 
AjaxEnclosureTests.java
            - InlineEnclosurePage_*.html / .java : test pages for 
InlineEnclosureTest.java

    - DefaultMarkupCacheKeyProvider: (Fixed a bug?)
            - Added a missing dot prefixing the file-extension.
            - Not directly related to the issue, but many wicket unit tests 
were failing without this change.
              


Thanks for support:
    Martin Makundi
    Igor Vaynberg
    Jeremy Thomerson  


> Simplified visibility control of Enclosures in Ajax requests
> ------------------------------------------------------------
>
>                 Key: WICKET-3422
>                 URL: https://issues.apache.org/jira/browse/WICKET-3422
>             Project: Wicket
>          Issue Type: New Feature
>          Components: wicket
>    Affects Versions: 1.4.15
>            Reporter: Joonas Hämäläinen
>              Labels: Ajax, AjaxRequestTarget, Enclosure, Visibility
>         Attachments: InlineAndAjaxifiedEnclosures_patch.txt
>
>
> <b>Problem:</b>
>     The amount of boilerplate code needed to create partitions of a web page 
> that take their
>     visibility setting from a controlling component. 
>         "Changing the visibility of a child component in Ajax callback method 
> will not affect the entire 
>         enclosure but just the child component itself. This is because only 
> the child component is added
>         to the AjaxRequestTarget."
>         - https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html
> <b>Solution:</b>
>     1. 'Inline' Enclosure tags, implemented as an attribute that can be 
> attached to an arbitrary html tag.
>         Works just like a regular Enclosure, but is Ajax ready.
>     2. When handling Ajax requests, Inline Enclosures that are controlled by 
> Components already in the Ajax 
>         request target are automatically added to the Ajax request target.
> Example:
>     Below we have an ajax link: 'toggleLink' that is used to 
>     toggle the visibility of the component 'label1'. Since the 
>     label1 component happens to be the controlling child component
>     of the enclosure, the visibility of the whole enclosure is toggled 
>     at the same time.
>     Html:
>     -----
>         <a href="#" wicket:id="toggleLink">Toggle visibility</a>
>         <div wicket:enclosure="child:label1">
>             The visibility of this text is also toggled.
>             <div wicket:id="label1">Test</div>
>         </div>
>     Here we have the 'inline' Enclosure tag:
>         <div wicket:enclosure="child:label1">
>     Notice that no boilerplate code for this is necessary on the
>     Java side. The tag can be an arbitrary html tag (but cannot 
>     simultaneously be another wicket tag, like WebMarkupContainer). 
>     If it does not yet have a wicket id (as in this example), a 
>     page-unique id will be generated for it (ex. inlineEnclosure-0). 
>     The handling of the child id attribute is identical to the handling 
>     of child id:s in traditional Wicket Enclosure tags.
>     On Java side we only need to introduce the child object and some kind 
>     of control for the toggling of the visibility of the child object.
>     Here an ajax link is used. When user clicks the link, the visibility
>     of the entire Enclosure is toggled. Developer must also remember to 
>     set the outputmarkupId=true for the label, as usual for Ajaxified code. 
>     Nothing else is needed, the patch handles everything from here.
>     Java:
>     -----
>       private Label label1 = new Label("label1", "Test Label 1");
>       private AjaxLink<Void> toggleLink;
>       public MinimalAjaxEnclosurePage()
>       {
>             toggleLink = new AjaxLink<Void>("toggleLink"){
>                   @Override
>                   public void onClick(AjaxRequestTarget target)
>                   {
>                         label1.setVisible(!label1.isVisible());
>                         target.addComponent(label1);
>                   }
>                   
>             };
>             add(toggleLink);
>             label1.setOutputMarkupId(true);
>             add(label1);
>       }        
> Testing:
>     The patch can be tested with the new unit tests in
>         src/test/java/org/apache/wicket/markup/html/internal
>         - InlineEnclosureTest has tests for rendering of Inline enclosures in 
> various situations:
>                 - chooses the correct child, whether or not child id is set
>                 - reuses existing wicket:id
>                 - works when nested with other inline Enclosures or 
> traditional Wicket Enclosure tags
>         - AjaxEnclosureTest has tests for toggling visibility of Inline 
> enclosures by toggling 
>           the visibility of their controllers in Ajax requests:
>                 - only the correct child controls the enclosure, even when 
> child id is not set
>                 - works with nested inline enclosures
> Changes to Wicket code:
>     - EnclosureHandler:
>             - Enhanced state handling to enable recognizing the end tags of 
> inline enclosures.
>                 - this also covers some border cases of handling enclosures 
> without explicitly
>                   designated child id:s.
>             - recognizes inline enclosures by their attribute 
> (wicket:enclosure) and gives them 
>               a page-unique id. The id is also written directly to the 
> underlying Xml-tag which 
>               causes a warning.
>     - EnclosureResolver:
>             - recognizes an inline Enclosure tag and creates an Enclosure 
> instance for it
>     - Enclosure:
>             - has a flag and a getter to recognize the 'inline' Enclosure 
> instances
>             - implements onAfterRenderChildren, notifying child objects 
> stored in the onComponentTagBody phase
>             - new method: updateVisibility(), used in Ajax calls to update 
> the visibility of the enclosure with the 
>               visibility of it's controlling child object
>             - new method: getChildId(), used in Ajax calls to get the child's 
> id so it can be compared to the id of components
>               added to the Ajax target
>     - MarkupContainer
>             - prevented removing inline Enclosures at the time of detach. 
>     - WebApplication:
>             - newAjaxRequestTarget: Adds a new listener: AjaxEnclosureListener
>     - AjaxEnclosureListener (new class) (implementing 
> AjaxRequestTarget.IListener)
>             - onBeforeRespond: searches the Page for those inline Enclosures 
> that have their 
>               child controllers added to Ajax Request target, and adds them 
> to the target as well.
>                 - Also sets these values to the found Enclosures to help with 
> ajax updates:
>                     - setOutputMarkupPlaceholderTag=true  
>                     - setMarkupId=[id generated in EnclosureHandler]        
>     - New tests:
>         - src/test/java/org/apache/wicket/markup/html/internal:
>             - AjaxEnclosurePage_*.html / .java   : test pages for 
> AjaxEnclosureTests.java
>             - InlineEnclosurePage_*.html / .java : test pages for 
> InlineEnclosureTest.java
>     - DefaultMarkupCacheKeyProvider: (Fixed a bug?)
>             - Added a missing dot prefixing the file-extension.
>             - Not directly related to the issue, but many wicket unit tests 
> were failing without this change.
>               
> Thanks for support:
>     Martin Makundi
>     Igor Vaynberg
>     Jeremy Thomerson  

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to