• 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: FileUpload
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FileUpload


  • Subject: Re: FileUpload
  • From: Chuck Hill <email@hidden>
  • Date: Tue, 28 Jan 2003 21:21:54 -0800

Jonathan,

First let me recommend that you pick up a copy of "The Pragmatic
Programmer" by Andrew Hunt and David Thomas (ISBN 020161622).  You will
find it a wealth of distilled knowledge and experience of many years
programming.

Second, Hungarian Notation is an evil thing to inflict on code and needless
in a strongly typed language.  If Java is anything, it is strong typed.  I
say this as I find it extremely difficult to read your code with the method
and variable names that you use.  Yes, I am a Code Purity Bigot.  :-)

Third, don't assume.  If you don't know, and it is not documented, use a
debugger or NSLog.out.appendln(...) to verify what you think is a fact.

Now, as to what is wrong, NSPathUtilities.lastPathComponent(null) returns a
empty string (""), not null.  So the method

// Thumb File Upload Of File Path
public void setKvcPicThumbRef(String aFilePath) {
    kvcPicThumbRef = NSPathUtilities.lastPathComponent(aFilePath);
}

will always leave kvcPicThumbRef with a non-null value.  Hence,

if (getKvcPicThumbRef() != null)

will always evaluate to true - clearly not what you intend!  Your method
should read something like

public void setKvcPicThumbRef(String aFilePath) {
    kvcPicThumbRef = null;

    if (aFilePath != null)
    {
        kvcPicThumbRef = NSPathUtilities.lastPathComponent(aFilePath);
    }
}



Regards,
Chuck

At 04:43 PM 28/01/2003 +0000, Jonathan Fleming wrote:
>
>
>
>
>I am having a problem with the "if" statement on this piece of code shown
>below, I have set it to upload something if a filepath is available and to
>do nothing or more to the point leave it in the same state if the filepath
>is null, however, when I set the "if" statement to != null on save I still
>find that an empty or null entry has been made to the database, effectivly
>overwriting the data that was already there, which is what I did not want to
>do.
>When I do the reverse for the "if" statement == null, I get nothing saved to
>the database whether or not a filepath has been entered.
>
>I tried to solve the problem but it is eluding me. Can anyone help please.
>
>Regards
>Jonathan
>
>Here's the code:
>
>//instance variables
>	protected String kvcPicLrgRef = null;
>    	protected String kvcPicThumbRef = null;
>
>
>
>// Thumb File Upload Of File Path
>    public void setKvcPicThumbRef(String aFilePath) {
>        kvcPicThumbRef = NSPathUtilities.lastPathComponent(aFilePath);
>    }
>
>    public String getKvcPicThumbRef() {
>        return kvcPicThumbRef;
>    }
>
>
>    // Thumb File Upload of Data
>    public void setKvcPicThumb(NSData aPicture) {
>        kvcPicThumb = aPicture;
>    }
>
>    public NSData getKvcPicThumb() {
>        return kvcPicThumb;
>    }
>
>
>    /*----------------------       Validation       ---------------------*/
>
>
>    public WOComponent dbSaveChanges(){
>        try {
>            tbJobPicture.validateForSave();
>            // get editing context
>            EOEditingContext ec = session().defaultEditingContext();
>            TbJobPicture tbJobPicture = tbJobPicture();
>
>            // this checks if data was entered into the fileUpload component
>            if (getKvcPicThumbRef() != null)
>            {
>                // Something was uploaded, update the EO
>                tbJobPicture.setPicThumbRef(getKvcPicThumbRef());
>                tbJobPicture.setPicThumbnail(getKvcPicThumb());
>            }
>
>            // save changes made in editing context to object store
>            ec.saveChanges();
>
>            // create a new tbJob
>            tbJobPicture = new TbJobPicture();
>        }
>        catch (NSValidation.ValidationException exception) {
>            validationDictionary.setObjectForKey(Boolean.TRUE,
>                                                 "saveValidationFailed");
>            validationDictionary.setObjectForKey(exception.getMessage(),
>                                                 "saveValidationString");
>        }
>
>_________________________________________________________________
>It's fast, it's easy and it's free. Get MSN Messenger today!
>http://messenger.msn.co.uk
>
>

--

Chuck Hill                                 email@hidden
Global Village Consulting Inc.             http://www.global-village.net
_______________________________________________
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.

References: 
 >FileUpload (From: "Jonathan Fleming" <email@hidden>)

  • Prev by Date: EOF cocoa app
  • Next by Date: Re: FileUpload
  • Previous by thread: FileUpload
  • Next by thread: Re: FileUpload
  • Index(es):
    • Date
    • Thread