First:
You bind the DDC to the wrong model. You bind it directly to the LDM
instead of the vendor's state property.
DropDownChoice stateFC = new DropDownChoice("state", states, choiceRenderer);
should be sufficient.
Second:
Your current setup assumes that the Vendor#state is of type
SelectOption (from the point of view of the DDC's model setup). I
would rewrite your setup to the following: make State a first class
citizen. Something like:
public class State {
private String short;
private String name;
..... geters/setters
}
and then:
public class Vendor {
private State state;
}
ArrayList<State> states = Arrays.asList(new State("AL", "Alabama"), ...);
DropDownChoice stateFC = new DropDownChoice("state", new
PropertyModel(vendorModel, "state"), states, new
ChoiceRenderer("short", "name");
(I've added the propertymodel to clarify to which property you
actually bind). Now everything should line up correctly.
Martijn
On 3/10/08, rmattler <[EMAIL PROTECTED]> wrote:
>
> I don't understand. Vendor.state and SelectOption.state are both Strings.
>
> I cut down my form to only have state on the form so I can post all the
> code. The code pulls the correct data from the database and displays it on
> the form but when I save it is gives me the following error.
>
>
> java.lang.UnsupportedOperationException: Model class
>
> com.myprepress.pages.vendor.profile.VendorEntry2$1 does not support
> setObject(Object)
>
>
> <html>
> <form wicket:id="vendorEntryForm2">
> <select wicket:id="state">
> <option></option>
> </select>
> <input type="submit" wicket:id="save" value="Save"><br>
> </form>
> </html>
>
> public class VendorEntry2 extends BasePage {
>
> @SpringBean
> VendorDAO vendorDAO;
> private long tblId;
> private Integer oldVersionNumber;
>
> public VendorEntry2(long id) {
>
> tblId = id;
> // get the version number to ensure that the object hasn't
> been saved to
> // the database by another users
> // -1 is a new object
> if (id != -1) {
> Vendor vendor = null;
> try {
> vendor = vendorDAO.load(id);
> oldVersionNumber = vendor.getVersionNumber();
> } catch (DataObjectNotFoundException donfe) {
> getSession().error("Object not found");
> throw new RestartResponseException(new
> ErrorObjectNotFound(new
> VendorList()));
> }
> }
>
> // load the object to be displayed to the screen
> // make it LoadableDetachableModel so it is not stored in the
> session
> // -1 is a new object
>
> IModel vendorModel = new LoadableDetachableModel() {
> protected Object load() {
>
> if (tblId == -1) {
> return new Vendor();
> } else {
> return vendorDAO.load(tblId);
> }
> }
> };
>
> // add form
> Form form = new Form("vendorEntryForm2", new
> CompoundPropertyModel(vendorModel)) {
> protected void onSubmit() {
> Vendor updatedVendor = (Vendor)
> getModelObject();
> try {
> vendorDAO.save(updatedVendor,
> oldVersionNumber);
> setResponsePage(VendorList.class);
> } catch (DataObjectModifiedException dome) {
> // try again");
> setResponsePage(new VendorEntryError(
> "Data changed by
> another user. Please refresh and try again.",
> tblId));
> }
> }
> };
> add(form); // must add form before adding other components
>
>
> // add state
> ArrayList<SelectOption> states = new
> ArrayList<SelectOption>();
> states.add(new SelectOption("AL", "Alabama"));
> states.add(new SelectOption("OH", "Ohio"));
> states.add(new SelectOption("NY", "New York"));
> ChoiceRenderer choiceRenderer = new ChoiceRenderer("display",
> "state");
>
> DropDownChoice stateFC = new DropDownChoice("state",
> vendorModel, new
> Model(states),
> choiceRenderer);
>
> form.add(stateFC);
>
> // add submit button
> form.add(new Button("save"));
>
> }
>
> }
>
> @Entity
> @Table(name = "vendor", schema = "public")
>
> public class Vendor implements java.io.Serializable {
>
>
> private long tblId;
> private String state;
>
>
> @Column(name = "state", length = 2)
> public String getState() {
> return this.state;
> }
>
> public void setState(String state) {
> this.state = state;
> }
>
>
>
>
>
>
> Johan Compagner wrote:
> >
> > This has to work yes, the only thing is do build up the new
> > Model(states) as States so the same type of object as vendor.state
> > returns.
> >
> > On 3/7/08, Kai Mutz <[EMAIL PROTECTED]> wrote:
> >> [EMAIL PROTECTED] <> wrote:
> >> > It is nice to know I'm not the only one struggling with
> >> > DropDownChoices. I'm new to Wicket and I'm pretty far with
> >> > rebuilding an application we are using internally. Has anybody
> >> > proposed an alternative or a wrapper to DropDownChoices?
> >>
> >> Have you tried something like:
> >>
> >> Vendor vendor = (Vendor) vendorModel.getObject();
> >>
> >> DropDownChoice stateFC = new DropDownChoice("state", new
> >> PropertyModel(vendor, "state"), new Model(states), choiceRenderer);
> >>
> >> This should work.
> >>
> >> Kai
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
> --
> View this message in context:
> http://www.nabble.com/DropDownChoice-getting-value-into-the-model-tp15905486p15950742.html
>
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.1 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]