• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Direct Actions and Sessions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Direct Actions and Sessions


  • Subject: Re: Direct Actions and Sessions
  • From: Colin Clark <email@hidden>
  • Date: Thu, 27 Nov 2003 10:59:39 -0500

Hi Greg,

On Thursday, November 27, 2003, at 06:43 AM, Greg Hulands wrote:
The way I will update the WO app would be something like /MyApp.woa/wa/setTitleForImage?image=uniqueImageNumber&title=newtitle.

Questions:

1. How do I get the session with a direct action as I need to get the default editing context to update the database.

If you do need to access the session from within a direct action, it's quite easy. Just call the session() method. If a session doesn't already exist, this will create a new one.


However, you don't necessarily need to use the default editing context just to do an update to the database. If you'd like to ensure that your direct actions do remain stateless, just create a new editing context in the direct action, fetch the EO that you want to update, make the save, and change. Peer editing contexts are really handy for this sort of thing.

2. How do I parse passed in parameters to the direct action, eg image and title in the above example.

The parameters are stored as form values in the request. Simply call context().request().formValueForKey(String formKey);


Here's a basic example, off the top of my head:

public WOActionResults updateImageTitleAction() {
Integer imageNum = Integer.parseInt(context().request().stringFormValueForKey("uniqueImageN umber"));
String newTitleForImage = context().request().formValueForKey("title");
EOEditingContext ec = new EOEditingContext();
Image = (Image) EOUtilities.objectMatchingKeyAndValue(ec, "Image", "imageNumber", imageNum);
image.setTitle = newTitleForImage;


	ec.saveChanges();
}

Any pointers to documentation on how to use direct actions properly would be appreciated.

The JavaDocs are your friends.

For WODirectAction:
http://developer.apple.com/documentation/WebObjects/Reference/API5.2/ com/webobjects/appserver/WODirectAction.html


EOEditingContext Concepts:
http://developer.apple.com/documentation/WebObjects/Reference/API5.2/ com/webobjects/eocontrol/concepts/EOEditingContextConcepts.html


Hope that helps,

Colin
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Direct Actions and Sessions
      • From: Greg Hulands <email@hidden>
References: 
 >Direct Actions and Sessions (From: Greg Hulands <email@hidden>)

  • Prev by Date: RE: Integer vs. Number vs int
  • Next by Date: Re(4): Resources for porting WO applications from 5.1 to 5.2 and Xcode?
  • Previous by thread: Re: Direct Actions and Sessions
  • Next by thread: Re: Direct Actions and Sessions
  • Index(es):
    • Date
    • Thread