Hi Paul, > It looks as if I am not able to construct what I need without > a round trip and therefore executing the value changed event.
Ok. Then it is important for you to distinguish within the valueChanged method whether the textfield still has focus . You validate if it does not have focus and ignore validation if it has focus. See the snippet below which shows how to do this. > I think it would be a good idea to update the JavaDoc for the > ValueChangedEvent as there it does not mention the "problem" > with a round trip causing the event to fire. Thanks for the suggestion. I have created https://www.canoo.com/jira/browse/UBA-7921 for fixing in the next release. > with a round trip causing the event to fire. I personally > think it is a bug that the value changed is sent with every > round trip. ValueChanged will be fired whenever value in the textfield has changed on the client side. In Swing suppose you are editing a text field and you press accelerator key for a menu item. The menu action is fired even though the textfield still hold focus. In the event handler for menu action you can get the latest value of the textfield. We want to have similar behavior for ULCTextField. So on a roundtrip dirty value of the textfield is synched to the server i.e. value of the textfield on the server becomes same as that on the client side and is available in the action handler for the menu item. Since the text value on the server is changing we must fire valueChanged event. 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: Thursday, February 04, 2010 10:15 AM > To: '[email protected]' > Subject: RE: [ULC-developer] Text Field and Value changed event > > Hi Janak > > Unfortunately this does not completely solve my problem. > > I would have like to have used the focusLost event but can't > as I need to know when a field changes The focus lost fires > every time navigate moves from or to an item. For example. If > have a validation routine that checks the entered value > against the database and if it is not unique then I need to > show the user a list of valid values to choose from. This > validation should only occur if the user has made changes to > the field. I also call other validation routines when a user > changes a value. Again, these validation routines should only > fire if actual changes were made. I could store two values > for each text field and then check one against the other, but > obviously this is not a good idea. > > I like idea to use the ULC Enablers but I have a problem with > them. The enablers only check for values entered into a > field. This would solve half of my problem, but I also have > the validation routines that are fired and depending on > whether the validation routine was successful I am also > enabling buttons. Therefore I have the following scenario: > > I have an edit screen with different fields, some editable > some display only, some of the fields are mandatory and some > have validation routines attached. Only when all mandatory > fields have been entered and the validation routines are > successful do I enable the "ok" button. I can use the > enablers for the mandatory fields but not the fields that > have a validation routine attached. > > Using the InputVerifier will not work as I am not stopping > the users from entering a certain value, I just need to react > when they do add a value. > > It looks as if I am not able to construct what I need without > a round trip and therefore executing the value changed event. > I think it would be a good idea to update the JavaDoc for the > ValueChangedEvent as there it does not mention the "problem" > with a round trip causing the event to fire. I personally > think it is a bug that the value changed is sent with every > round trip. I think it should work the same as written in the > JavaDoc. Otherwise nobody can ever be sure when the event > will actually fire. > > Paul --------------------- import com.ulcjava.base.application.AbstractApplication; import com.ulcjava.base.application.ULCBoxPane; import com.ulcjava.base.application.ULCButton; import com.ulcjava.base.application.ULCCheckBox; import com.ulcjava.base.application.ULCFrame; import com.ulcjava.base.application.ULCMenu; import com.ulcjava.base.application.ULCMenuBar; import com.ulcjava.base.application.ULCMenuItem; import com.ulcjava.base.application.ULCPollingTimer; 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.KeyEvent; import com.ulcjava.base.application.event.ValueChangedEvent; import com.ulcjava.base.application.util.KeyStroke; import com.ulcjava.base.client.UITextField; import com.ulcjava.base.development.DevelopmentRunner; import com.ulcjava.base.server.IDispatcher; public class InFocusTextFieldValueChanged extends AbstractApplication { private ULCTextField fTextField; private boolean fValueChanged; private ULCTextField fSecondTextfield; private ULCCheckBox fCheckBox; private ULCPollingTimer fPoll; private ULCButton fButton; public void start() { ULCFrame frame = new ULCFrame("InFocusTextFieldValueChanged"); ULCMenuBar bar = new ULCMenuBar(); ULCMenu menu = new ULCMenu("File"); ULCMenuItem menuItem = new ULCMenuItem("Save"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK, false)); menuItem.addActionListener(new IActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Menu Action Text: " + fTextField.getValue()); } }); fPoll = new ULCPollingTimer(10000, new IActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Polling Action : " + fTextField.getText() + " : " + fSecondTextfield.getText() + " : " + fCheckBox.isSelected()); } }); fPoll.start(); menu.add(menuItem); bar.add(menu); ULCBoxPane box = new ULCBoxPane(true); fTextField = new MyTextField(10); fTextField.addValueChangedListener(new IValueChangedListener() { public void valueChanged(ValueChangedEvent event) { fValueChanged = true; boolean infocus = ((MyTextField)fTextField).isInfocus(); System.out.println("First Field Value changed > " + fTextField.getValue() + " Infoucs " + infocus); if (infocus) { // mark textfield as dirty ((MyTextField)fTextField).markAsDirty(); } else { // validate } } }); box.add(ULCBoxPane.BOX_EXPAND_CENTER, fTextField); fSecondTextfield = new ULCTextField(10); fSecondTextfield.addValueChangedListener(new IValueChangedListener() { public void valueChanged(ValueChangedEvent event) { fValueChanged = true; System.out.println("Second Field Value changed > " + fSecondTextfield.getValue()); } }); box.add(ULCBoxPane.BOX_EXPAND_CENTER, fSecondTextfield); fCheckBox = new ULCCheckBox("Check"); box.add(ULCBoxPane.BOX_EXPAND_CENTER, fCheckBox); fButton = new ULCButton("Stop"); fButton.addActionListener(new IActionListener() { public void actionPerformed(ActionEvent event) { if (fPoll.isRunning()) { fButton.setText("Start"); fPoll.stop(); } else { fButton.setText("Stop"); fPoll.start(); } } }); box.add(ULCBoxPane.BOX_EXPAND_CENTER, fButton); frame.add(box); frame.setMenuBar(bar); frame.setSize(300, 300); frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE); frame.setVisible(true); } public static void main(String[] args) throws Exception { DevelopmentRunner.setApplicationClass(InFocusTextFieldValueChanged.class); DevelopmentRunner.main(args); } public boolean isValueChanged() { return fValueChanged; } public void setValueChanged(boolean valueChanged) { fValueChanged = valueChanged; } public ULCTextField getTextField() { return fTextField; } public ULCTextField getSecondTextfield() { return fSecondTextfield; } public static class MyTextField extends ULCTextField { boolean fInfocus; public MyTextField(int i) { super(i); } public void markAsDirty() { invokeUI("markAsDirty"); } protected void updateValue(Object value) { System.out.println("First Field Server Update Value: " + value); super.updateValue(value); } protected String typeString() { return MyUITextField.class.getName(); } protected void updateInFocus(boolean focus) { fInfocus = focus; } public boolean isInfocus() { return fInfocus; } protected IDispatcher createDispatcher() { return new MyTextFieldDispatcher(); } protected class MyTextFieldDispatcher extends ULCTextComponentDispatcher { public final void updateInFocus(boolean inFocus) { MyTextField.this.updateInFocus(inFocus); } } } public static class MyUITextField extends UITextField { public void flushDirtyData() { super.flushDirtyData(); updateStateULC("inFocus", fInFocus); } public void markAsDirty() { getSession().addDirtyDataOwner(this); setValueChangedEventPending(true); } } _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
