You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Shelli Orton <Sh...@sjrb.ca> on 2010/09/22 21:53:43 UTC
Setting Checked Boxes in CheckGroup
Hi,
I am trying to use a CheckGroup to manage which columns are used in a
datatable. I've set up my columns as per the code below. The
getColumnCheckBoxes method creates the check boxes that will be part of
the group. The getDefaultColumns defines which columns should be
checked by default. The default columns are being set, but the boxes
are not being displayed as "checked" when the page is first loaded.
However, the correct columns are being displayed in the datatable, so
they are being set "behind the scenes".
How do I get them to display as checked on page load?
Thanks in advance!
Shelli
CODE:
public class HomePage extends WebPage
{
StringResourceModel columnA = new StringResourceModel("columnA",
this,
null);
StringResourceModel columnB = new StringResourceModel("columnB",
this,
null);
StringResourceModel columnC = new StringResourceModel("columnC",
this,
null);
StringResourceModel columnD = new StringResourceModel("columnD",
this,
null);
ArrayList<SelectOption> columnCheckBoxes = null;
CheckGroup<SelectOption> columnCheckGroup = new
CheckGroup<SelectOption>("columnCheckGroup",
new ArrayList<SelectOption>());
@SuppressWarnings("rawtypes")
List<IColumn> columns = new ArrayList<IColumn>();
/**
* Constructor that is invoked when page is invoked without a
session.
*
* @param parameters Page parameters
*/
@SuppressWarnings("rawtypes")
public HomePage(final PageParameters parameters)
{
@SuppressWarnings("serial")
Form queryForm = new Form("queryForm")
{
@Override
protected void onSubmit()
{
// do stuff
}
};
add(queryForm);
// Create column selection boxes
columnCheckGroup.add(new
CheckGroupSelector("columnCheckGroupSelector"));
@SuppressWarnings({ "unchecked", "serial" })
ListView checkBoxes = new ListView("columnCheckGroup",
getColumnCheckBoxes())
{
@SuppressWarnings("unchecked")
protected void populateItem(ListItem item)
{
item.add(new Check("columnCheckbox", item.getModel()));
item.add(new Label("displayValue",
new PropertyModel(item.getModel(),
"displayValue")));
}
};
if (columnCheckGroup.getModelObject().isEmpty())
{
columnCheckGroup.setModelObject(this.getDefaultColumns());
}
columnCheckGroup.add(checkBoxes);
queryForm.add(columnCheckGroup);
// more init stuff...
}
public ArrayList<SelectOption> getColumnCheckBoxes()
{
if (columnCheckBoxes == null)
{
columnCheckBoxes = new ArrayList<SelectOption>();
columnCheckBoxes.add(new SelectOption("columnA",
this.columnA.getObject()));
columnCheckBoxes.add(new SelectOption("columnB",
this.columnB.getObject()));
columnCheckBoxes.add(new SelectOption("columnC",
this.columnC.getObject()));
columnCheckBoxes.add(new SelectOption("columnD",
this.columnD.getObject()));
}
return columnCheckBoxes;
}
/*
By default, columns A and B are selected
*/
private ArrayList<SelectOption> getDefaultColumns()
{
ArrayList<SelectOption> defaultColumns = new
ArrayList<SelectOption>();
defaultColumns.add(new SelectOption("columnA",
this.columnA.getObject()));
defaultColumns.add(new SelectOption("columnB",
this.columnB.getObject()));
return defaultColumns;
}
class SelectOption implements Serializable
{
private static final long serialVersionUID = 1L;
private String propertyValue;
private String displayValue;
/**
* Utility class for storing property and display values for
option
* widgets (e.g. drop down lists, check boxes).
*/
public SelectOption(String propertyValue, String displayValue)
{
this.propertyValue = propertyValue;
this.displayValue = displayValue;
}
// getters/setters ....
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Setting Checked Boxes in CheckGroup
Posted by Shelli Orton <Sh...@sjrb.ca>.
I added the missing methods and the default selected options are now checked.
Thanks!
Shelli
-----Original Message-----
From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
Sent: Tuesday, September 28, 2010 9:54 AM
To: users@wicket.apache.org
Subject: Re: Setting Checked Boxes in CheckGroup
your SelectOption class is missing equals and hashcode
-igor
On Tue, Sep 28, 2010 at 8:38 AM, Shelli Orton <Sh...@sjrb.ca> wrote:
> Just wondering if anyone has had a chance to look at the quickstart project and could tell me what I'm doing wrong...
>
> Shelli
>
> -----Original Message-----
> From: Shelli Orton
> Sent: Thursday, September 23, 2010 2:24 PM
> To: users@wicket.apache.org
> Subject: RE: Setting Checked Boxes in CheckGroup
>
> I have attached a sample Eclipse project that exhibits the behaviour. If someone can take the time to look at it and help me solve the problem, it would be greatly appreciated. Please let me know if you need anything else.
>
> Thanks again!
>
> Shelli
>
> -----Original Message-----
> From: Erik van Oosten [mailto:e.vanoosten@grons.nl]
> Sent: Thursday, September 23, 2010 12:13 PM
> To: users@wicket.apache.org
> Subject: Re: Setting Checked Boxes in CheckGroup
>
> See http://wicket.apache.org/start/quickstart.html
>
> Use this to create a small application that exhibits the bug.
>
> Regards,
> Erik.
>
>
> Op 23-09-10 19:26, Shelli Orton schreef:
>> What do you mean by "quickstart"?
>>
>> Shelli
>>
>> -----Original Message-----
>> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
>> Sent: Thursday, September 23, 2010 10:57 AM
>> To: users@wicket.apache.org
>> Subject: Re: Setting Checked Boxes in CheckGroup
>>
>> im going to guess something is wrong with your model. hard to tell
>> without a quickstart.
>>
>> -igor
>>
>
>
>
> --
> Erik van Oosten
> http://www.day-to-day-stuff.blogspot.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
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Setting Checked Boxes in CheckGroup
Posted by Igor Vaynberg <ig...@gmail.com>.
your SelectOption class is missing equals and hashcode
-igor
On Tue, Sep 28, 2010 at 8:38 AM, Shelli Orton <Sh...@sjrb.ca> wrote:
> Just wondering if anyone has had a chance to look at the quickstart project and could tell me what I'm doing wrong...
>
> Shelli
>
> -----Original Message-----
> From: Shelli Orton
> Sent: Thursday, September 23, 2010 2:24 PM
> To: users@wicket.apache.org
> Subject: RE: Setting Checked Boxes in CheckGroup
>
> I have attached a sample Eclipse project that exhibits the behaviour. If someone can take the time to look at it and help me solve the problem, it would be greatly appreciated. Please let me know if you need anything else.
>
> Thanks again!
>
> Shelli
>
> -----Original Message-----
> From: Erik van Oosten [mailto:e.vanoosten@grons.nl]
> Sent: Thursday, September 23, 2010 12:13 PM
> To: users@wicket.apache.org
> Subject: Re: Setting Checked Boxes in CheckGroup
>
> See http://wicket.apache.org/start/quickstart.html
>
> Use this to create a small application that exhibits the bug.
>
> Regards,
> Erik.
>
>
> Op 23-09-10 19:26, Shelli Orton schreef:
>> What do you mean by "quickstart"?
>>
>> Shelli
>>
>> -----Original Message-----
>> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
>> Sent: Thursday, September 23, 2010 10:57 AM
>> To: users@wicket.apache.org
>> Subject: Re: Setting Checked Boxes in CheckGroup
>>
>> im going to guess something is wrong with your model. hard to tell
>> without a quickstart.
>>
>> -igor
>>
>
>
>
> --
> Erik van Oosten
> http://www.day-to-day-stuff.blogspot.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
RE: Setting Checked Boxes in CheckGroup
Posted by Shelli Orton <Sh...@sjrb.ca>.
Just wondering if anyone has had a chance to look at the quickstart project and could tell me what I'm doing wrong...
Shelli
-----Original Message-----
From: Shelli Orton
Sent: Thursday, September 23, 2010 2:24 PM
To: users@wicket.apache.org
Subject: RE: Setting Checked Boxes in CheckGroup
I have attached a sample Eclipse project that exhibits the behaviour. If someone can take the time to look at it and help me solve the problem, it would be greatly appreciated. Please let me know if you need anything else.
Thanks again!
Shelli
-----Original Message-----
From: Erik van Oosten [mailto:e.vanoosten@grons.nl]
Sent: Thursday, September 23, 2010 12:13 PM
To: users@wicket.apache.org
Subject: Re: Setting Checked Boxes in CheckGroup
See http://wicket.apache.org/start/quickstart.html
Use this to create a small application that exhibits the bug.
Regards,
Erik.
Op 23-09-10 19:26, Shelli Orton schreef:
> What do you mean by "quickstart"?
>
> Shelli
>
> -----Original Message-----
> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
> Sent: Thursday, September 23, 2010 10:57 AM
> To: users@wicket.apache.org
> Subject: Re: Setting Checked Boxes in CheckGroup
>
> im going to guess something is wrong with your model. hard to tell
> without a quickstart.
>
> -igor
>
--
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Setting Checked Boxes in CheckGroup
Posted by Shelli Orton <Sh...@sjrb.ca>.
I have attached a sample Eclipse project that exhibits the behaviour. If someone can take the time to look at it and help me solve the problem, it would be greatly appreciated. Please let me know if you need anything else.
Thanks again!
Shelli
-----Original Message-----
From: Erik van Oosten [mailto:e.vanoosten@grons.nl]
Sent: Thursday, September 23, 2010 12:13 PM
To: users@wicket.apache.org
Subject: Re: Setting Checked Boxes in CheckGroup
See http://wicket.apache.org/start/quickstart.html
Use this to create a small application that exhibits the bug.
Regards,
Erik.
Op 23-09-10 19:26, Shelli Orton schreef:
> What do you mean by "quickstart"?
>
> Shelli
>
> -----Original Message-----
> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
> Sent: Thursday, September 23, 2010 10:57 AM
> To: users@wicket.apache.org
> Subject: Re: Setting Checked Boxes in CheckGroup
>
> im going to guess something is wrong with your model. hard to tell
> without a quickstart.
>
> -igor
>
--
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Setting Checked Boxes in CheckGroup
Posted by Erik van Oosten <e....@grons.nl>.
See http://wicket.apache.org/start/quickstart.html
Use this to create a small application that exhibits the bug.
Regards,
Erik.
Op 23-09-10 19:26, Shelli Orton schreef:
> What do you mean by "quickstart"?
>
> Shelli
>
> -----Original Message-----
> From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
> Sent: Thursday, September 23, 2010 10:57 AM
> To: users@wicket.apache.org
> Subject: Re: Setting Checked Boxes in CheckGroup
>
> im going to guess something is wrong with your model. hard to tell
> without a quickstart.
>
> -igor
>
--
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Setting Checked Boxes in CheckGroup
Posted by Shelli Orton <Sh...@sjrb.ca>.
What do you mean by "quickstart"?
Shelli
-----Original Message-----
From: Igor Vaynberg [mailto:igor.vaynberg@gmail.com]
Sent: Thursday, September 23, 2010 10:57 AM
To: users@wicket.apache.org
Subject: Re: Setting Checked Boxes in CheckGroup
im going to guess something is wrong with your model. hard to tell
without a quickstart.
-igor
On Thu, Sep 23, 2010 at 9:25 AM, Shelli Orton <Sh...@sjrb.ca> wrote:
> Does anybody have a suggestion for this?
>
> Thanks,
>
> Shelli
>
> -----Original Message-----
> From: Shelli Orton
> Sent: Wednesday, September 22, 2010 1:54 PM
> To: users@wicket.apache.org
> Subject: Setting Checked Boxes in CheckGroup
>
> Hi,
>
> I am trying to use a CheckGroup to manage which columns are used in a
> datatable. I've set up my columns as per the code below. The
> getColumnCheckBoxes method creates the check boxes that will be part of
> the group. The getDefaultColumns defines which columns should be
> checked by default. The default columns are being set, but the boxes
> are not being displayed as "checked" when the page is first loaded.
> However, the correct columns are being displayed in the datatable, so
> they are being set "behind the scenes".
>
> How do I get them to display as checked on page load?
>
> Thanks in advance!
>
> Shelli
>
> CODE:
>
> public class HomePage extends WebPage
> {
> StringResourceModel columnA = new StringResourceModel("columnA",
> this,
> null);
> StringResourceModel columnB = new StringResourceModel("columnB",
> this,
> null);
> StringResourceModel columnC = new StringResourceModel("columnC",
> this,
> null);
> StringResourceModel columnD = new StringResourceModel("columnD",
> this,
> null);
>
> ArrayList<SelectOption> columnCheckBoxes = null;
>
> CheckGroup<SelectOption> columnCheckGroup = new
> CheckGroup<SelectOption>("columnCheckGroup",
> new ArrayList<SelectOption>());
>
> @SuppressWarnings("rawtypes")
> List<IColumn> columns = new ArrayList<IColumn>();
>
> /**
> * Constructor that is invoked when page is invoked without a
> session.
> *
> * @param parameters Page parameters
> */
> @SuppressWarnings("rawtypes")
> public HomePage(final PageParameters parameters)
> {
> @SuppressWarnings("serial")
> Form queryForm = new Form("queryForm")
> {
> @Override
> protected void onSubmit()
> {
> // do stuff
> }
> };
>
> add(queryForm);
>
> // Create column selection boxes
> columnCheckGroup.add(new
> CheckGroupSelector("columnCheckGroupSelector"));
>
> @SuppressWarnings({ "unchecked", "serial" })
> ListView checkBoxes = new ListView("columnCheckGroup",
> getColumnCheckBoxes())
> {
> @SuppressWarnings("unchecked")
> protected void populateItem(ListItem item)
> {
> item.add(new Check("columnCheckbox", item.getModel()));
> item.add(new Label("displayValue",
> new PropertyModel(item.getModel(),
> "displayValue")));
> }
>
> };
>
> if (columnCheckGroup.getModelObject().isEmpty())
> {
> columnCheckGroup.setModelObject(this.getDefaultColumns());
> }
>
> columnCheckGroup.add(checkBoxes);
> queryForm.add(columnCheckGroup);
>
> // more init stuff...
>
> }
>
> public ArrayList<SelectOption> getColumnCheckBoxes()
> {
> if (columnCheckBoxes == null)
> {
> columnCheckBoxes = new ArrayList<SelectOption>();
>
> columnCheckBoxes.add(new SelectOption("columnA",
> this.columnA.getObject()));
> columnCheckBoxes.add(new SelectOption("columnB",
> this.columnB.getObject()));
> columnCheckBoxes.add(new SelectOption("columnC",
> this.columnC.getObject()));
> columnCheckBoxes.add(new SelectOption("columnD",
> this.columnD.getObject()));
> }
>
> return columnCheckBoxes;
> }
>
> /*
> By default, columns A and B are selected
> */
> private ArrayList<SelectOption> getDefaultColumns()
> {
> ArrayList<SelectOption> defaultColumns = new
> ArrayList<SelectOption>();
>
> defaultColumns.add(new SelectOption("columnA",
> this.columnA.getObject()));
> defaultColumns.add(new SelectOption("columnB",
> this.columnB.getObject()));
>
> return defaultColumns;
> }
>
> class SelectOption implements Serializable
> {
> private static final long serialVersionUID = 1L;
>
> private String propertyValue;
> private String displayValue;
>
> /**
> * Utility class for storing property and display values for
> option
> * widgets (e.g. drop down lists, check boxes).
> */
> public SelectOption(String propertyValue, String displayValue)
> {
> this.propertyValue = propertyValue;
> this.displayValue = displayValue;
> }
>
> // getters/setters ....
> }
> }
>
>
> ---------------------------------------------------------------------
> 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
>
>
---------------------------------------------------------------------
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
Re: Setting Checked Boxes in CheckGroup
Posted by Igor Vaynberg <ig...@gmail.com>.
im going to guess something is wrong with your model. hard to tell
without a quickstart.
-igor
On Thu, Sep 23, 2010 at 9:25 AM, Shelli Orton <Sh...@sjrb.ca> wrote:
> Does anybody have a suggestion for this?
>
> Thanks,
>
> Shelli
>
> -----Original Message-----
> From: Shelli Orton
> Sent: Wednesday, September 22, 2010 1:54 PM
> To: users@wicket.apache.org
> Subject: Setting Checked Boxes in CheckGroup
>
> Hi,
>
> I am trying to use a CheckGroup to manage which columns are used in a
> datatable. I've set up my columns as per the code below. The
> getColumnCheckBoxes method creates the check boxes that will be part of
> the group. The getDefaultColumns defines which columns should be
> checked by default. The default columns are being set, but the boxes
> are not being displayed as "checked" when the page is first loaded.
> However, the correct columns are being displayed in the datatable, so
> they are being set "behind the scenes".
>
> How do I get them to display as checked on page load?
>
> Thanks in advance!
>
> Shelli
>
> CODE:
>
> public class HomePage extends WebPage
> {
> StringResourceModel columnA = new StringResourceModel("columnA",
> this,
> null);
> StringResourceModel columnB = new StringResourceModel("columnB",
> this,
> null);
> StringResourceModel columnC = new StringResourceModel("columnC",
> this,
> null);
> StringResourceModel columnD = new StringResourceModel("columnD",
> this,
> null);
>
> ArrayList<SelectOption> columnCheckBoxes = null;
>
> CheckGroup<SelectOption> columnCheckGroup = new
> CheckGroup<SelectOption>("columnCheckGroup",
> new ArrayList<SelectOption>());
>
> @SuppressWarnings("rawtypes")
> List<IColumn> columns = new ArrayList<IColumn>();
>
> /**
> * Constructor that is invoked when page is invoked without a
> session.
> *
> * @param parameters Page parameters
> */
> @SuppressWarnings("rawtypes")
> public HomePage(final PageParameters parameters)
> {
> @SuppressWarnings("serial")
> Form queryForm = new Form("queryForm")
> {
> @Override
> protected void onSubmit()
> {
> // do stuff
> }
> };
>
> add(queryForm);
>
> // Create column selection boxes
> columnCheckGroup.add(new
> CheckGroupSelector("columnCheckGroupSelector"));
>
> @SuppressWarnings({ "unchecked", "serial" })
> ListView checkBoxes = new ListView("columnCheckGroup",
> getColumnCheckBoxes())
> {
> @SuppressWarnings("unchecked")
> protected void populateItem(ListItem item)
> {
> item.add(new Check("columnCheckbox", item.getModel()));
> item.add(new Label("displayValue",
> new PropertyModel(item.getModel(),
> "displayValue")));
> }
>
> };
>
> if (columnCheckGroup.getModelObject().isEmpty())
> {
> columnCheckGroup.setModelObject(this.getDefaultColumns());
> }
>
> columnCheckGroup.add(checkBoxes);
> queryForm.add(columnCheckGroup);
>
> // more init stuff...
>
> }
>
> public ArrayList<SelectOption> getColumnCheckBoxes()
> {
> if (columnCheckBoxes == null)
> {
> columnCheckBoxes = new ArrayList<SelectOption>();
>
> columnCheckBoxes.add(new SelectOption("columnA",
> this.columnA.getObject()));
> columnCheckBoxes.add(new SelectOption("columnB",
> this.columnB.getObject()));
> columnCheckBoxes.add(new SelectOption("columnC",
> this.columnC.getObject()));
> columnCheckBoxes.add(new SelectOption("columnD",
> this.columnD.getObject()));
> }
>
> return columnCheckBoxes;
> }
>
> /*
> By default, columns A and B are selected
> */
> private ArrayList<SelectOption> getDefaultColumns()
> {
> ArrayList<SelectOption> defaultColumns = new
> ArrayList<SelectOption>();
>
> defaultColumns.add(new SelectOption("columnA",
> this.columnA.getObject()));
> defaultColumns.add(new SelectOption("columnB",
> this.columnB.getObject()));
>
> return defaultColumns;
> }
>
> class SelectOption implements Serializable
> {
> private static final long serialVersionUID = 1L;
>
> private String propertyValue;
> private String displayValue;
>
> /**
> * Utility class for storing property and display values for
> option
> * widgets (e.g. drop down lists, check boxes).
> */
> public SelectOption(String propertyValue, String displayValue)
> {
> this.propertyValue = propertyValue;
> this.displayValue = displayValue;
> }
>
> // getters/setters ....
> }
> }
>
>
> ---------------------------------------------------------------------
> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: Setting Checked Boxes in CheckGroup
Posted by Shelli Orton <Sh...@sjrb.ca>.
Does anybody have a suggestion for this?
Thanks,
Shelli
-----Original Message-----
From: Shelli Orton
Sent: Wednesday, September 22, 2010 1:54 PM
To: users@wicket.apache.org
Subject: Setting Checked Boxes in CheckGroup
Hi,
I am trying to use a CheckGroup to manage which columns are used in a
datatable. I've set up my columns as per the code below. The
getColumnCheckBoxes method creates the check boxes that will be part of
the group. The getDefaultColumns defines which columns should be
checked by default. The default columns are being set, but the boxes
are not being displayed as "checked" when the page is first loaded.
However, the correct columns are being displayed in the datatable, so
they are being set "behind the scenes".
How do I get them to display as checked on page load?
Thanks in advance!
Shelli
CODE:
public class HomePage extends WebPage
{
StringResourceModel columnA = new StringResourceModel("columnA",
this,
null);
StringResourceModel columnB = new StringResourceModel("columnB",
this,
null);
StringResourceModel columnC = new StringResourceModel("columnC",
this,
null);
StringResourceModel columnD = new StringResourceModel("columnD",
this,
null);
ArrayList<SelectOption> columnCheckBoxes = null;
CheckGroup<SelectOption> columnCheckGroup = new
CheckGroup<SelectOption>("columnCheckGroup",
new ArrayList<SelectOption>());
@SuppressWarnings("rawtypes")
List<IColumn> columns = new ArrayList<IColumn>();
/**
* Constructor that is invoked when page is invoked without a
session.
*
* @param parameters Page parameters
*/
@SuppressWarnings("rawtypes")
public HomePage(final PageParameters parameters)
{
@SuppressWarnings("serial")
Form queryForm = new Form("queryForm")
{
@Override
protected void onSubmit()
{
// do stuff
}
};
add(queryForm);
// Create column selection boxes
columnCheckGroup.add(new
CheckGroupSelector("columnCheckGroupSelector"));
@SuppressWarnings({ "unchecked", "serial" })
ListView checkBoxes = new ListView("columnCheckGroup",
getColumnCheckBoxes())
{
@SuppressWarnings("unchecked")
protected void populateItem(ListItem item)
{
item.add(new Check("columnCheckbox", item.getModel()));
item.add(new Label("displayValue",
new PropertyModel(item.getModel(),
"displayValue")));
}
};
if (columnCheckGroup.getModelObject().isEmpty())
{
columnCheckGroup.setModelObject(this.getDefaultColumns());
}
columnCheckGroup.add(checkBoxes);
queryForm.add(columnCheckGroup);
// more init stuff...
}
public ArrayList<SelectOption> getColumnCheckBoxes()
{
if (columnCheckBoxes == null)
{
columnCheckBoxes = new ArrayList<SelectOption>();
columnCheckBoxes.add(new SelectOption("columnA",
this.columnA.getObject()));
columnCheckBoxes.add(new SelectOption("columnB",
this.columnB.getObject()));
columnCheckBoxes.add(new SelectOption("columnC",
this.columnC.getObject()));
columnCheckBoxes.add(new SelectOption("columnD",
this.columnD.getObject()));
}
return columnCheckBoxes;
}
/*
By default, columns A and B are selected
*/
private ArrayList<SelectOption> getDefaultColumns()
{
ArrayList<SelectOption> defaultColumns = new
ArrayList<SelectOption>();
defaultColumns.add(new SelectOption("columnA",
this.columnA.getObject()));
defaultColumns.add(new SelectOption("columnB",
this.columnB.getObject()));
return defaultColumns;
}
class SelectOption implements Serializable
{
private static final long serialVersionUID = 1L;
private String propertyValue;
private String displayValue;
/**
* Utility class for storing property and display values for
option
* widgets (e.g. drop down lists, check boxes).
*/
public SelectOption(String propertyValue, String displayValue)
{
this.propertyValue = propertyValue;
this.displayValue = displayValue;
}
// getters/setters ....
}
}
---------------------------------------------------------------------
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
RE: PropertyModel getObject returns null
Posted by Shelli Orton <Sh...@sjrb.ca>.
I figured out what was happening. The object returned by getObject is
the property value, not the model object (I'm still wrapping my head
around Wicket terminology/architecture). I found this example of a
compare method that deals with nulls:
class DataRecordComparator implements Comparator<DataRecord>,
Serializable
{
private static final long serialVersionUID = 1L;
@SuppressWarnings({ "rawtypes", "unchecked" })
public int compare(final DataRecord o1, final DataRecord o2)
{
PropertyModel<Comparable> model1 = new
PropertyModel<Comparable>(o1,
getSort().getProperty());
PropertyModel<Comparable> model2 = new
PropertyModel<Comparable>(o2,
getSort().getProperty());
int result = 0;
if (model1.getObject() == null && model2.getObject() ==
null)
{
result = 0;
}
else if (model1.getObject() == null)
{
result = 1;
}
else if (model2.getObject() == null)
{
result = -1;
}
else
{
result = ((Comparable)
model1.getObject()).compareTo(model2.getObject());
}
if (!getSort().isAscending())
{
result = -result;
}
return result;
}
}
-----Original Message-----
From: Shelli Orton
Sent: Wednesday, September 22, 2010 2:42 PM
To: users@wicket.apache.org
Subject: PropertyModel getObject returns null
Hi,
I followed the example on this page
https://cwiki.apache.org/WICKET/simple-sortable-datatable-example.html
to create a SortableDataProvider. I am running into a
NullPointerException when my Comparator class' compare method is invoked
at
int result = model1.getObject().compareTo(model2.getObject());
My class is exactly the same as the example code except for the type of
objects passed in to the method and used in <Type>.
The model1.getObject() is returning null. I have confirmed in debugging
that model1 has both a valid expression and target set.
How does the object get set in a PropertyModel?
Thanks in advance!
Shelli
---------------------------------------------------------------------
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
PropertyModel getObject returns null
Posted by Shelli Orton <Sh...@sjrb.ca>.
Hi,
I followed the example on this page
https://cwiki.apache.org/WICKET/simple-sortable-datatable-example.html
to create a SortableDataProvider. I am running into a
NullPointerException when my Comparator class' compare method is invoked
at
int result = model1.getObject().compareTo(model2.getObject());
My class is exactly the same as the example code except for the type of
objects passed in to the method and used in <Type>.
The model1.getObject() is returning null. I have confirmed in debugging
that model1 has both a valid expression and target set.
How does the object get set in a PropertyModel?
Thanks in advance!
Shelli
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org