Re: Problem with a form
Re: Problem with a form
- Subject: Re: Problem with a form
- From: "Sigurður E. Vilhelmsson" <email@hidden>
- Date: Thu, 28 Jun 2007 20:14:37 +0000
I'm going to systematically dismantle my form so I can figure out
what's going on. I'll report my findings.
Best regards,
Siggi
2007/6/28, Janine Sisk <email@hidden>:
I'm right here. :) But I'm pretty sure (can never say 100%) that the
code in the tutorial lets you edit an existing record and not upload
a new image without any errors. I know I tried it, and no-one else
has reported it not working (so far). Of course it's always possible
you've found an approach I didn't try, so if you get the same error
from the tutorial code, definitely let me know.
janine
On Jun 28, 2007, at 10:07 AM, Chuck Hill wrote:
>
> On Jun 28, 2007, at 9:11 AM, Sigurður E. Vilhelmsson wrote:
>
>> 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?
>
> It might not be you. :-) WOFileUpload works in odd ways and
> Janine was trying to work around them. She may have missed this one.
>
> A WOTextField will output its current content when the page is
> generated and update the content when the form is submitted.
> WOFileUpload works the same way, except that there is never any
> current content. When the form is submitted, if you have not
> uploaded a file it wipes out whatever it is bound to. application/
> octet-stream is probably a default value when nothing is uploaded.
>
> Does this happen with the unmodified code? I'd also mention this
> to Janine.
>
> Chuck
>
>> 2007/6/28, Chuck Hill <email@hidden>:
>>> 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 (email@hidden)
>>> > Help/Unsubscribe/Update your Subscription:
>>> > 40global-village.net
>>> >
>>> > This email sent to email@hidden
>>> >
>>>
>>> --
>>>
>>> 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 (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> 40global-village.net
>>
>> This email sent to email@hidden
>>
>
> --
>
> 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 (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> 40furfly.net
>
> This email sent to email@hidden
>
_______________________________________________
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