You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Java Programmer <jp...@gmail.com> on 2007/12/07 14:11:05 UTC
Any example of using DataView with Forms?
hello,
I have problem with setting Forms on DataView. I have list of Consumer
objects, each consumer has Set of attributes, I wanted to add
DropDownChoice with all attributes, when pressing Add consumer would
get new attribute to its Set, and will be saved in database. Quite
simply but not form me :(
Some ugly spike code:
private class ConsumerDataView extends DataView {
public ConsumerDataView(String id, ConsumerDataProvider dataProvider) {
super(id, dataProvider);
}
protected void populateItem(Item item) {
final Consumer consumer = (Consumer) item.getModelObject();
item.setModel(new CompoundPropertyModel(consumer));
item.add(new Label("name"));
Form addAttributeForm = new Form("addAttributeForm") {
protected void onSubmit() {
System.out.println(getModel().getObject());
}
};
/* AttributeDescriptorProvider attributeDescriptorProvider
= new AttributeDescriptorProvider();
DropDownChoice attributeDescriptor = new
DropDownChoice("attributeDescriptors",
new PropertyModel(attributeDescriptorProvider,
"attributeDescriptor"),
getAttributeDAO().getAllAttributeDescriptors()); */
DropDownChoice attributeDescriptor = new
DropDownChoice("attributeDescriptors", new Model(new
AttributeDescriptor()),
getAttributeDAO().getAllAttributeDescriptors());
addAttributeForm.add(attributeDescriptor);
item.add(addAttributeForm);
}
}
Submiting this form results in WicketMessage: No get method defined
for class: class com.test.entities.Consumer expression:
addAttributeForm
I consider that addAttributeForm doesn't belongs to object, but does
this mean that I cannot nest forms in data view?
HTML code of form:
<tr wicket:id="consumers">
<td>
<form style="margin:0;" wicket:id="addAttributeForm">
<select wicket:id="attributeDescriptors">
<option>[option]</option>
</select>
<input type="submit" value="Add" />
</form>
</td>
<td>
<input type="checkbox" wicket:id="selected" />
</td>
</tr>
Any idea what should be done to get it work?
Best regards,
Adr
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Any example of using DataView with Forms?
Posted by Newgro <pe...@gmx.ch>.
Hi Adr,
http://www.cs.tut.fi/~jkorpela/forms/tables.html Here they say that you
have to put the form around the table. Maybe it works for you.
Cheers
Per
--
View this message in context: http://www.nabble.com/Any-example-of-using-DataView-with-Forms--tf4962008.html#a14212791
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
Re: Any example of using DataView with Forms?
Posted by Java Programmer <jp...@gmail.com>.
Oh I did it ...
The previous code need small changes:
Model model = new Model(new AttributeDescriptor());
addAttributeForm.setModel(model);
DropDownChoice attributeDescriptor = new
DropDownChoice("attributeDescriptors", model,
getAttributeDAO().getAllAttributeDescriptors());
and then we can use:
protected void onSubmit() {
AttributeDescriptor attributeDescriptor =
(AttributeDescriptor) getModel().getObject();
consumer.getAttributeDescriptor().add(attributeDescriptor);
try {
getConsumerService().changeAttributesDescr(consumer.getName(),
consumer.getAttributeDescriptor());
} catch (ConsumerException e) {
e.printStackTrace();
}
}
consumer also was removed from model (removed line item.setModel(new
CompoundPropertyModel(consumer)); )
so form could its own model ...
Maybe there is better solution for this, but that is working so it
maybe helps someone ....
Best regards,
Adr
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org