Hi,

Which version of ULC are you using?

What is you purpose behind using the KeyListener? Is it to validate the
text entered in the textfield? If yes then there are alternative ways of
doing validation. 

With KeyListener all validation will happen on the server side resulting
in a roundtrip for every key typed.

You can use ULC's IDataType's various implementations to do validations on
the client side without incurring a roundtrip. Also with ULC'08, there is
an inbuilt support for dispalying format errors. Please see the snippet at
the end of this mail.

>"A keyboard event is generated when a key is typed (pressed and
released). The keyTyped()method >in the listener object is then invoked,
and the KeyEventis passed to it."

The server side event is fired when the key is typed.
        
>However, I have a situation where if the information in a ULCTextField is
not valid a dialog
> will pop up when enter is pressed to inform the user of the error.  

When and how do you pop the dialog? 

Are you popping the dialog after testing in the KeyListener.keyTyped that
the key is Enter key? If yes, then you can add IActionListener on
textfield which will fire when you press enter key on the textfield.

>The problem is that keyTyped() is getting called when I press enter, but
before enter is 
>released.  This wouldn't be a problem, except that the dialog then closes
when the enter button >is released.  

Can you please tell me how and when the dialog is created and made
visible?

BTW, there is no guarantee for response time on the developer list. For
guaranteed response time please consider purchasing Premium Support so
that you can post on premium support list.
 
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
[EMAIL PROTECTED]
        Sent: Tuesday, September 23, 2008 11:54 PM
        To: [email protected]
        Subject: [ULC-developer] IKeyListener
        
        

        Has anybody else noticed this problem with the IKeyListener?
        
        The documentation says:
        
        "A keyboard event is generated when a key is typed (pressed and
released). The keyTyped()method in the listener object is then invoked,
and the KeyEventis passed to it."
        
        However, I have a situation where if the information in a
ULCTextField is not valid a dialog will pop up when enter is pressed to
inform the user of the error.  The problem is that keyTyped() is getting
called when I press enter, but before enter is released.  This wouldn't be
a problem, except that the dialog then closes when the enter button is
released.  The only way to really read the dialog is to press enter, hold
it while I read, and then release it when I'm done to dispose of the
dialog. The dialog itself is part of an API that I can't edit or extend.
        
        I thought somebody else may have noticed this and hopefully found
a way around it.
        
        Any help would be appreciated, thanks.  
        
        CONFIDENTIALITY NOTICE: This message and any attachment(s) are
solely for the use of the intended recipient(s) identified above and may
contain information that is proprietary, privileged, or confidential. If
you are not an intended recipient, you may not review, retransmit, or
otherwise use this message or any attachment. If you have received this
message in error, please immediately notify the sender by reply e-mail and
delete this message. 

-------------------------------


import java.util.HashMap;
import java.util.Map;

import com.ulcjava.base.application.AbstractAction;
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.BorderFactory;
import com.ulcjava.base.application.IAction;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.application.datatype.ULCDefaultErrorManager;
import com.ulcjava.base.application.datatype.ULCRegularExpressionDataType;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.util.Color;
import com.ulcjava.base.development.DevelopmentRunner;
import com.ulcjava.base.shared.ErrorCodes;

public class ErrorManagerRegExpDatatypeSnippet extends AbstractApplication
{
    public void start() {
        ULCTextField textField = new ULCTextField(20);
        
        Map errorMessages = new HashMap();
        
        // This error message will be shown as tooltip text
        errorMessages.put(ErrorCodes.ERROR_CODE_VALUE_DOES_NOT_MATCH,
"format : xxxx.xxxx.xx");
        
        ULCDefaultErrorManager defErrMgr =  new
ULCDefaultErrorManager(errorMessages,  Color.pink,
BorderFactory.createLineBorder(Color.red, 1));
        ULCRegularExpressionDataType validator = new
ULCRegularExpressionDataType(
                 defErrMgr,
                        "[0-9]{1,4}\\.[0-9]{1,4}\\.[0-9]{1,2}"// checked
after input is complete
        );

        textField.setDataType(validator);

        ULCBoxPane content = new ULCBoxPane(1, 0);
        content.add(textField);
        content.add(new ULCButton(new ShowValueAction(textField)));

        ULCFrame frame = new
ULCFrame("ErrorManagerRegExpDatatypeSnippet");
        frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
        frame.add(content);
        frame.setSize(300, 150);
        frame.setVisible(true);
    }

    private static class ShowValueAction extends AbstractAction {
        private ULCTextField fTextField;

        public ShowValueAction(ULCTextField textField) {
            fTextField = textField;
            putValue(IAction.NAME, "Show Value");
        }

        public void actionPerformed(ActionEvent event) {
            Object value = fTextField.getValue();
            System.out.println("value = " + value);
            System.out.println("value.getClass() = " + (value == null ?
null : value.getClass().getName()));
        }
    }
    
    public static void main(String[] args) {
 
DevelopmentRunner.setApplicationClass(ErrorManagerRegExpDatatypeSnippet.cl
ass);
        DevelopmentRunner.main(args);
    }
}
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to