[ 
https://issues.apache.org/jira/browse/WICKET-6410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16062674#comment-16062674
 ] 

Fabian T. commented on WICKET-6410:
-----------------------------------

Hi Martin,

The behaviour when we use the “LoadableDetachableModel” is very similar to the 
“AbstractReadOnlyModel”. The state handling is different, but we don’t really 
need it in our case.

After a submit, “ChoiceRenderer#getObject” calls “choices.getObject()”, even if 
nothing is selected in the dropdown (so the id is still null or empty). After 
that, the Load method of LoadableDetachableModel is called. And in this load 
method we still have our bigger SQL Statement.

In our understanding, “ChoiceRenderer#getObject” is just used to determine the 
selected object in the dropdown, correct? So when no element is selected, why 
do we need to call the load method?  The getObject here is not called for 
rendering the List in the Dropdown. The Dropdown is not refreshed, since after 
submit only some components are refreshed via Ajax, but not our Dropdown with 
the big SQL behind.


ChoiceRenderer:
{code:java}
        @Override
        public T getObject(String id, IModel<? extends List<? extends T>> 
choices)
        {
               // We think the following four lines will prevent unnecessary 
calls to getObject
                // No choice selected, so no matching against the List of 
choices
                if (StringUtils.isBlank(id)) {
                        return null;
                }


                List<? extends T> _choices = choices.getObject();
                for (int index = 0; index < _choices.size(); index++)
                {
                        // Get next choice
                        final T choice = _choices.get(index);
                        if (getIdValue(choice, index).equals(id))
                        {
                                return choice;
                        }
                }
                return null;
        }
{code}


Greetz

> ChoiceRenderer getObject always calls IModel#getObject when id is null
> ----------------------------------------------------------------------
>
>                 Key: WICKET-6410
>                 URL: https://issues.apache.org/jira/browse/WICKET-6410
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 7.1.0
>            Reporter: Fabian T.
>            Priority: Trivial
>         Attachments: debug_Screenshot.png
>
>
> {code:java}
> @Override
>       public T getObject(String id, IModel<? extends List<? extends T>> 
> choices)
>       {
>               List<? extends T> _choices = choices.getObject();
>               for (int index = 0; index < _choices.size(); index++)
>               {
>                       // Get next choice
>                       final T choice = _choices.get(index);
>                       if (getIdValue(choice, index).equals(id))
>                       {
>                               return choice;
>                       }
>               }
>               return null;
>       }
> }
> {code}
> This Methode always calls „choices.getObject();”, even if the id is null or 
> empty.
> In our project we got some bigger SQL Statements behind some getObject 
> methods of different dropDownChoices. Avoiding to call getObject when the id 
> is null or empty increases the performance.
> Feel free to correct me if I mess up something else with this fix.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to