[newbie] Wicket:enclosure not working

72 views
Skip to first unread message

Mario Giammarco

unread,
Mar 27, 2018, 6:22:34 AM3/27/18
to invesdwin-platform
Hello,
it is not a NoWicket problem but it is about the generated html code so I ask anyway:

I have added a wicket enclosure to hide a fieldset but it is not working:

<wicket:enclosure child="mctcnc.comune_gridColumn">
                <fieldset>
                    <legend wicket:id="mctcnc_legend">Mctcnc</legend>
                    <div class="form-group">
                        <label class="control-label col-sm-2" wicket:for="mctcnc.comune">
                            <wicket:label>
                                Comune
                            </wicket:label>
                        </label>
                        <div wicket:id="mctcnc.comune_gridColumn" class="col-sm-4">
                            <input type="text" class="form-control" wicket:id="mctcnc.comune">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2" wicket:for="mctcnc.dataDiNascita">
                            <wicket:label>
                                Data Di Nascita
                            </wicket:label>
                        </label>
                        <div wicket:id="mctcnc.dataDiNascita_gridColumn" class="col-sm-4">
                            <input type="date" class="form-control" wicket:id="mctcnc.dataDiNascita">
                        </div>
                    </div>
                </fieldset>
                <fieldset>
                    <legend wicket:id="risultati_legend">Risultati</legend>
                    <div wicket:id="risultati_gridColumn" class="table-responsive">
                        <table class="table table-condensed table-hover table-striped" wicket:id="risultati"></table>
                    </div>
                </fieldset>
            </wicket:enclosure>

Mario Giammarco

unread,
Mar 27, 2018, 12:22:32 PM3/27/18
to invesdwin-platform
I am debugging this problem.
I have noticed that I have not created panels for my sub-models. I have created them now but nothing changed and I discovered that I do not fully understand the difference in doing:

public class MainType {


public SubType getMySubType() {
}

}

when SubType has an associated SubTypePanel or not.

 

Edwin Stang

unread,
Mar 27, 2018, 6:24:36 PM3/27/18
to invesdwin-platform
I have reverted the commit that changed the behavior of the gridcolumn. Now the wicket:enclosure should work properly again because the gridcolumn is not put visible/invisible properly reflecting the inner components state properly. It seems it was a bad idea try to allow updating of the inner component, since in that case the gridcolumn error info will not be pushed for validation errors. I will write in the other topic on how you should change your timer code to reflect that.

Edwin Stang

unread,
Mar 27, 2018, 6:28:06 PM3/27/18
to invesdwin-platform
You only need panels for subtypes that should be embeddable for @BeanPathEndPoint annotated properties (you need to instantiate the appropriate Panel then in the binding interceptor as long as the ideas of ticket https://github.com/subes/invesdwin-nowicket/issues/3 have not been resolved). Or for Lists of <ul> or TabbedPanels.

For all other cases the nested elements will be generated into the surrounding models page/panel html code as a fieldset. The only way to prevent that is the two options above.

Edwin Stang

unread,
Mar 27, 2018, 6:49:47 PM3/27/18
to invesdwin-platform
I have also looked at your current code. The wicket:enclosure also only works when mctcnc.comune is actually made invisible. Either via component modification or via a hideComune() utility method in your MCTCNC model (or via an interceptor as an override utility method inside your Home model).

Also it seems confusing to me why you would create Page classes for your models inside the panel package, even if those models are not even panels but instead nested models of the Home class. Maybe you are trying to hide the markup because you don't actually want that model nested in Home?

Here are the decisions involved with Model usages:
1. create only a <Model>Page class if you want to make it available in wicket as an individually navigable page. You can navigate to that page via an action button method that returns the given model.
2. create only a <Model>Panel class if you want to make it available in wicket as a component (can be for a modal dialog, for another page via a binding interceptor, for lists via <ul> or tabbedpanels
3. don't create anything and don't add @GeneratedMarkup annotation to the model if it should be nested inside another Page/Page only
4. You can mix and use multiple of the decisions above. Only the usage of the model decides about if its markup is
 a) instantiated as a Page (on redirect via a action button method or when the url is directly accessed)
 b) instantiated as a Panel (in a modal dialog, when used via a binding interceptor for a @BeanPathRoot, for lists of <ul> or tabbedpanels
 c) not instanted at all when being embedded inside another Page/Panels model and thus the markup that was generated into that is used.

Mario Giammarco

unread,
Mar 28, 2018, 4:47:15 AM3/28/18
to invesdwin-platform
Very sorry you have not seen updated code, I pushed this morning a lot of changes.
In the code that you have seen I have left by mistake the Page classes that I then changed in Panels and then (after reading this thread) deleted completely.
Eucaris and Mctcnc do not need a panel.
Regarding wicket:enclosure the problem is this (now I am understanding...): in Home.java I have hideEucaris() and hideMctcnc(). Unfortuately in html code there is no wicket:id of eucaris or mctcnc so I thaught that I can use mctcnc.comune to hide all fieldset.

Edwin Stang

unread,
Mar 28, 2018, 10:39:43 AM3/28/18
to invesdwin-platform
wicket:enclosure should work as you are saying with "hideEucaris() and hideMctcnc()" in Home since the visible state is also propageted with the nesting parents for each property. So when Mctcnc is hidden in home, every component of Mctcnc.xyz is hidden too. The problem with wicket:enclosure was that the GridColumn fix I made previously was causing this error. So with that problem away your wicket:enclosure should work properly with "hideEucaris() and hideMctcnc()".

Also I guess you used wicket:enclosure to hide the legend and labels of the properties. The wicket:enclosure is optional now because I have made some improvements in nowicket that make the labels and legends hide properly when the component they are made for is hidden. The only benefit that wicket:enclosure now brings is that the fieldset tag is hidden too when that is being used. Thus the small vertical gap it introduces is removed by that. See commit: https://github.com/subes/invesdwin-nowicket/commit/a071a68154eb4cd1e38a43339105c27eb2f634ba

Also I have seen the error regarding the risultati update (in the wicket debug panel in the website you gave me access to). When looking at the source code in the browser it seems risultati is not shown, this might be because you added a wicket:enclosure around it (though I don't see this in the repo because you might now have pushed your changes from this morning). If you want to use wicket:enclosure for risultati, you have to define a div with a wicket id around the enclosure and bind it via an interceptor to WebMarkupContainer. Then in the ajax timer you update that web markup container instead of the risultati_gridcolumn because the wicket:enclosure prevents the placeholder tag to be rendered for this.

Though you could also just remove the wicket:enclosure for risultati, add a wicket:id to the fieldset, bind it via the interceptor to WebMarkupContainer and override its isVisible() method to copy the visible state of the risultati component (which you retrieve from the component registry).

Or make it even simpler and remove the wicket:enclosure for risultati and modify your ajax timer as noted previously(what I currently see in your repo the fix has not been applied, so the risultati gets updated which is invisible because the gridcolumn workaround was removed because it did not work well with wicket:enclosure, so now we have to update the gridcolumn because that is the only component that has a placeholder tag now) from:
---------------------------
@Override
            protected void onTimer(final AjaxRequestTarget target) {
                final List<QueryReplyModel> risultati = ((Home) HtmlContext.getModel(HomePage.this).getObject())
                        .getRisultati();
                int size;
                if (risultati != null) {
                    size = risultati.size();
                } else {
                    size = 0;
                }
                if (size > actualSize) {
                    logger.debug("++++++++++++++++rinfresco pagina");
                    //                                GuiService.get().processRequestFinally(getComponent());
                    //
                    //                            } else {
                    final Component c = HtmlContext.get(HomePage.this).getComponentRegistry().getComponent(
                            HomeConstants.risultati);
                    target.add(c);

                }
                actualSize = size;
            }
---------------------------
To:
---------------------------
@Override
            protected void onTimer(final AjaxRequestTarget target) {
                final List<QueryReplyModel> risultati = ((Home) HtmlContext.getModel(HomePage.this).getObject())
                        .getRisultati();
                int size;
                if (risultati != null) {
                    size = risultati.size();
                } else {
                    size = 0;
                }
                if (size > actualSize) {
                    logger.debug("++++++++++++++++rinfresco pagina");
                    //                                GuiService.get().processRequestFinally(getComponent());
                    //
                    //                            } else {
                   final Component risultati = HtmlContext.get(HomePage.this).getComponentRegistry().getComponent(
                            HomeConstants.risultati + GridColumnHtmlElement.GRID_COLUMN_WICKET_ID_SUFFIX);
                    target.add(c);

                }
                actualSize = size;
            }
---------------------------

Regarding the other question about the odd behavior of risultati sometimes appearing and sometimes not. This is because when an eager event is fired (for your combo boxes or when a button is invoked) the whole form gets updated because GuiService.processRequestFinally() gets called for it inside NoWicket. When that update happens when the risultati are non-empty, the tag will be properly rendered in the browser because the parent tag (the form) included it. After that has happened, the ajax timer will continue working properly until the risultati once become invisible again without a replacement tag being rendered. Since risultati is empty in the beginning and the ajax timer uses the missing wicket id to update the risultati (it is hidden because of a wicket:enclosure most probably), it fails and the error is displayed in the wicket debug panel in the website in the browser. Then again some action has to happen which updates the form via GuiService.processReuquestFinall() (again an eager event form combo box or button) to make it visible again.

You can get out of this odd behavior by simply applying the fix above to make sure the placeholder tag for the risultat_gridcolumn is always there (by removing any wicket:enclosure around it) to be updated and using the ajax timer code above to update that component. Or using one of the other approaches above involving WebMarkupContainer and update that component instead in the ajax timer behavior.

Hope this explains everything.

Mario Giammarco

unread,
Mar 28, 2018, 10:57:40 AM3/28/18
to invesdwin-platform
Reading this I quickly discovered that I have made a big mistake that explains everything!
And it explains also the strange behaviour I have seen.
Doing tests I have by mistake surrounded the "Risultati" tabs with wicket:enclosure making it disappear when hideMctcnc is called!
Dangerous bug!
Thanks you very much for your work and help!
Now the app works very well and it is faster and lighter than the previous one that was based on Vaadin 6.
I now push changes and leave the test running until tomorrow just in case you want to see it running.
Many thanks again.
In the near future I will try your other suggestions to see if I can optimize it even more.
I also will check if the architecture is clean (is is compliant with MVC pattern? and so on)

sub es

unread,
Mar 28, 2018, 11:05:31 AM3/28/18
to Mario Giammarco, invesdwin-platform
Great, I am happy everything works fine for you now!

--
You received this message because you are subscribed to the Google Groups "invesdwin-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to invesdwin-platf...@googlegroups.com.
To post to this group, send email to invesdwin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/invesdwin-platform/813bf0c9-64a5-46f2-8b03-65031f5889bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages