Heres the pastebin: Palette: http://pastebin.ca/327900
Recorder: http://pastebin.ca/327901 -regards Nino -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Giltal Sent: 25. januar 2007 11:18 To: wicket-user@lists.sourceforge.net Subject: Re: [Wicket-user] Palette add selected option Hi Can you please post your Palette and Recorder classes ... Thanks Nino Wael wrote: > > I think I have something somewhere... > > As I remember you need to update the recorder component... > > Below is only meant as a sniplet(notice the recreate model, which now are > called from the palette onchange function).. > > > > package com.sas.jobindsats.ui.palette.component; > > import java.util.ArrayList; > import java.util.Collection; > import java.util.Collections; > import java.util.Iterator; > import java.util.List; > > import wicket.Component; > import wicket.markup.html.form.HiddenField; > import wicket.markup.html.form.IChoiceRenderer; > import wicket.model.AbstractModel; > import wicket.util.string.Strings; > > import com.sas.jobindsats.ui.palette.Palette; > > /** > * Component to keep track of selections on the html side. Also used for > * encoding and decoding those selections between html and java. > * > * @author Igor Vaynberg ( ivaynberg ) > */ > public class Recorder extends HiddenField { > private static final long serialVersionUID = 1L; > > private static final String[] EMPTY_IDS = new String[0]; > > private final String seperator = "#"; > > /** conviniently maintained array of selected ids */ > private String[] ids; > > /** parent palette object */ > private Palette palette; > > /** > * @return parent Palette object > */ > public Palette getPalette() { > return palette; > } > > /** > * @param id > * component id > * @param palette > * parent palette object > */ > public Recorder(String id, Palette palette) { > super(id); > this.palette = palette; > > // BELOW ENSURES THAT IDS ARE NOT NULL > reCreateModel(); > AbstractModel model = new AbstractModel() { > > public Object getObject(Component component) { > StringBuffer modelStringBuffer = new > StringBuffer(); > > for (int i = 0; ids.length > i; i++) { > modelStringBuffer.append(ids[i]); > if (i + 1 < ids.length) { > > modelStringBuffer.append(seperator); > } > } > > // set model and update ids array > > String modelString = > modelStringBuffer.toString(); > > return modelString; > > } > > public void setObject(Component component, Object > object) { > updateIds((String) object); > }; > }; > setModel(model); > } > > protected void onValid() { > super.onValid(); > updateIds(); > } > > /** > * @return iterator over selected choices > */ > public Iterator getSelectedChoices() { > IChoiceRenderer renderer = getPalette().getChoiceRenderer(); > > if (ids.length == 0) { > return Collections.EMPTY_LIST.iterator(); > } > > List selected = new ArrayList(ids.length); > for (int i = 0; i < ids.length; i++) { > Iterator it = getPalette().getChoices().iterator(); > while (it.hasNext()) { > final Object choice = it.next(); > if (renderer.getIdValue(choice, > 0).equals(ids[i])) { > selected.add(choice); > break; > } > } > } > return selected.iterator(); > } > > /** > * @return iterator over unselected choices > */ > public Iterator getUnselectedChoices() { > IChoiceRenderer renderer = getPalette().getChoiceRenderer(); > Collection choices = getPalette().getChoices(); > > if (choices.size() - ids.length == 0) { > return Collections.EMPTY_LIST.iterator(); > } > > List unselected = new ArrayList(Math > .max(1, choices.size() - ids.length)); > Iterator it = choices.iterator(); > while (it.hasNext()) { > final Object choice = it.next(); > final String choiceId = renderer.getIdValue(choice, 0); > boolean selected = false; > for (int i = 0; i < ids.length; i++) { > if (ids[i].equals(choiceId)) { > selected = true; > break; > } > } > if (!selected) { > unselected.add(choice); > } > } > return unselected.iterator(); > } > > protected void onInvalid() { > super.onInvalid(); > updateIds(); > } > > private void updateIds() { > updateIds(getValue()); > } > > public void updateIds(String value) { > if (Strings.isEmpty(value)) { > ids = EMPTY_IDS; > } else { > ids = value.split(seperator); > } > } > > public void reCreateModel() { > > // construct the model string based on selection collection > IChoiceRenderer renderer = getPalette().getChoiceRenderer(); > StringBuffer modelStringBuffer = new StringBuffer(); > > Iterator selection = ((Collection) > getPalette().getModelObject()) > .iterator(); > > while (selection.hasNext()) { > > modelStringBuffer.append(renderer.getIdValue(selection.next(), 0)); > if (selection.hasNext()) { > modelStringBuffer.append(seperator); > } > } > > // Get values from modelstringbuffer > > String modelString = modelStringBuffer.toString(); > > // Only add if not already added > String[] local = getValue().split(seperator); > > for (int i = 0; local.length > i; i++) { > if (modelString.indexOf(local[i]) == -1) { > modelString += seperator + local[i]; > } > } > updateIds(modelString); > > } > > } > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Vincent > Renaville > Sent: 30. november 2006 11:40 > To: Wicket List > Subject: [Wicket-user] Palette add selected option > > Dear, > > I use the paleete component, to assigne option to a User. but I don't > find a functionnality, how to set already selected option ?. > > Exemple : a user selected option, I store it into a database: > In the futur, the user want to update his option, at the moment he > doesn't see his previous selected option. > > Do you have a solution. > > Kind regards, > > Vincent > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > -- View this message in context: http://www.nabble.com/Palette-add-selected-option-tf2730861.html#a8599378 Sent from the Wicket - User mailing list archive at Nabble.com. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user