You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by OjO <fa...@washington.edu> on 2009/05/01 19:23:31 UTC

Re: Null model with CheckGroup

Thank you, Igor! I had trouble subscribing to the mailing list. Just noticed
your response on my Nabble Alert today. I also found out it by checking the
source code of Check.java. Here is my code sample:

   List<ItemI> selectedItems = 
      (getSelectedList() == null
       ? new ArrayList()
       : new ArrayList (getSelectedList()));

    Form form = new MySelectItemForm ("form", selectedItems);
    add(form);
    final CheckGroup itemGroup = new CheckGroup ("group", selectedItems);
    form.add (itemGroup);
    
    List<ItemI> choiceList = getList();
    ListView itemList = new ListView("item_list", choiceList ) {
	
	protected void populateItem(ListItem item) {
	  
	  item.add (new Check ("ckbox_item", 
			       item.getModel(),
			       itemGroup));

	  ItemI t = (ItemI)item.getModelObject();
	  item.add (new Label("item_title", t.getName()));
	}
      };
    itemGroup.add(itemList);

    CheckGroupSelector selectAll = 
      new CheckGroupSelector ("groupselector_echan", itemGroup);
    if ( choiceList.size () == selectedItems.size()) {
      selectAll.add (new SimpleAttributeModifier ("checked", "checked"));
    }
    itemGroup.add (selectAll);

I thought the CheckGroupSelector would set checked automatically if it sees
the itemGroup has the same collection as the choiceList. But it does not.



igor.vaynberg wrote:
> 
> just like with any choice component in wicket, items are checked if
> they are contained in the same collection model they would be put in
> on submit, so in your case if the collection that is the model object
> of the checkgroup contains the same value as the check's model object
> the check is checked.
> 
> -igor
> 
> On Wed, Apr 29, 2009 at 12:54 PM, OjO <fa...@washington.edu> wrote:
>>
>> With CheckBox, I can pass in the Boolean value. But with Check, how do I
>> let
>> it know the item should be displayed as checked initially?
>>
>> OjO wrote:
>>>
>>> How does the Check object determine if the checkbox should be tagged as
>>> checked?
>>>
>>>
>>>
>>> igor.vaynberg wrote:
>>>>
>>>> in the example checkgroup inherits a property of the
>>>> compoundpropertymodel as its model. i suggest you read the models wiki
>>>> page.
>>>>
>>>> -igor
>>>>
>>>> On Fri, May 23, 2008 at 8:36 AM, seanblaes <se...@hifiit.com>
>>>> wrote:
>>>>>
>>>>> That's how the example at
>>>>> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=%3Aorg.apache.wicket.examples.compref.CheckGroupPage
>>>>> shows it.  I added an empty ArrayList as the model, and it works now.
>>>>> Should I send a message to the bugs list to update the examples page
>>>>> above?
>>>>>
>>>>>
>>>>> I did note that when you view the source of the example, it uses the
>>>>> empty
>>>>> ArrayList approach I'm using now.
>>>>>
>>>>>
>>>>> igor.vaynberg wrote:
>>>>>>
>>>>>>  CheckGroup group = new CheckGroup("merchantCheckboxGroup",
>>>>>> **model**);
>>>>>>
>>>>>> you are never setting the model you are passing in.
>>>>>>
>>>>>> -igor
>>>>>>
>>>>>> On Fri, May 23, 2008 at 12:09 AM, seanblaes <se...@hifiit.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hello all, I'm beating my head on the wall and not really sure what
>>>>>>> I'm
>>>>>>> doing
>>>>>>> wrong... :(
>>>>>>>
>>>>>>> I am attempting to use a CheckGroup to contain several choices -
>>>>>>> maybe
>>>>>>> it's
>>>>>>> even the wrong way to go about it.  I followed the example on the
>>>>>>> Wicket
>>>>>>> webpage, but it's not working for me.
>>>>>>>
>>>>>>> Here's my HTML:
>>>>>>>
>>>>>>> <input type="checkbox" name="filter_by_merchant"
>>>>>>> id="filter_by_merchant"
>>>>>>> wicket:id="filterByMerchantCheckbox" value="1" onchange="var
>>>>>>> l=$('optional_filter_by_merchant'); if (this.checked){l.show()} else
>>>>>>> {l.hide()}"/>
>>>>>>> <label for="filter_by_merchant">Merchant</label>
>>>>>>>
>>>>>>> <ul id="optional_filter_by_merchant" class="inline optional-indent">
>>>>>>>        <li wicket:id="merchants">
>>>>>>>                <input type="checkbox"
>>>>>>> name="filter_by_merchant_rich_clicks"
>>>>>>> id="filter_by_merchant_rich_clicks"
>>>>>>> wicket:id="merchantCheckboxComponent"
>>>>>>> />
>>>>>>>                <label for="filter_by_merchant_rich_clicks"
>>>>>>> wicket:id="merchantCheckboxLabel">Rich Clicks</label>
>>>>>>>        </li>
>>>>>>> </ul>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> And I have a method to populate this section:
>>>>>>>
>>>>>>> private CheckGroup createMerchantFilterMerchantsCheckboxes(Model
>>>>>>> model) {
>>>>>>>        CheckGroup group = new CheckGroup("merchantCheckboxGroup");
>>>>>>>        ListView merchants = new ListView("merchants",
>>>>>>> MerchantOption.loadOptions()) {
>>>>>>>                private static final long serialVersionUID = 1L;
>>>>>>>
>>>>>>>                protected void populateItem(ListItem item) {
>>>>>>>                        item.add(new
>>>>>>> Check("merchantCheckboxComponent"));
>>>>>>>                        item.add(new Label("merchantCheckboxLabel",
>>>>>>> new
>>>>>>> PropertyModel(item.getModel(), "value")));
>>>>>>>                }
>>>>>>>        };
>>>>>>>        group.add(merchants);
>>>>>>>
>>>>>>>        return group;
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> When I call this method from my page class, it's pretty simple:
>>>>>>>
>>>>>>> ReportTypeOption def = new ReportTypeOption();
>>>>>>> Model model = new Model(def);
>>>>>>> setModel(model);
>>>>>>> Form form = new Form("reportForm");
>>>>>>> add(form);
>>>>>>> form.add(createMerchantFilterMerchantsCheckboxes(model));
>>>>>>>
>>>>>>>
>>>>>>> But, every time I hit the page, it throws
>>>>>>> "org.apache.wicket.WicketRuntimeException: CheckGroup
>>>>>>> [0:reportForm:merchantCheckboxGroup] contains a null model object,
>>>>>>> must
>>>>>>> be
>>>>>>> an object of type java.util.Collection".
>>>>>>>
>>>>>>> From what I can tell, this code is exactly like what's on the demo
>>>>>>> page.
>>>>>>> Further, I've tried reading all the docs I can find and have even
>>>>>>> tried
>>>>>>> stepping through the code.  But, I'm not getting anywhere.  Does
>>>>>>> anybody
>>>>>>> have any ideas on how to get that model populated?  It's complaining
>>>>>>> that
>>>>>>> the CheckGroup doesn't have a model associated, not the Check, and
>>>>>>> indeed
>>>>>>> it's not initialized with a model.  Should it be?  Which one?
>>>>>>> --
>>>>>>> View this message in context:
>>>>>>> http://www.nabble.com/Null-model-with-CheckGroup-tp17419490p17419490.html
>>>>>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Null-model-with-CheckGroup-tp17419490p17427924.html
>>>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Null-model-with-CheckGroup-tp17419490p23301416.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Null-model-with-CheckGroup-tp17419490p23336823.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org