Matthew, we wrote the phone formatter in house. It's way too messy to share on here. If I were going to rewrite it, I'd use regex to:

* Strip everything except [0-9x#] from the input
* Everthing before the 'x' or '#' is the phone number, everything after is the extension * Count the number of digits in the phone number part. Make sure there are 10, then format it as (###) ###-#### ext. ###

--
Sam Barnum
360 Works
http://www.360works.com
415.865.0952



On May 14, 2008, at 11:06 PM, Matthew Young wrote:

Sorry I can't help you with your question. But may I ask where you get the
PhoneFormatter?

On Wed, May 14, 2008 at 5:58 PM, Sam Barnum <[EMAIL PROTECTED]> wrote:

Using the tips in this PDF
http://londonwicket.org/content/LondonWicket-FormsWithFlair.pdf

I created the simple RequiredBorder class as follows:

public class RequiredBorder extends MarkupComponentBorder {
       public void renderAfter(Component component) {
               FormComponent fc = (FormComponent) component;
               if (fc.isRequired()) {
                       super.renderAfter(component);
               }
       }
}

This basically adds a "*" after any required fields. It seemed to work
great until I used it with an ajax phone formatter behavior:

new AjaxFormComponentUpdatingBehavior("onchange") {
       protected void onUpdate(AjaxRequestTarget target) {
               Object oldValue = component.getValue();
String formatted = new PhoneFormatter().format (oldValue);
               component.setModelObject(formatted);
               target.addComponent(component);
       }
}


This caused duplicate "*" indicators to appear after my phone field when
the phone number changed, one per onchange request.  I tried adding a
boolean field to the RequiredBorder so it only gets processed once. This fixed the phone formatter duplicates, but if the form submits and stays on
the same page, all the "*" marks disappear from the required fields.

This is definitely some sort of lifecycle problem, but how do you fix it?

On a related note, is it generally a bad idea to mix AJAX and non- ajax actions? It seems like this is one of many issues I've run into when doing
this.

Thanks,

-Sam Barnum

Reply via email to