Re: Enums and DropDownChoices in Web Beans

2007-09-20 Thread Dan Syrstad
On 9/20/07, dtoffe <[EMAIL PROTECTED]> wrote:
>
>
> For most cases, the PropertyChangeEvents are ok. But now I'm facing a
> particular problem and I guess I'm trying to use the wrong tool for the
> task.
> Let's say I have a bean with two properties and I want to show them as
> dropdownchoices, but they are related, think for example of the CarMake,
> CarModel, or Country, State pairs, where the first value determines a
> subset
> of possibilities for the second value.
> I would like to select the first value, and have the second
> dropdownchoice to get filtered by the possible values. How should I face
> such a situation ?  I guess having the second dropdownchoice based on an
> enum is not correct, since I only want a (non necessarily contiguous)
> subset
> of values to be allowed.
>
> Thanks for your help !
>
> Daniel



I've created a new example in the
wicket.contrib.webbeans.examples.dependentfields package that illustrates
this. You'll need to get the latest WWB code from SVN (rev 28) to run the
example. The example is based on the Wicket Ajax example with a Car Make and
Model (two dependent drop-down fields). Basically, you need to implement a
custom field for the Car's Model (an enum), because it is dependent on the
Make enum:

public class ModelField extends EnumField
{
private ElementMetaData makeProp;

public ModelField(String id, IModel model, ElementMetaData metaData,
boolean viewOnly)
{
// Init with an empty set of values. We can't build the list until
later.
super(id, model, metaData, viewOnly, Collections.EMPTY_LIST);

// Retrieve the parameter that defines which Make property we need.
makeProp = getDependentProperty(metaData, "makeProp", Make.class);

setValuesModel( new ValuesModel() );
}

private final class ValuesModel extends AbstractReadOnlyModel
{
@Override
public Object getObject(Component component)
{
// Retrieve the value of the dependent property.
Make make = (Make)getDependentPropertyBean(makeProp);
if (make != null) {
// Build a list of models based on the make.
List values = new ArrayList();
for (Model modelChoice : Model.values()) {
if (modelChoice.getMake().equals(make)) {
values.add(modelChoice);
}
}

return values;
}

return Collections.EMPTY_LIST;
}
}
}


And in beanprops, you would say:

Car {
cols: 1;
props:make, model{ makeProp: make };
}

On the "model" property, I specified the "makeProp" parameter (defined by
ModelField) to specify which Make property in your bean that it should be
dependent on. And viola, changing the Car's Make causes the list of choices
for the Car's Model to change - in real-time via Ajax. The advantage here is
that this field can be reused over and over wherever you may have a
Make/Model pair.


Re: Enums and DropDownChoices in Web Beans

2007-09-20 Thread dtoffe

For most cases, the PropertyChangeEvents are ok. But now I'm facing a
particular problem and I guess I'm trying to use the wrong tool for the
task.
Let's say I have a bean with two properties and I want to show them as
dropdownchoices, but they are related, think for example of the CarMake,
CarModel, or Country, State pairs, where the first value determines a subset
of possibilities for the second value.
I would like to select the first value, and have the second
dropdownchoice to get filtered by the possible values. How should I face
such a situation ?  I guess having the second dropdownchoice based on an
enum is not correct, since I only want a (non necessarily contiguous) subset
of values to be allowed.

Thanks for your help !

Daniel



Dan Syrstad-2 wrote:
> 
> I assume your real-life case is more involved than just calling info().
> See
> the Introduction/Getting Started documentation at
> http://wicketwebbeans.sourceforge.net for an examples on how to implement
> PropertyChangeEvents and how to do #2 above.
> 

-- 
View this message in context: 
http://www.nabble.com/Enums-and-DropDownChoices-in-Web-Beans-tf4481885.html#a12796948
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Enums and DropDownChoices in Web Beans

2007-09-19 Thread Dan Syrstad
On 9/19/07, dtoffe <[EMAIL PROTECTED]> wrote:
>
>
> Hi !
>
> I want to make an Enum field in a bean to fire an event. With plain
> Wicket I can do something like:
>
> DropDownChoice ddc = new DropDownChoice("person", options) {
>
> public void onSelectionChanged(java.lang.Object
> newSelection) {
> info("Changed!");
> }
>
> protected boolean wantOnSelectionChangedNotifications() {
> return true;
> }
> }
>
> How can I do this in Web Beans, is there any beanprops that I can use
> ?


WWB is oriented around changes to bean properties. You work with your bean
directly and not the Wicket components. Changing a form drop-down that's
associated with an enum property on your bean causes WWB to call the setter
on your bean as soon as the change occurs. You can update your model from
that point as appropriate. You can also fire PropertyChangeEvents from your
bean to cause other related fields to be refreshed. I think for most cases,
this is sufficient.

However, if you want to perform your exact example above (calling info()),
you have two basic choices:

1. Have your Page/Component containing the BeanForm listen to your bean for
PropertyChangeEvents and invoke info() when the enum property changes.
2. Create a sub-class of EnumField and register it with ComponentRegistry.
You custom enum field can implement the code you have above directly.

I assume your real-life case is more involved than just calling info(). See
the Introduction/Getting Started documentation at
http://wicketwebbeans.sourceforge.net for an examples on how to implement
PropertyChangeEvents and how to do #2 above.

-Dan

Thanks !
>
> Daniel
>


Enums and DropDownChoices in Web Beans

2007-09-19 Thread dtoffe

Hi !

I want to make an Enum field in a bean to fire an event. With plain
Wicket I can do something like:

DropDownChoice ddc = new DropDownChoice("person", options) {

public void onSelectionChanged(java.lang.Object
newSelection) {
info("Changed!");
}

protected boolean wantOnSelectionChangedNotifications() {
return true;
}
}

How can I do this in Web Beans, is there any beanprops that I can use ?

Thanks !

Daniel

-- 
View this message in context: 
http://www.nabble.com/Enums-and-DropDownChoices-in-Web-Beans-tf4481885.html#a12780572
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]