FilePath On Upload Using Key Value Coding
FilePath On Upload Using Key Value Coding
- Subject: FilePath On Upload Using Key Value Coding
- From: "Jonathan Fleming" <email@hidden>
- Date: Tue, 31 Dec 2002 15:24:02 +0000
Hello all,
I'm having trouble understanding how to use the code below to get the last
component of a filepath into the database through a custom EnterpriseObject
created with the EOModel.
Here are the attributes/properties of the EOModel that we are concerned with
in a custom java file called TbJobPicture:
public NSData picThumbnail() {
return (NSData)storedValueForKey("picThumbnail");
}
public void setPicThumbnail(NSData value) {
takeStoredValueForKey(value, "picThumbnail");
}
public String picThumbRef() {
return (String)storedValueForKey("picThumbRef");
}
public void setPicThumbRef(String value) {
takeStoredValueForKey(value, "picThumbRef");
Normally in the fileUpload component I would bind the data to
tbJobPictureItem.picThumbnail & the filePath to tbJobPictureItem.picThumbRef
where tbJobPicture is the instance variable (TbJobPicture tbJobPicture;).
However, I want to put only the last part of the file path into the database
whereas the way I am doing it at the moment I get the full path such as:
C:\Documents and Settings\All Users.WINXP\Documents\My Pictures\Sample
Pictures\Sunset.jpg
To get only Sunset.jpg I have to use the lastPathComponent() but it can only
be used on a String not a custom enterprise object like TbJobPicture, thus
the reason for going down the key value coding route.
Basically How do I get the example I have been given below to convert or
save to the appropriate database field/property? My mind is shot to pieces
and I can not see the answer, simple though it may be to many of you, I've
been stuck on this for weeks.
I'd appreciate your help one and all
Regards
Jonathan
This is what was suggested to me, but I have failed to understand how to use
it.
Take advantage of key-value coding!
Bind the filePath attribute of your WOFileUpload element to something like
"myFilePath". In the component that contains the WOFileUpload element,
create two methods and an instance variable:
protected String myFilePath;
public void setMyFilePath(String aFilePath) {
myFilePath = NSPathUtilities.lastPathComponent(aFilePath);
}
public String getMyFilePath() {
return myFilePath;
}
Or if you want to hold onto the full path for other reasons you could do the
following instead:
public void setMyFilePath(String aFilePath) {
myFilePath = aFilePath;
}
public String getMyFilePath() {
return NSPathUtilities.lastPathComponent(myFilePath);
}
In either case, invoke getMyFilePath when you do whatever you need to do to
get the file name into the database field to which you allude.
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 3 months FREE*.
http://join.msn.com/?page=features/featuredemail&xAPID=42&PS=47575&PI=7324&DI=7474&SU=
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_addphotos_3mf
_______________________________________________
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.