Problem with a form
Problem with a form
- Subject: Problem with a form
- From: "Sigurður E. Vilhelmsson" <email@hidden>
- Date: Thu, 28 Jun 2007 12:00:23 +0000
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) {
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) {
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:
This email sent to email@hidden