this part of the concept i understand...what i don't get is a little deeper...from your example i am accessing a property in input. however, I don't have such a property in my object. I some how have to figure out if that mode is selected. basically, i want to implement imodel as show in a example on the forum to put my object in a collection if it is selected. In the example ivan implements imodel. and set that model as the model that the checkbox works with.
http://www.nabble.com/Design-questions%3A-Use-of-controllers-and-wicket-models-tf3373279.html#a9510784 i don't understand how the implentaion works. can you help me with understanding how that works please. -B Eelco Hillenius wrote: > > Wicket models are a way to locate values. > > Let's take a look at wicket.examples.compref.CheckBoxPage. That page > has a nested static class called Input, with a property bool: > > private static class Input implements Serializable > { > public Boolean bool = Boolean.TRUE; > } > > Then, in CheckBoxPage's constructor we do (simplified): > > final Input input = new Input(); > setModel(new CompoundPropertyModel(input)); > Form form = new Form("form"); > form.add(new CheckBox("bool")); > > CompoundPropertyModel might be a bit distracting, so let's rewrite > this to use a normal model: > > final Input input = new Input(); > Form form = new Form("form"); > form.add(new CheckBox("bool", PropertyModel(input, "bool"))); > > another way to rewrite the model: > > form.add(new CheckBox("bool", new Model(input) > { > public Object getObject() > { > return ((Input)super.getObject()).bool; > } > > public void setObject(Object object) > { > ((Input)super.getObject()).bool = (Boolean)object; > } > })); > > and yet another to rewrite the model is: > > form.add(new CheckBox("bool", new IModel() > { > public Object getObject() > { > return input.bool; > } > > public void setObject(Object object) > { > input.bool = (Boolean)object; > } > > public void detach() > { > } > })); > > and *yet* another way is: > > form.add(new CheckBox("bool", new AbstractCheckBoxModel() > { > @Override > public boolean isSelected() > { > return input.bool; > } > > @Override > public void select() > { > input.bool = true; > } > > @Override > public void unselect() > { > input.bool = false; > } > })); > > If you compare these examples, the constant factor is that we're after > the bool property of the Input instance. It is important that you > understand that the typical thing for Wicket models to do is to pass > and get values from other objects, typically your domain objects or > 'form beans' (that's the name which other frameworks often use). Here, > the Input instance is that object, and any of the above combinations > just provides the facility for components to work on that object in a > generic fashion. > > So... the CheckBox component calls getObject on it's model to > determine whether it should render itself as checked or not. It calls > setObject on the model when it receives input. The typical case for > that is when it is part of a form. The form calls updateModel on all > nested components, and the components then call setObject with the > received (and converted) input. > > Now, to get back to your original question. We could rewrite the above > example to work on a list of checkboxes/ input objects like this: > > List<Input> inputs = new ArrayList<Input>(Arrays.asList(new Input[] { > new Input(), > new Input(), new Input() })); > ListView l = new ListView("list", inputs) > { > @Override > protected void populateItem(ListItem item) > { > // item.getModel().getObject() would give the Input > instance for > // this particular list element > item.add(new CheckBox("bool", new > PropertyModel(item.getModel(), > "bool"))); > } > }; > form.add(l); > System.err.println("selection for the second input: " + > inputs.get(1).bool); > > As you can see, the idea stays the same; in both cases we're after the > bool property of instances of Input. > > I'd say, let this sink in a bit, and try to play with this code > yourself, so that you understand better how it works. > > Hope this helps, > > Eelco > > On 3/27/07, GS-ikiini <[EMAIL PROTECTED]> wrote: >> >> ok so i'm trying to implement my own model but i have little idea what i >> am >> suppose to be trying to do here. can someone please give a brief overview >> as >> to what the getObject, and setObject expects and does please. I am really >> lost and need some help with this. also how does the model intereact with >> the componenet..what do they tell each other.? >> >> -B >> >> >> >> igor.vaynberg wrote: >> > >> > On 3/26/07, GS-ikiini <[EMAIL PROTECTED]> wrote: >> >> >> >> >> >> its saying that you create a custom model that takes as an argument in >> >> the >> >> constructor the object/model that you want to tie to a check box. this >> >> model >> >> is used as the model that we pass to our check box component. the >> >> setObject >> >> method gets called at the push of the submit button and sets that >> >> object/model as part of the collection if it is selected. is this >> >> correct? >> > >> > >> > sounds about right. >> > >> > -igor >> > >> > >> > >> > -B >> >> >> >> >> >> >> >> igor.vaynberg wrote: >> >> > >> >> > if you dont grasp the concepts perhaps you should read the wiki page >> on >> >> > models >> >> > >> >> > the concept is: >> >> > >> >> > since the checkbox works by setting/clearing a boolean the model >> >> > translates >> >> > a set boolean->insert into collection and clear boolean->remove from >> >> > collection. >> >> > >> >> > there is explanation there, try to read that too, not just look at >> the >> >> > code. >> >> > >> >> > -igor >> >> > >> >> > >> >> > On 3/26/07, GS-ikiini <[EMAIL PROTECTED]> wrote: >> >> >> >> >> >> >> >> >> I don't quite grasp the concepts used in that tread. from what i >> >> >> understand i >> >> >> should create a separate model that takes the model that has to get >> >> >> set(the >> >> >> model that is selected via checkbox) in the object i'm making, and >> >> places >> >> >> it >> >> >> in a collection if it is selected. Is this correct? >> >> >> >> >> >> -B >> >> >> >> >> >> >> >> >> >> >> >> igor.vaynberg wrote: >> >> >> > >> >> >> > please search mail archives before posting >> >> >> > >> >> >> > >> >> >> >> >> >> http://www.nabble.com/Design-questions%3A-Use-of-controllers-and-wicket-models-tf3373279.html#a9510784 >> >> >> > >> >> >> > -igor >> >> >> > >> >> >> > >> >> >> > On 3/26/07, GS-ikiini <[EMAIL PROTECTED]> wrote: >> >> >> >> >> >> >> >> >> >> >> >> Hey all, >> >> >> >> >> >> >> >> I have a list view that contains a list of objects. these >> objects >> >> are >> >> >> >> selectable via checkboxes. My problem is that i don't know how >> to >> >> know >> >> >> or >> >> >> >> tell my code what objects have been selected. here is what i >> want >> >> to >> >> >> do. >> >> >> >> >> >> >> >> i ahve a list of objects lets call them pens. So i have a list >> of 5 >> >> >> >> different types of pen objects. this object type is a property ( >> a >> >> >> list >> >> >> >> of >> >> >> >> this object to be specific) in another object say a pencilCase. >> i >> >> >> want >> >> >> a >> >> >> >> user to select 0-many different pens which will then be placed >> in >> >> the >> >> >> >> pencil >> >> >> >> case by the applicaition. what i am not sure how to do is >> associate >> >> >> each >> >> >> >> pen >> >> >> >> in the list with what is selected. I seen on the wiki that i can >> >> add >> >> a >> >> >> >> boolean property to the pens called selected. and make that what >> >> the >> >> >> >> checkbox renders on. but i don't have access to the pens to do >> >> that. >> >> >> is >> >> >> >> another some way i can do an association externally? I thought >> of >> >> >> >> creating >> >> >> >> a >> >> >> >> separate list of booleans variables that i can compare side by >> side >> >> >> with >> >> >> >> the >> >> >> >> list of pens. selection of check boxes will set the booleans in >> >> that >> >> >> >> list. >> >> >> >> then look at what is true and go get the pen in the pens list at >> >> that >> >> >> >> position and do what i got to do with it. however I think this >> >> method >> >> >> 1- >> >> >> >> may >> >> >> >> not work and 2 - is to elementary and not very professional. I >> am >> >> sure >> >> >> >> there >> >> >> >> is another way to do this. Please advise. >> >> >> >> >> >> >> >> >> >> >> >> -B >> >> >> >> -- >> >> >> >> View this message in context: >> >> >> >> >> >> >> >> >> >> http://www.nabble.com/check-box-questions-how-to-I-associate-an-object-with-a-boolean-seletion-from-a-checkbox-component-tf3469311.html#a9680769 >> >> >> >> 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 >> >> >> >> [email protected] >> >> >> >> 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 >> >> >> > [email protected] >> >> >> > https://lists.sourceforge.net/lists/listinfo/wicket-user >> >> >> > >> >> >> > >> >> >> >> >> >> -- >> >> >> View this message in context: >> >> >> >> >> >> http://www.nabble.com/check-box-questions-how-to-I-associate-an-object-with-a-boolean-seletion-from-a-checkbox-component-tf3469311.html#a9682170 >> >> >> 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 >> >> >> [email protected] >> >> >> 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 >> >> > [email protected] >> >> > https://lists.sourceforge.net/lists/listinfo/wicket-user >> >> > >> >> > >> >> >> >> -- >> >> View this message in context: >> >> >> http://www.nabble.com/check-box-questions-how-to-I-associate-an-object-with-a-boolean-seletion-from-a-checkbox-component-tf3469311.html#a9682786 >> >> 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 >> >> [email protected] >> >> 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 >> > [email protected] >> > https://lists.sourceforge.net/lists/listinfo/wicket-user >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/check-box-questions-how-to-I-associate-an-object-with-a-boolean-seletion-from-a-checkbox-component-tf3469311.html#a9696881 >> 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 >> [email protected] >> 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 > [email protected] > https://lists.sourceforge.net/lists/listinfo/wicket-user > > -- View this message in context: http://www.nabble.com/check-box-questions-how-to-I-associate-an-object-with-a-boolean-seletion-from-a-checkbox-component-tf3469311.html#a9700217 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 [email protected] https://lists.sourceforge.net/lists/listinfo/wicket-user
