Model for form with variable number of fields

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Model for form with variable number of fields

Tauren Mills
Hello,

I have a process that reads a CSV data file.  The data contains lists
of people, but the number of fields, the order and the type of fields
can vary from one CSV to another.

Because the data in each column is unknown, a form is displayed with a
preview of the data in a table.  The table column headers contain
dropdown list of possible field types for each column in the csv file.
 I'm using a RepeatingView to generate the headers.

The problem is, I'm unclear how to design the CompoundPropertyModel
for the form.  I assume my model needs to contain a collection of some
sort since I have a varying number of field.  But how do I map the set
of RepeatingView->WebMarkupContainer->DropDownChoice objects to the
model as a collection?

Here's the code:

preview = importer.previewImport(new FileInputStream(dataFile),10,2);
  ...
RepeatingView headers = new RepeatingView("header");
form.add(headers);
int numFields = preview.getRecords()[0].getFields().length;
for (int j = 0; j < numFields; j++) {
  WebMarkupContainer cell = new WebMarkupContainer(headers.newChildId());
  headers.add(cell);
  cell.add(new EdiCriteriaDropDownChoice("criteria").setRequired(true));
}

And the markup:

        <table cellspacing="1">
          <tr>
          <th wicket:id="header">
                  <select name="select" wicket:id="criteria"></select>
          </th>
          </tr>
           ...
        </table>

What kind of model would work with this?

Thanks,
Tauren

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
IMPORTANT NOTICE:

This mailing list is shutting down. Please subscribe to the Apache Wicket user list. Send a message to: "users-subscribe at wicket.apache.org" and follow the instructions.
_______________________________________________
Wicket-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/wicket-user
Reply | Threaded
Open this post in threaded view
|

Re: Model for form with variable number of fields

Igor Vaynberg-2
dont use a compound model, that is just a shortcut for common cases.

create a model that keeps an index and a ref to the list model, and pulls
things in and out like that.

class indexedmodel implements imodel {
  private final imodel list;
  private final int index;

  getobject() { return list.getobject().get(index); }
  setobject(object o) { list.getobject().set(index, o); }
  detach() { list.detach(); }
}

and pass one of those to the dropdownchoice

-igor


On 8/4/07, Tauren Mills <[hidden email]> wrote:

>
> Hello,
>
> I have a process that reads a CSV data file.  The data contains lists
> of people, but the number of fields, the order and the type of fields
> can vary from one CSV to another.
>
> Because the data in each column is unknown, a form is displayed with a
> preview of the data in a table.  The table column headers contain
> dropdown list of possible field types for each column in the csv file.
> I'm using a RepeatingView to generate the headers.
>
> The problem is, I'm unclear how to design the CompoundPropertyModel
> for the form.  I assume my model needs to contain a collection of some
> sort since I have a varying number of field.  But how do I map the set
> of RepeatingView->WebMarkupContainer->DropDownChoice objects to the
> model as a collection?
>
> Here's the code:
>
> preview = importer.previewImport(new FileInputStream(dataFile),10,2);
>   ...
> RepeatingView headers = new RepeatingView("header");
> form.add(headers);
> int numFields = preview.getRecords()[0].getFields().length;
> for (int j = 0; j < numFields; j++) {
>   WebMarkupContainer cell = new WebMarkupContainer(headers.newChildId());
>   headers.add(cell);
>   cell.add(new EdiCriteriaDropDownChoice("criteria").setRequired(true));
> }
>
> And the markup:
>
>         <table cellspacing="1">
>           <tr>
>                 <th wicket:id="header">
>                         <select name="select"
> wicket:id="criteria"></select>
>                 </th>
>           </tr>
>            ...
>         </table>
>
> What kind of model would work with this?
>
> Thanks,
> Tauren
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> IMPORTANT NOTICE:
>
> This mailing list is shutting down. Please subscribe to the Apache Wicket
> user list. Send a message to: "users-subscribe at wicket.apache.org" and
> follow the instructions.
> _______________________________________________
> Wicket-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
IMPORTANT NOTICE:

This mailing list is shutting down. Please subscribe to the Apache Wicket user list. Send a message to: "users-subscribe at wicket.apache.org" and follow the instructions.
_______________________________________________
Wicket-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/wicket-user