Thanks Chuck for your help.  One more tool in the toolbelt :)

The MIME type reported is application/octet-stream.  The field should
be empty, since I haven't selected a file right?

Best regards,
Sigurdur

2007/6/28, Chuck Hill <[EMAIL PROTECTED]>:
Add the lines below to see what is in mimeType.  That should help
track down the problem.


On Jun 28, 2007, at 5:00 AM, Sigurður E. Vilhelmsson wrote:

> Hi all,
>
> First, I'd like to thank everyone that chimed in on my WOPopUpButton
> problem last week.  I believe I've got that covered, so on to the next
> one.
>
> I'm building on Janine Sisk's tutorial and have a problem with
> updating an entity through my form.  What happens is that if I edit an
> entity already in the database, and leave the field BigFlag empty
> (i.e. update only currency or name), I get an error:
>
> The mimeType property of Country exceeds maximum length of 20
> characters
>
> So I figure something else than MimeType is getting passed to the
> mimeType field in my database.  Any pointers on how to figure this out
> (i.e. how to see what gets passed) or something obviously wrong in my
> code below?
>
> Best regards,
> Sigurdur
>
>
> The java for my edit page (minus comments) is:
>
> package com.ninukot.pages;
>
> import com.ninukot.pages.DisplayOneCountry;
> import com.ninukot.eo.Country;
> import com.ninukot.eo.Currency;
> import com.webobjects.appserver.*;
> import com.webobjects.eoaccess.EOGeneralAdaptorException;
> import com.webobjects.eoaccess.EOUtilities;
> import com.webobjects.eocontrol.EOEditingContext;
> import com.webobjects.foundation.NSArray;
> import com.webobjects.foundation.NSData;
> import com.webobjects.foundation.NSTimestamp;
>
> public class AddEditCountry extends WOComponent {
>
>       private Country country;
>
>       public Currency currencyItem;
>
>       public String imageFileName;
>
>       private String errorMsg;
>
>       public AddEditCountry(WOContext context) {
>               super(context);
>       }
>
>       public NSArray allCurrency () {
>               EOEditingContext ec = session().defaultEditingContext();
>               return EOUtilities.objectsForEntityNamed(ec, "Currency");
>       }
>
>       public Currency selectedCurrency() {
>               return country.currency();
>       }
>
>       public void setSelectedCurrency(Currency aCurrency) {
>               country.addObjectToBothSidesOfRelationshipWithKey(aCurrency,
> "currency");
>       }
>
>       public Country country() {
>               if (country == null) {
>
> EOUtilities.createAndInsertInstance(session().defaultEditingContext(),
> "Country");
>               }
>               return country;
>       }
>
>       public WOComponent saveChanges() {
>               if (hasError()) {
>                       return context().page();
>               }
>
>               country().setLastModifiedDate(new NSTimestamp());
>
>               try {
>                       session().defaultEditingContext().saveChanges();
>               } catch (ValidationException e) {
NSLog.out.appendln("MIME type in save changes: " + country().mimeType
());

>                       setErrorMsg(e.getMessage());
>               } catch (EOGeneralAdaptorException e) {
>                       setErrorMsg(e.getMessage());
>               }
>
>               if (hasError()) {
>                       return context().page();
>               } else {
>                       return goToDisplayOneCountry();
>               }
>       }
>
>       public void validationFailedWithException(Throwable t, Object value,
>                       String keyPath) {
NSLog.out.appendln("MIME type from takeValues: " + value);
>               setErrorMsg(t.getMessage());
>       }
>
>       public void setErrorMsg(String newMsg) {
>               errorMsg = newMsg;
>       }
>
>       public String errorMsg() {
>               return errorMsg;
>       }
>
>       public void setCountry (Country newCountry) {
>               country = newCountry;
>       }
>
>       public NSData imageData() {
>               return country.bigFlag();
>       }
>
>       public void setImageData(NSData imageData) {
>               if (imageData.length() > 0) {
>                       country().validateTakeValueForKeyPath(imageData, 
"bigFlag");
>               }
>       }
>
>       public boolean hasError() {
>               return errorMsg() != null;
>       }
>
>    public boolean hasThumbnailFlag() {
>        return country().thumbnailFlag() != null;
>    }
>
>       public void sleep() {
>               setErrorMsg(null);
>               super.sleep();
>       }
>
>       public DisplayOneCountry goToDisplayOneCountry() {
>               DisplayOneCountry nextPage = (DisplayOneCountry)
> pageWithName("DisplayOneCountry");
>               nextPage.setCountry(country);
>               return nextPage;
>       }
>
> }
>
> The html:
>
> <p>
> <webobject name="ShowThumbnail">
> Current image:<br />
> <webobject name="Thumbnail"></webobject>
> </webobject>
> </p>
>
> <webobject name="Form">
> <table>
> <tr><td>Nafn: <webobject name="Name"></webobject></td></tr>
> <tr><td>Höfuðborg: <webobject name="Capital"></webobject></td></tr>
> <tr><td>Fáni: <webobject name = "BigFlag"></webobject></td></tr>
> <tr><td>Mynt: <webobject name = "Currency"></webobject></td></tr>
> <tr><td><webobject name="SubmitButton"></webobject></td></tr>
> </table>
> </webobject>
> <webobject name="ShowErrors">
> <font color="red"><webobject name="Error"></webobject></font>
> </webobject>
> <p><webobject name="LinkToDisplayAllCountry">Back to the Index</
> webobject></p>
>
> and WOD:
> ShowErrors : WOConditional {
>       condition = hasError;
> }
>
> Error : WOString {
>       value = errorMsg;
> }
>
> Form : WOForm {
>       enctype = "multipart/form-data";
> }
>
> Name : WOTextField {
>       value = country.name;
> }
>
> Capital : WOText {
>       value = country.capital;
> }
>
> BigFlag : WOFileUpload {
>       mimeType = country.mimeType;
>       data = imageData;
>       filePath = imageFileName;
> }
>
> Currency : WOPopUpButton {
>       list = allCurrency;
>       item = currencyItem;
>       displayString = currencyItem.currency;
>       selection = selectedCurrency;
> }
>
> SubmitButton : WOSubmitButton {
>       action = saveChanges;
>       value = "Save Changes";
> }
>
> ShowThumbnail: WOConditional {
>       condition = hasThumbnailFlag;
> }
>
> Thumbnail : WOImage {
>       data = country.thumbnailFlag;
>       mimeType = country.mimeType;
> }
>
> LinkToDisplayAllCountry : WOHyperlink {
>       pageName = "DisplayAllCountry";
> }
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/chill%
> 40global-village.net
>
> This email sent to [EMAIL PROTECTED]
>

--

Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to