In the Button.onSubmit do getForm.visitChildren(FormComponent.class,
new IVisitor()
{
public Object component(Component component)
{
//do something with the models from the components here.
}
}
Maurice
On Fri, Jun 13, 2008 at 2:10 PM, wfroud <[EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> I have successfully written some code to create a dynamic form depending on
> drop down selection.
>
> I have used the technique described here
> http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html
>
> A shortened copy of the code is below.
>
> The problem I'm now having is how to extract data entered into the
> dynamically generated components.
> I'm starting with trying to get information from the TextField component, so
> any help regarding
> this would be of enormous help. Please refer to the TODO comments below, I
> think I'm close.
>
>
> // Define a model to hold values for any component, at the moment just the
> TextField.
>
> final ComponentPanelModel compPanelModel = new ComponentPanelModel();
>
> // Define the list model.
>
> final List paramsList = getParamPanels(queryDef, compPanelModel);
>
> IModel paramsModel = new LoadableDetachableModel() {
> protected Object load() {
> return paramsList;
> }
> };
>
> // Then add the list to the page.
>
> f.add(new ListView("paramsList", paramsModel) {
>
> @Override
> public ListView setReuseItems(boolean arg) {
> // According to
> http://cwiki.apache.org/WICKET/using-listviews.html
> // we need to add this or items will be removed and re-added,
> // without being validated.
> return super.setReuseItems(true);
> }
>
> @Override
> protected void populateItem(ListItem item) {
> Panel p = (Panel) item.getModelObject();
> item.setModel(new CompoundPropertyModel(p));
> item.add(p);
> }
>
> private void optimizedItemRemoval() {
> // According to
> http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html
> // this should be used to prevent components from forgetting
> content.
> // Not sure how to yet.
> }
> });
>
> // This is the method that returns the various panels:
>
> public List getParamPanels(QueryDef queryDef, ComponentPanelModel compModel)
> {
>
> List<Panel> params = new ArrayList<Panel>();
> if (queryDef == null) {
> return params;
> }
>
> List<QueryDefParam> qdp =
> queryDefParamDao.getQueryDefParams(queryDef.getQueryDefId());
>
> for (QueryDefParam p : qdp) {
>
> if ("TextField".equals(p.getName())) {
> params.add(new TextFieldPanel("panel", new
> CompoundPropertyModel(compModel), p.getDescription()));
> }
> else if ("CheckBox".equals(p.getName())) {
> params.add(new CheckBoxPanel("panel", null,
> p.getDescription()));
> }
>
> }
>
> return params;
> }
>
> f.add(new Button("save") {
> public void onSubmit() {
>
> // TODO Iterate through the list of panels, which may differ
> TextField,
> Check box etc.
> // TODO For each one we need to be able to access the model
> objects value.
>
> }
> });
>
>
> public class ComponentPanelModel {
> private String textField;
>
> public String getTextField() {
> return textField;
> }
>
> public void setTextField(String textField) {
> this.textField = textField;
> }
> }
>
> public class TextFieldPanel extends Panel {
> public TextFieldPanel(String name, IModel model, String description) {
> super(name, model);
> add(new TextField("textField"));
> add(new Label("description", description));
> }
> }
>
> public class CheckBoxPanel extends Panel {
> public CheckBoxPanel(String name, IModel model, String description) {
> super(name, model);
> add(new CheckBox("checkBox", new Model()));
> add(new Label("description", description));
> }
> }
>
> Thanks again.
>
> Will
> --
> View this message in context:
> http://www.nabble.com/Dynamic-Form-Data-Retrieval-tp17822033p17822033.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]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]