|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
How to get the data altered by the user in html page in a list viewHello,
I am rendering a list view having multiple rows using wicket. In form submit(), I could retrive the data in below mentioned code but i am not sure whether it is right way of getting the changed data from the list view . Below is my code snippet attached. Please review the code and let me know the best practice. // LiConfig is application pojo private Form form; private ListView li_config_settings_row; private List<LiConfig> li_config_settings;// applicaton pojo list li_config_settings_row = new ListView("settingRow", li_config_settings) { protected void populateItem(ListItem item) { final LiConfig p = (LiConfig) item.getModelObject(); item.setModel(new CompoundPropertyModel(p)); //Some code to add components like Hidden fields, Text fields, Labels etc. } }; form.add(li_config_settings_row); form = new Form("sectionPanelForm"){ protected void onSubmit() { ArrayList<LiConfig> liConfigs = new ArrayList<LiConfig>(); Iterator<ListItem> iterator = li_config_settings_row.iterator(); while (iterator.hasNext()) { ListItem listItem = iterator.next(); LiConfig l = new LiConfig(); Iterator<Component> childIterator = listItem..iterator(); boolean changed = false; while (childIterator.hasNext()) { Component c = childIterator.next(); if (c.getId().equalsIgnoreCase("isChanged")) { if ((((HiddenField) c).getConvertedInput() .toString()).equalsIgnoreCase("1")) { changed = true; } } if (c.getId().equalsIgnoreCase("id")) { l.setId(new Integer(((HiddenField) c) .getConvertedInput().toString())); } if (c.getId().equalsIgnoreCase("fieldValue")) { l .setFieldValue(((TextField) c) .getConvertedInput() != null ? ((TextField) c) .getConvertedInput().toString() : ""); } } if (changed) { liConfigs.add(l); } } if (liConfigs.size() != 0) { ArrayList<LiConfig> updatedList = new ArrayList(); String changedValue; for (LiConfig li : liConfigs) { changedValue = li.getFieldValue(); li = ConfigWizardhelper.getLiConfig(li.getId()); li.setFieldValue(changedValue); updatedList.add(li); } ConfigWizardhelper.insertORUpdateLiConfigs(updatedList); } HashMap<String, String> param = new HashMap<String, String>(); param.put("id", id); ConfigWizardPage.index = getIndex(); setResponsePage(ConfigWizardPage.class); } }; |
|
|
Re: How to get the data altered by the user in html page in a list viewa) you should be using models to bind data instead of directly
iterating over listview's listitems b) when using listview in a form you should call setreuseitems(true) on it. -igor On Mon, Jul 7, 2008 at 3:17 AM, Deepak_G <Deepak.Headstrong@...> wrote: > > Hello, > > I am rendering a list view having multiple rows using wicket. In form > submit(), I could retrive the data in below mentioned code but i am not sure > whether it is right way of getting the changed data from the list view . > Below is my code snippet attached. Please review the code and let me know > the best practice. > > // LiConfig is application pojo > private Form form; > private ListView li_config_settings_row; > private List<LiConfig> li_config_settings;// applicaton pojo list > li_config_settings_row = new ListView("settingRow", li_config_settings) { > protected void populateItem(ListItem item) { > final LiConfig p = (LiConfig) item.getModelObject(); > item.setModel(new CompoundPropertyModel(p)); > //Some code to add > components like Hidden fields, Text fields, Labels etc. > } > }; > form.add(li_config_settings_row); > > form = new Form("sectionPanelForm"){ > protected void onSubmit() { > ArrayList<LiConfig> liConfigs = new ArrayList<LiConfig>(); > Iterator<ListItem> iterator = li_config_settings_row.iterator(); > while (iterator.hasNext()) { > ListItem listItem = iterator.next(); > LiConfig l = new LiConfig(); > Iterator<Component> childIterator = listItem..iterator(); > boolean changed = false; > while (childIterator.hasNext()) { > Component c = childIterator.next(); > if (c.getId().equalsIgnoreCase("isChanged")) { > if ((((HiddenField) c).getConvertedInput() > .toString()).equalsIgnoreCase("1")) { > changed = true; > } > > } > if (c.getId().equalsIgnoreCase("id")) { > l.setId(new Integer(((HiddenField) c) > .getConvertedInput().toString())); > } > if (c.getId().equalsIgnoreCase("fieldValue")) { > l > .setFieldValue(((TextField) c) > .getConvertedInput() != null ? ((TextField) c) > .getConvertedInput().toString() > : ""); > } > > } > if (changed) { > liConfigs.add(l); > } > } > > if (liConfigs.size() != 0) { > ArrayList<LiConfig> updatedList = new ArrayList(); > String changedValue; > for (LiConfig li : liConfigs) { > changedValue = li.getFieldValue(); > li = ConfigWizardhelper.getLiConfig(li.getId()); > li.setFieldValue(changedValue); > updatedList.add(li); > > } > ConfigWizardhelper.insertORUpdateLiConfigs(updatedList); > } > HashMap<String, String> param = new HashMap<String, String>(); > param.put("id", id); > > ConfigWizardPage.index = getIndex(); > setResponsePage(ConfigWizardPage.class); > } > }; > -- > View this message in context: http://www.nabble.com/How-to-get-the-data-altered-by-the-user-in-html-page--in-a-list-view-tp18313650p18313650.html > Sent from the Wicket - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free Forum Powered by Nabble | Forum Help |