Hello everybody,
I have a problem with wicket.extensions.markup.html.form.select.Select.
If a form containing such a dropdown is submitted with errors, the
selection is not remembered.
I have attached a simple demonstration showing that, which can be put
into QuickStart directly. The textfield is required. If you keep it
empty, and select e.g. Option 3, Option 1 will be selected again after
the submit. If you submit the form successfully, Option 3 is selected.
If you leave the textfield empty again, and select Option 2, Option 3
will be the one to show up. I can't say for sure if this is a bug, but
it seems like that to me.
Coming that far was hard enough, so if this could be worked out, I'd be
glad to put a usage example in the Wiki (the JavaDocs lack a usage example).
A thing that bothers me with adding options that way, is that there
needs to be a span inside the <optgroup>, because if I put the wicket:id
into the <optgroup>, it will not show up in the HTML (just its
children). Having to put a <option wicket:id="option"></option> inside
of it was a bit weird to me at the beginning, but this is not a problem,
if it were mentioned in the docs somewhere :)
Another problem I still have is with understanding model chaining. In
the example you can also see a (commented out) Label, which should
display the current value of the dropDown property of the model bean. I
thought this could be done with a chained PropertyModel. But the value
for the Label still seems to be taken via the id of the Component, and
not via the expression provided with PropertyModel. What would be the
correct way to do this, other than changing the id of the Label?
--
It's a Blog now:
http://www.2rue.de <cid:[email protected]>
Title: QuickStart
QuickStart
package wicket.quickstart;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import wicket.PageParameters;
import wicket.extensions.markup.html.form.select.IOptionRenderer;
import wicket.extensions.markup.html.form.select.Select;
import wicket.extensions.markup.html.form.select.SelectOptions;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.Form;
import wicket.markup.html.form.TextField;
import wicket.markup.html.panel.FeedbackPanel;
import wicket.model.CompoundPropertyModel;
import wicket.model.IModel;
import wicket.model.Model;
import wicket.model.PropertyModel;
/**
* Basic bookmarkable index page.
*
* NOTE: You can get session properties from QuickStartSession via
getQuickStartSession()
*/
public class Index extends QuickStartPage {
/**
* Very simple IOptionRenderer.
*/
private static final IOptionRenderer OPTION_RENDERER = new
IOptionRenderer() {
public String getDisplayValue(Object object) {
return String.valueOf(object);
}
public IModel getModel(Object value) {
return new Model((Serializable) value);
}
};
/**
* Some values for the dropdown
*/
private static List dropDownValues = new ArrayList();
static {
dropDownValues.add("Option 1");
dropDownValues.add("Option 2");
dropDownValues.add("Option 3");
}
/**
* Constructor that is invoked when page is invoked without a session.
*
* @param parameters Page parameters
*/
public Index(final PageParameters parameters) {
// create the model bean, and manage access through
CompoundPropertyModel
ModelBean bean = new ModelBean();
IModel model = new CompoundPropertyModel(bean);
Form form = new Form("testForm", model);
// display form errors
form.add(new FeedbackPanel("feedback"));
// Dropdown with a single optgroup
Select dropDown = new Select("dropDown");
dropDown.add(new SelectOptions("optGroup1", dropDownValues,
OPTION_RENDERER));
form.add(dropDown);
// textfield to show wrong behaviour through form errors
form.add(new TextField("textField").setRequired(true));
add(form);
// Doesn't work
// WicketMessage: No get method defined for
// class: class wicket.quickstart.Index$ModelBean
// expression: debugLabel
// Label l = new Label("debugLabel", new PropertyModel(model,
"dropDown"));
// add(l);
}
/**
* Simple model bean for storing form input.
*/
public class ModelBean {
private String dropDown;
private String textField;
/**
* Get the dropDown.
* @return Returns the dropDown.
*/
public String getDropDown() {
return this.dropDown;
}
/**
* Get the textField.
* @return Returns the textField.
*/
public String getTextField() {
return this.textField;
}
/**
* Set the dropDown.
* @param dropDown The dropDown to set.
*/
public void setDropDown(String dropDown) {
this.dropDown = dropDown;
}
/**
* Set the textField.
* @param textField The textField to set.
*/
public void setTextField(String textField) {
this.textField = textField;
}
}
}
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user