Re: EOEditingContext conceptual question
Re: EOEditingContext conceptual question
- Subject: Re: EOEditingContext conceptual question
- From: LD <email@hidden>
- Date: Mon, 12 Sep 2005 14:26:17 +1000
Hi there,
On 12/09/2005, at 8:01 AM, Miguel Arroz wrote:
Imagine I have three pages (or components) on my App, main,
ManageOpenTickets and AddTicket. Suppose main is just a menu, with
an hyperlink that links to ManageOpenTickets. ManageOpenTickets
shows a table (based on an WORepetition) with all the tickets, and
contains an hyperlink to AddTicket, which allows me to fill in a
new ticket.
Now, what I do on AddTicket is the following. I create a new ticket
on the class constructor, and the page has fields binded to the
ticket keys (like "Subject", "Description", etc). Here's the code:
protected SMTicket newTicket;
public AddTicket(WOContext context) throws Exception {
super(context);
newTicket = (SMTicket) EOUtilities.createAndInsertInstance
( session().defaultEditingContext(), "Ticket" );
}
So, I create and insert an "empty" ticket on the editing context.
After I fill in the fields on the browser and click on the submit
button, the following action is called (forget validation for now):
public WOComponent add() {
session().defaultEditingContext().saveChanges();
return pageWithName("ManageOpenTickets");
}
So far, so good (I guess, but I'm a newbie, so if this is bad
practice, please tell me!).
You'll be better off creating a WOComponent that 'edits' a ticket.
It'll create and insert a new ticket if one was not supplied. e.g.,
below.
public class EditTicket extends WOComponent {
protected SMTicket ticket;
protected EOEditingContext ec;
public EditTicket( WOContext context ) {
super( context );
aTicket = null;
ec = session().defaultEditingContext();
}
public SMTicket ticket() {
if ( ticket == null ) {
ticket = ( SMTicket )EOUtilities.createAndInsertInstance
( ec, "Ticket" );
}
return ticket;
}
public void setTicket( SMTicket aTicket ) {
this.ticket = aTicket;
}
public WOComponent saveChangesToTicketAction() {
ec.saveChanges();
return pageWithName( "ManageOpenTickets" );
}
}
public class ManageOpenTickets extends WOComponent {
public SMTicket aTicket; // from WORepetition
<...>
public WOComponent createTicket() {
return pageWithName( "EditTicket" );
}
public WOComponent editTicket() {
WOComponent nextPage;
nextPage = createTicket();
nextPage.takeValueForKey( aTicket, "ticket" );
return nextPage;
}
<...>
}
with regards,
--
LD
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden