Hi Paul,

> I use the value changed event to see that the user has 
> modified a text field. This should only be done when the 
> focus leaves the item so that validation can be performed.

valueChanged event will be fired when value has changed on the client and
there is a roundtrip even when focus has not been lost. In your case key
listener on client is generating a roundtrip. If you don't want to
validate during this roundtrip then you can set a flag in your special
event listener and ignore validation in valueChanged event listener based
on this flag.

 I 
> would also like to know when the user types  value into the 
> item. This way I can set mandatory flags on the screen.

You can use ULCHasChangedEnabler and ULCMandatoryAndEnabler for this
purpose.

> don't want to send key listeners to the server for obvious 
> performance reasons. I therefore came up with the idea to 
> send just two events from the client to the server, when the 
> value changes from null/empty to a value or when the value 
> changes from a value to null/empty. This way I need only send 
> two events to the client.

If your validation is syntactic in nature i.e. checks for null value or
only alphanumeric etc then you can use InputVerifier on the client side:
http://lists.canoo.com/mailman/private/ulc-developer/2006/004888.html


You can keep track on the server side of the fact whether value changed
from null to something or something to null using the following extension:

 public class MyULCTextField extends ULCTextField {
        public MyULCTextField(String string) {
            super(string);
        }

        public MyULCTextField(int i) {
            super(i);
        }

        
        private Object fLastValue;
     
        @Override
        protected void updateValue(Object value) {
            fLastValue = getValue();
            super.updateValue(value);
            System.out.println("Last val " + fLastValue + " New val " +
getValue());
        }
    } 

The updateValue method is called during a roundtrip if the textfield has
changed on the client.
 
Thanks and regards,

Janak

-----------------------------------------
Janak Mulani

email: [email protected]
url: http://www.canoo.com

Beyond AJAX - Java Rich Internet Applications 

http://www.canoo.com/ulc
-----------------------------------------  

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of 
> Paul Harrison
> Sent: Tuesday, February 02, 2010 5:42 PM
> To: '[email protected]'; '[email protected]'
> Subject: RE: [ULC-developer] Text Field and Value changed event
> 
> Hi Janek
> 
> Yes, I thought that this was happening.
> 
> My requirement is this:
> 
> I use the value changed event to see that the user has 
> modified a text field. This should only be done when the 
> focus leaves the item so that validation can be performed. I 
> would also like to know when the user types  value into the 
> item. This way I can set mandatory flags on the screen. I 
> don't want to send key listeners to the server for obvious 
> performance reasons. I therefore came up with the idea to 
> send just two events from the client to the server, when the 
> value changes from null/empty to a value or when the value 
> changes from a value to null/empty. This way I need only send 
> two events to the client.
> 
> Paul
> 
> 
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Janak Mulani
> Sent: Dienstag, 2. Februar 2010 17:31
> To: [email protected]
> Subject: RE: [ULC-developer] Text Field and Value changed event
> 
> Hi Paul,
> 
> > ValueChanged event. The ValueChanged event should only be 
> > sent to the client when focus leaves the item, which is not 
> happening.
> 
> We fixed the following bug:
> 
> https://www.canoo.com/jira/browse/UBA-7287
> 
> If while editing a text field there is a roundtrip (like your custom
> event), the textfield flushes the data and since that changes 
> the value on
> the server side it follows that the valueChanged event is fired.
> 
> Can you tell me what is your exact requirement? May be I can 
> suggest an
> alternative.
> 
> BTW, we will look into your premium list problem.
> 
> Thanks and regards,
> 
> Janak
> 
> -----------------------------------------
> Janak Mulani
> 
> email: [email protected]
> url: http://www.canoo.com
> 
> Beyond AJAX - Java Rich Internet Applications 
> 
> http://www.canoo.com/ulc
> -----------------------------------------  
> 
> > -----Original Message-----
> > From: Paul Harrison [mailto:[email protected]] 
> > Sent: Tuesday, February 02, 2010 4:09 PM
> > To: '[email protected]'
> > Subject: RE: [ULC-developer] Text Field and Value changed event
> > 
> > Dear Janak
> > 
> > Unfortunately the error is still there. I have changed my 
> > code to use the code example you give below. I get the event 
> > sent to the server as expected, but the problem exists that 
> > when the ActionEvent comes to the server, so does the 
> > ValueChanged event. The ValueChanged event should only be 
> > sent to the client when focus leaves the item, which is not 
> happening.
> > 
> > Janka, I have sent the reply originally to the Developer List 
> > from my work account ([email protected]) but I got the 
> > standard reply indicating that I have not yet registered.
> > 
> > Paul
> > 
> > 
> > 
> > -----Original Message-----
> > From: [email protected] 
> > [mailto:[email protected]] On Behalf Of 
> Janak Mulani
> > Sent: Dienstag, 2. Februar 2010 11:34
> > To: [email protected]
> > Subject: RE: [ULC-developer] Text Field and Value changed event
> > 
> >  
> > Hi Paul,
> > 
> > Firstly we have updated our records and your should be able 
> to post on
> > premium list.
> > 
> > Secondly, it seems that you have created your own event 
> > category. Please
> > see section 4.3 of ULC Extension Guide that describes 
> > creating a custom
> > event type.
> > 
> > From your code snippets, I have created a sample (see below) 
> > which has the
> > key and mouse listeners on the client side but which fires an 
> > ActionEvent
> > (one of the predefined event categories). It works fine. 
> >  
> > Thanks and regards,
> > 
> > Janak
> > 
> > -----------------------------------------
> > Janak Mulani
> > 
> > email: [email protected]
> > url: http://www.canoo.com <http://www.canoo.com/> 
> > 
> > Beyond AJAX - Java Rich Internet Applications
> > 
> > http://www.canoo.com/ulc
> > ----------------------------------------- 
> > ________________________________
> > 
> >     From: [email protected]
> > [mailto:[email protected]] On Behalf Of 
> > Paul Harrison
> >     Sent: Monday, February 01, 2010 11:54 AM
> >     To: '[email protected]'
> >     Subject: [ULC-developer] Text Field and Value changed event
> >     
> >     Hi all
> > 
> >     I have a ULCTextField that I have created an extension to its
> > client couterpart, the UITextField.
> > 
> >     My UITextfield extends the standard one because I need 
> > three extra
> > events. A mouse double click and a value from and value to 
> > null event. 
> > 
> >     The double click listener is working just fine but I am having
> > problems with my valueFromNullEvent and the valueToNullEvent. 
> > The events
> > themselves work just fine, the only problem is, is that 
> when I send my
> > event to the server, it also invokes the ValueChangedEvent. The
> > ValueChangedEvent normally only gets fired once focus leaves 
> > the field. I
> > have not left the field and I have no server code that would 
> > force a focus
> > changed.
> >      
> >     my client code is as follows:
> > 
> >      protected void postInitializeState()
> >         {
> >             super.postInitializeState();
> > 
> >             _borderManager = new BorderManager(this);
> >             getBasicTextField().addKeyListener(new KeyListener()
> >             {
> >                 public void keyTyped(KeyEvent e)
> >                 {
> >                     if (Character.isLetterOrDigit(e.getKeyChar()))
> >                     {
> >                         if (getBasicTextField().getText() == null ||
> > getBasicTextField().getText().trim().length() == 0)
> >                         {
> >     
> > fireEventULC(SPRINT_VALUE_CHANGED_FROM_NULL_EVENT,
> > SPRINT_VALUE_CHANGED_FROM_NULL_EVENT, new Object[] {});
> >                         }
> >                     }
> >                 }
> > 
> >                 public void keyReleased(KeyEvent e)
> >                 {
> >                    if (getBasicTextField().getText() == null ||
> > getBasicTextField().getText().length() == 0)
> >                     {
> >                     fireEventULC(SPRINT_VALUE_CHANGED_TO_NULL_EVENT,
> > SPRINT_VALUE_CHANGED_TO_NULL_EVENT, new Object[] {});
> >                     }
> >                 }
> > 
> >                 public void keyPressed(KeyEvent e)
> >                 {
> >                 }
> >             });
> > 
> >      
> > 
> >             getBasicTextField().addMouseListener(new MouseListener()
> >             {
> >                   public void mouseClicked(MouseEvent e)
> >                 {
> >                     if (e.getClickCount() == 2)
> >                     {
> >                         fireEventULC(SPRINT_DOUBLE_CLICK_EVENT,
> > "doubleClicked", new Object[] {});
> >                     }
> >                 }
> > 
> >                             ....
> > 
> >                             ....
> > 
> >                             ....
> > 
> >      
> > 
> >     It seems to me that the KexEvents are logged by ULC to 
> > be able to
> > know if a value has changed. Because I have my own key 
> listener which
> > fires its own event, it seems to get in the way of the 
> > valuechanged event.
> > I tried printing out the isValueChangedEventPending()  
> value but it is
> > false.
> > 
> >     Could you please tell me if I am doing something wrong 
> > or if this
> > is standard behaviour. If it is standard behaviour then the 
> > Java Doc of
> > the ValueChangedEvent is incorrect and I would be very 
> grateful for a
> > workaround.
> > 
> >     Kins regards
> > 
> >     Paul Harrison
> > --------------------------------
> > 
> > 
> > import java.awt.event.KeyEvent;
> > import java.awt.event.KeyListener;
> > import java.awt.event.MouseAdapter;
> > import java.awt.event.MouseEvent;
> > 
> > import com.ulcjava.base.application.AbstractApplication;
> > import com.ulcjava.base.application.ULCBoxPane;
> > import com.ulcjava.base.application.ULCContainer;
> > import com.ulcjava.base.application.ULCFrame;
> > import com.ulcjava.base.application.ULCTextField;
> > import com.ulcjava.base.application.event.ActionEvent;
> > import com.ulcjava.base.application.event.IActionListener;
> > import com.ulcjava.base.application.event.IValueChangedListener;
> > import com.ulcjava.base.application.event.ValueChangedEvent;
> > import com.ulcjava.base.client.UITextField;
> > import com.ulcjava.base.development.DevelopmentRunner;
> > import com.ulcjava.base.shared.UlcEventCategories;
> > 
> > 
> > public class TextFieldWithKeyMouseListener extends 
> > AbstractApplication {
> > 
> >     public void start() {
> >         ULCFrame frame = new 
> > ULCFrame("TextFieldWithKeyMouseListener");
> >         frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
> >         frame.getContentPane().add(createView());
> >         frame.setSize(200, 200);
> >         frame.setVisible(true);
> > 
> >     }
> > 
> >     public ULCContainer createView() {
> >         ULCBoxPane hBox = new ULCBoxPane(true);
> > 
> >         TextFieldActionListener actionListener = new
> > TextFieldActionListener();
> > 
> >         ULCTextField textField = new MyULCTextField(10);
> >         textField.addActionListener(actionListener);
> >         textField.addValueChangedListener(new 
> > IValueChangedListener() {
> >             public void valueChanged(ValueChangedEvent event) {
> >                 System.out.println(".valueChanged()");
> >             }
> >         });
> > 
> >         ULCTextField textField2 = new ULCTextField(10);
> >         textField2.addActionListener(actionListener);
> > 
> >         hBox.add(textField);
> >         hBox.add(textField2);
> >         return hBox;
> >     }
> > 
> >     private class TextFieldActionListener implements 
> IActionListener {
> >         public void actionPerformed(ActionEvent event) {
> >             System.out.println("Action event : " +
> > event.getActionCommand());
> >         }
> >     }
> > 
> >     public static void main(String[] args) {
> >  
> > DevelopmentRunner.setApplicationClass(TextFieldWithKeyMouseLis
> > tener.class)
> > ;
> >         DevelopmentRunner.main(args);
> >     }
> > 
> >     public static class MyULCTextField extends ULCTextField {
> >         public MyULCTextField(String string) {
> >             super(string);
> >         }
> > 
> >         public MyULCTextField(int i) {
> >             super(i);
> >         }
> > 
> >         protected String typeString() {
> >             return MyUITextField.class.getName();
> >         }
> >     }
> > 
> >     public static class MyUITextField extends UITextField {
> > 
> >         @Override
> >         protected void postInitializeState() {
> >             super.postInitializeState();
> >             getBasicTextField().addKeyListener(new KeyListener() {
> >                 public void keyTyped(KeyEvent e) {
> >                     if (Character.isLetterOrDigit(e.getKeyChar())) {
> >                         if (getBasicTextField().getText() == null ||
> > getBasicTextField().getText().trim().length() == 0) {
> >  
> > fireEventULC(UlcEventCategories.ACTION_EVENT_CATEGORY, 
> > "actionPerformed",
> > new Object[] {
> >                                     
> > "SPRINT_VALUE_CHANGED_TO_NULL_EVENT",
> > new Integer(0) });
> >                             //
> > fireEventULC(SPRINT_VALUE_CHANGED_FROM_NULL_EVENT,
> > SPRINT_VALUE_CHANGED_FROM_NULL_EVENT,
> >                             // new Object[] {});
> >                         }
> >                     }
> >                 }
> > 
> >                 public void keyReleased(KeyEvent e) {
> >                     if (getBasicTextField().getText() == null ||
> > getBasicTextField().getText().length() == 0) {
> >  
> > fireEventULC(UlcEventCategories.ACTION_EVENT_CATEGORY, 
> > "actionPerformed",
> > new Object[] {
> >                                 
> > "SPRINT_VALUE_CHANGED_TO_NULL_EVENT", new
> > Integer(0) });
> >                         //
> > fireActionPerformedULC(event.getActionCommand(), 
> > getCurrentModifiers());
> >                         //
> > fireEventULC(SPRINT_VALUE_CHANGED_TO_NULL_EVENT,
> > SPRINT_VALUE_CHANGED_TO_NULL_EVENT,
> >                         // new Object[] {});
> >                     }
> >                 }
> > 
> >                 public void keyPressed(KeyEvent e) {
> >                 }
> >             });
> > 
> >             getBasicTextField().addMouseListener(new 
> MouseAdapter() {
> >                 public void mouseClicked(MouseEvent e) {
> >                     if (e.getClickCount() == 2) {
> > 
> >  
> > fireEventULC(UlcEventCategories.ACTION_EVENT_CATEGORY, 
> > "actionPerformed",
> > new Object[] {
> >                                 "doubleClicked", new Integer(0) });
> >                         // fireEventULC(SPRINT_DOUBLE_CLICK_EVENT,
> > "doubleClicked", new Object[] {});
> >                     }
> >                 }
> > 
> >             });
> >         }
> >     }
> > }
> > _______________________________________________
> > ULC-developer mailing list
> > [email protected]
> > http://lists.canoo.com/mailman/listinfo/ulc-developer
> > 
> _______________________________________________
> ULC-developer mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/ulc-developer
> _______________________________________________
> ULC-developer mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/ulc-developer
> 
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to