This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I imagine there must be regular expression usage. But what JSF would I use to validate. I am new to JSF and much help is much appreciated.
Kavita Tipnis
Ranch Hand
Joined: Sep 21, 2008
Posts: 177
posted
0
You can try using a custom validator
Dan Acuff
Ranch Hand
Joined: Jul 13, 2009
Posts: 62
posted
0
Hi, thanks for your reply. I think my first attempt was a backing bean attempt.
Can you correct me where I am wrong. I am very new to this but I figure I need to jump in with both feet. deleteFromCart is a fully functional method.
The method itself:
public void isNumber(Integer number, ShoppingCartItem cartId) {
if (number == 0){
deleteFromCart(cartId);
}
}
The interface tie-in:
public void isNumber(Integer number, ShoppingCartItem cartId);
You can't define a validation expression as an EL method call, and in fact, EL doesn't support method calls like that anyway. Validators are special classes with a specific organization (they contain a validate() method that throws an exception when validation fails). There are a number of built-in validators, but not many. And a few add-on ones, including a Regular Expression validator that's good for validating things like mixed alpha/numeric stuff.
The "validator" attribute is supposed to reference the name of a validator, either built-in or defined as a validator in faces-config where you map a logical validator name to a validator class and use the logical validator name in the "validator=" attribute declaration. Like I said, it's not an EL expression, just a name.
Customer surveys are for companies who didn't pay proper attention to begin with.
Dan Acuff
Ranch Hand
Joined: Jul 13, 2009
Posts: 62
posted
0
I totally get what your saying ..I tried the same thing with the valueChangeListener. does not seem to be many options to pass methods with parameters to a backing bean method.
What exactly DO I need to do, just for starters even, to get me on the correct path.
All I want to do is remove the item from the cart if they change the quantity to 0.
I recommend attaching an AJAX action to the onblur event. "onchange" has problems when you do stuff like this, even without JSF.
If your action processor invoked by the onblur action simply removes all cart items from the backing bean's model that have 0 items counts, the reRender will update the display minus the deleted items.
Assuming your cart display is a datatable, the easy way out is to rerender the entire datatable when you update the model. That's usually quick enough to make the user happy.
You do run the risk of annoying people, however. If they attempt to type something like "10" and various GUI hiccups cause the "1" to get lost, there's the possibility of something important being removed and the user being irritated enough not to replace it. I prefer an explicit "delete" button and a confirmation pop-up myself. An explicit button also makes it easier to support people who have JavaScript turned off a la the latest Adobe security bulletin.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How do I validate if an input box contains alphanumeric characters?