Re: Conditionals for username/password?
Re: Conditionals for username/password?
- Subject: Re: Conditionals for username/password?
- From: David LeBer <email@hidden>
- Date: Mon, 8 Nov 2004 13:10:28 -0500
On Nov 8, 2004, at 12:06 PM, Jeremy Matthews wrote:
I'm still working on my login page, but I've got a question:
If a user does not enter values into the login fields (username and
password) and clicks on the submit button, I want a WOConditional to
display "...enter your id/pass, yadda yadda yadda...".
After binding this conditional to the submit button, the submit button
no longer works. What gives? Is there a better way, short of using
JavaScript?
The conditional should be based on the result of the login action, not
bound directly to the submit button. You could do something like this:
Add these to your component:
public boolean errorFlag = false;
public boolean errorString = "";
Bind the "error conditional" to the error flag, and wrap the
conditional around a WOString bound to the errorString.
Bind the submit button to a checkUserLogin action that returns a
WOComponent
String username; // assume exists and bound to the username WOTextField
String password; // assume exists and bound to the password WOTextField
public WOComponent checkUserLogin() {
errorFlag = false;
errorString = "";
// You could check to make sure the fields have valid values
// ie:
if (username == null || username.length() == 0) {
errorFlag = true;
errorString = "A user is required. Doofus!";
return this.context().page();
}
EOEditingContext ec = session().defaultEditingContext();
NSDictionary args = new NSDictionary(new NSArray(new String[]
{username, password}),
new NSArray(new String[] {"username", "password"}));
try {
MemberData user = (MemberData)EOUtilities.objectMatchingValues(ec,
"MemberData", args);
NextPage page = (NextPage)pageWIthName("NextPage");
//setup page there
return page;
} catch (EOObjectNotAvailableException e) {
errorFlag = true;
errorString = "What are you trying to pull, that's no user I know
about. Idiot!";
return this.context().page();
}
}
Obviously your error messages should be a little more diplomatic :-)
;david
--
David LeBer
Codebase Software Systems
site: http://www.codebase.ca
blog: http://david.codebase.ca
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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