here are my short answers :) ask more if you need something explained in
detail
On 3/8/07, David Leangen <[EMAIL PROTECTED]> wrote:
First Question: Controller Logic
--------------------------------
The idea sounds good, but I'm wondering if this is even necessary. It
was suggested to me that cleanly separating stuff into a controller is
not worth the effort, since we'd be "duplicating" so much code for no
good reason.
you have to decide what is clearly "business logic" vs "ui logic". the
business logic should go into a separate service/controller/whatchamaggicit.
the ui logic is best embedded in wicket components because each component is
a full implementation of MVC already.
Also, say if we wanted to make the component compatible with
"bookmarkability", would it be a good idea to have a setter or
constructor in the controller that accepts something similar to
PageParameters, so wicket can just pass through that object to the
controller?
it would be a good idea if you can initialize some state off the
pageparameters, be that business state or ui state or both. that way you can
retain bookmarkability.
Second Question: Mapping Above Model to Wicket Models
-----------------------------------------------------
1. How do we connect the wicket model with our controller
above when validating the state and delegating to the
state-holder bean?
i think a lot of users underestimate the power of IModel when you implement
it directly. you dont have to use the default Model or PropertyModel, you
are just boxing yourself in. implement the interface yourself for most
flexibility - that way you can achieve any kind of mapping.
also do not underestimate the power of decorator/adapter pattern when it
comes to models.
2. How do we "associate" parts of the state-holder bean
with the wicket controls? For example, the "blue"
above needs a checkbox, so how do we associate the
value of blue in our bean above to the "blue" checkbox?
see above. take a simple example where you have a list of checkboxes and you
want all selected objects to end up in a collection. how do you do it?
sounds like a complex mapping? the most elegant way is to write a custom
model.
class mypage extends page {
private Set<Person> selected=new HashSet();
private class PersonCheckboxModel implements IModel<Boolean> {
private final IModel<Person> person;
public final PersonCheckBoxModel(IModel<Person> person) {
this.person=person; }
public Boolean getObject() {
return selected.contains(person.getObject());
}
public void setObject(Boolean b) {
if (Boolean.TRUE.equals(b)) {
selected.put(person.getObject());
} else {
selected.remove(person.getObject());
}
}
public void detach() { person.detach(); }
}
}
now all you have to do is
LoadableDetachableModel person=new LoadalbeDetachableModel(id);
new CheckBox(this, "cb", new PersonCheckBoxModel(person));
and everything magically works, hope it gives you some ideas.
-igor
Hope my ramblings make some sense.
Cheers,
Dave
-------------------------------------------------------------------------
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