Hi everyone,
I'm pretty much a newbie on Tapestry and need some help.
I'm building a simple web application for administering some data in a
database. I use Hibernate for database connection. I'll need several pages
that will handle insert of new record to table or editing an existing
record. I wan't to use the same page for insert and edit.
My question is basically: How should I build my pages and how should I
handle state between postbacks?
Let me take an example - I have a model object called Event, a page
ListEvents and a page EditEvent.
This is the essentials of my EditEvent.java:
public abstract Event getEvent();
public abstract void setEvent(Event event);
public void pageBeginRender(PageEvent event)
{
if(getEvent() == null)
// new Event
setEvent(new Event());
}
Could/should the thing in pageBeginRender be done by injection instead?
And this is the link between the Event list and the EditEvent page in
ListEvents.java:
@InjectPage("EditEvent")
public abstract EditEvent getEditEvent();
public IPage editEvent(int eventId) {
EditEvent editEvent = getEditEvent();
editEvent.setEvent(EventServices.getEvent(eventId));
return editEvent;
}
where EventServices.getEvent fetches Event from DB.
How should I handle state between postbacks? I have put my eventId in a
Hidden in the EditEvent.html like this:
<input jwcid="@Hidden" value="ognl:event.eventId" />
but this means I will have to redo EventServices.getEvent(eventId) after
postback. This could maybe be OK but where do I put the code? Or should I
store the Event instance in my visit state?
This must be one of the most common scenarios so I guess you all know how it
should be done - please tell me :)
Malin