hi, i am writing an application, but don't know how best to write it
in wicket. i can see lots of different ways to approach my problem
and would appreciate some direction as to which approach is the most
appropiate. i have read the documentation in the wiki regarding
models and understand the different page constructors but i am
confused about how long the objects are safe to hold on to and which
approach is best.
here is some (pseudo)code for a page i need to write. my situation is
i have one page which shows the details about a "Group" (collection of
users), which has a link on it to create a new "User" and add it to
the Group. (the CreateUser page has text boxes to set name ect and
saves to the database on submit) my ViewGroupDetails page:
// first decision = set the Group as a final variable before creating
the link so it is still there in the onClick?
final Group g = (Group)getModelObject();
new Link("adduser") {
public void onclick() {
// or get Group from the page's model only when link clicked?
Group g = (Group)ViewGroup.this.getModelObject();
// second decision = pass the whole Group into the new page constructor?
setResponsePage(new CreateUser(g));
// or make the new User object here and pass it in?
User u = new User();
u.setGroup(g);
setResponsePage(new CreateUser(u));
// or pass in just the group id number?
setResponsePage(new CreateUser(g.getId()));
}
}
so the constructor of my CreateUser page will either take a Group and
will create the User (as above), or take a Group's id number and load
the Group from the database first, or take a User directly. an id
number could be passed in by PageParameters or directly as an integer.
an object could be passed bare or put inside a Model. i am not sure
i am making any sense! i suppose my questions are...
- how 'safe' is it to pass the Group directly to the new page constructor?
- is it safe to create a final reference to an object and rely on that
object being still there and intact by the time the link is clicked?
- is it safe to getModelObject() to get the page's object at any time
in the future?
- i understand that the following is bad: new Label(group.getId())...
better to use a model and load the id when needed... am i falling into
the same trap with the final variables in the code above?
john
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]