Re: Another simple problem I am clueless about...
Re: Another simple problem I am clueless about...
- Subject: Re: Another simple problem I am clueless about...
- From: Chuck Hill <email@hidden>
- Date: Fri, 16 Mar 2007 16:48:06 -0700
On Mar 16, 2007, at 2:23 PM, Kevin Windham wrote:
I have a User object with an email() method. This is the standard
boilerplate generated by EOModeler from my User table.
public String email() {
return (String)storedValueForKey("email");
}
I have a registration page with a field on the page bound to
user.email and a method called fieldsValidate(). When I get to the
line ckEmail = user.email(); I get a null pointer exception.
user.email() is returning null. I am not sure why? The
registerNewUser method works fine if I take out the fieldsValidate
(). Can someone hit me with the clue-by-4.
Is it null if you type something into the email field on the form?
If you don't type in anything, WO makes the value a null, not an
empty string. Is that where you are getting hung up.
public class MyAccount_ActivateNewAccount extends WOComponent {
public User user;
public String confirmPassword;
public Boolean error;
protected String
ckEmail,ckFirstName,ckLastName,ckaddress1,ckCity,ckState,ckZip;
public MyAccount_ActivateNewAccount(WOContext context) {
super(context);
user = new User();
}
public Boolean fieldsValidate()
{
String highlight = "background: yellow;";
ckEmail = user.email();
if (ckEmail.equals("")) {
ckEmail = highlight;
} else { ckEmail = ""; }
if ((ckEmail+ckFirstName+ckLastName+ckaddress1+ckCity+ckState
+ckZip).equals("")) {
return true;
}
else {
return false;
}
}
public WOComponent registerNewUser()
{
if (fieldsValidate()) {
EOEditingContext ec = session().defaultEditingContext();
NSMutableArray arguments = new NSMutableArray();
arguments.addObject(user.email());
EOQualifier qualifier = EOQualifier.qualifierWithQualifierFormat
("email = %@", arguments);
EOFetchSpecification fetchSpec = new EOFetchSpecification
("User",qualifier,null);
NSArray results = new NSArray(ec.objectsWithFetchSpecification
(fetchSpec));
if (results.count() == 0) {
ec.insertObject(user);
ec.saveChanges();
}
else {
return null;
}
You are violating EOF Commandments. Thou shalt obey the commandments
or EOF shall smite thee. Really, really hard too.
http://en.wikibooks.org/wiki/Programming:WebObjects/EOF/Using_EOF/
The_EOF_Commandments
Chuck
MyAccount_RegistrationConfirmation nextPage =
(MyAccount_RegistrationConfirmation)pageWithName
("MyAccount_RegistrationConfirmation");
// Initialize your component here
nextPage.userID = user.email();
nextPage.password = user.password();
return nextPage;
}
else {
return null;
}
}
}
_______________________________________________
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:
This email sent to email@hidden