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(TextFieldWithKeyMouseListener.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
