Re: Conditionals for username/password?
Re: Conditionals for username/password?
- Subject: Re: Conditionals for username/password?
- From: Nathan Dumar <email@hidden>
- Date: Mon, 8 Nov 2004 14:37:39 -0500
Instead of using a WOConditional, you could also just use a WOString,
bound to a String. In the constructor, assign the value "" to the
string. This won't show up at all for the user. Then, when the error
condition occurs, assign the error value "That username and password
combination didn't work, jerk." or something more PC. When you return
null (or this.context().page()), the page now also includes this new
text. You can also include HTML tags in the string if you remember to
set escapeHTML to false. So you can do "<font size=-1 color=red>Nope.
Try again.</font><BR>"
Both have the same result; in WOBuilder, I find working with a little
WOString easier than the boxy WOConditional. Plus it seems a bit more
flexible to me. (But, it does mix logic and display, which isn't the
best idea if you're strict about that.)
Take care,
Nathan
On Nov 8, 2004, at 1:10 PM, David LeBer wrote:
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
_______________________________________________
WebObjects-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
_______________________________________________
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