Hi Paul,

In general, you can use:

- invokeULC to invoke a method on the server siide proxy from the client
- invokeUI to invoke a method on the client side proxy from the server

But calling invokeULC from the verify() method won't help because it has to
return a value to be able to set the focus.

So if you are using an InputVerifier then you will have to do the validation
on the client side.

On ULCCheckBox/ULCRadioButton the valueChanged is invoked only when the
value changes. So if you have a wrong value and you lose focus on the
checkbox (e.g. by tabbing out) then valueChanged event won't be fired.

On ULCTextField, the valueChanged event is fired on losing focus and only if
the value has changed. In the case of textfield, what you can do is in the
valueChangedListener check the value and if it is not correct make the
client side textfield dirty. Please see the snippet below.

I hope this helps.

Thanks and regards,

Janak

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

import com.ulcjava.base.application.AbstractApplication;
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.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;

public class TextFieldValidationOnValueChangeSnippet extends
AbstractApplication {

        public void start() {
                ULCBoxPane content = new ULCBoxPane(true);

                final ULCMyTextField field = new ULCMyTextField(10);
                content.add(field);
                field.addValueChangedListener(new IValueChangedListener() {
                        public void valueChanged(ValueChangedEvent event) {
                                ULCMyTextField fld = (ULCMyTextField) 
event.getSource();
                                if (fld.getText() == null || 
!fld.getText().equals("pass")) {
                                        fld.requestFocus();
                                        fld.makeDirty();
                                }
                        }
                });


                ULCButton but = new ULCButton("Button");
                but.addActionListener(new IActionListener() {

                        public void actionPerformed(ActionEvent event) {
                                System.out.println(field.getText());
                        }
                });

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

        public static void main(String[] args) {
                DevelopmentRunner
                                
.setApplicationClass(TextFieldValidationOnValueChangeSnippet.class);
                DevelopmentRunner.run();
        }

        public static class ULCMyTextField extends ULCTextField {

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

                protected String typeString() {
                        return UIMyTextField.class.getName();
                }

                public void makeDirty() {
                        invokeUI("makeDirty");
                }

        }

        public static class UIMyTextField extends UITextField {
                public void makeDirty() {
                        getBasicTextField().setText("");
                }

                protected void postInitializeState() {
                        super.postInitializeState();
                }

        }
}

>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] Behalf Of
>[EMAIL PROTECTED]
>Sent: Wednesday, October 18, 2006 6:29 PM
>To: [email protected]
>Subject: Re:RE: [ULC-developer] component validation - Navigation
>
>
>Hi Janak
>
>Unfortunately I cannot use the focus lost as I need to valid each
>item when chages are made, If I use the focus lost method then I
>get a call to the validation once for the correct item and when I
>put the focus back to the item if the validation fails then the
>other items focus lost method is fired.
>
>I thought about using a client side vefifier but the verifier must
>call the validation method on the server. How do I do a call to
>the server side from the client object?
>
>Paul
>
>
>>Hi Paul,
>>
>>ValueChanged Listener will be called only if the value changes.
>>
>>Isn't it possible to do the validation on FocusLost event?
>>
>>Alternatively you could extend the component to set an
>InputVerifier on the
>>client side:
>>
>>Server-side class:
>>
>>      public class ULCMyTextField extends ULCTextField {
>>
>>              public ULCMyTextField(int i) {
>>                      super(i);
>>              }
>>
>>              protected String typeString() {
>>                      return "mypackage.UIMyTextField";
>>              }
>>
>>      }
>>
>>Client-side class:
>>
>>      public class UIMyTextField extends UITextField {
>>
>>              protected void postInitializeState() {
>>                      super.postInitializeState();
>>                      getBasicTextField().setInputVerifier(new
>InputVerifier() {
>>
>>                              public boolean verify(JComponent input) {
>>                                      JTextField  text =
>((JTextField)input);
>>                                      return
>text.getText().equals("pass");
>>                              }
>>
>>                      });
>>              }
>>
>>      }
>>
>>The advantage is that there will be no server round trip.
>>
>>The disadvantage is that your business logic is moving to the
>client and if
>>you have to do complex validation against your business objects then you
>>will have to make all that available on the client.
>>
>>I hope this helps.
>>
>>Thanks and regards,
>>
>>Janak
>>
>>>-----Original Message-----
>>>From: [EMAIL PROTECTED]
>>>[mailto:[EMAIL PROTECTED] Behalf Of
>>>[EMAIL PROTECTED]
>>>Sent: Monday, October 16, 2006 2:38 PM
>>>To: [email protected]
>>>Subject: [ULC-developer] component validation - Navigation
>>>
>>>
>>>Hi all
>>>
>>>I have to perform validation on a text field/ check box / radio
>>>group etc and if the validation fails then the focus should stay
>>>within the item being validated. I have added a value changed
>>>listener and reset the focus back to the item being validated but
>>>after being validated once and the user navigates out again the
>>>value changed will not be called. Also, if the validation is being
>>>performed within a dialog window with a default button set then
>>>there is also a problem. the user changes the text in a text field
>>>and hits enter, the validation method is called but the button is
>>>also being pressed i.e. Focus does not stay in the item being validated.
>>>
>>>I dont want any navigation out of the field until the validation
>>>method returns true. I have seen an InputVerifier in Swing that
>>>seems to provide exactly the required functionality but I don't
>>>know how to implement this in ULC. Or do you have any other ideas?
>>>
>>>I have searched the archives for an answer to my problem, but have
>>>not found anything so I would be gratefull for your help
>>>
>>>Paul Harrison
>>>
>>>
>>>_____________________________________________________________
>>>NEU: Ihre Photos online verwalten, mit anderen teilen und die
>>>besten Bilder gleich entwickeln lassen - GRATIS für den 1. Monat
>>>(exkl. Entwicklung)
>>>www.sunrise.ch/photoalbum
>>>_______________________________________________
>>>ULC-developer mailing list
>>>[email protected]
>>>http://lists.canoo.com/mailman/listinfo/ulc-developer
>>
>>
>_____________________________________________________________
>NEU: Ihre Photos online verwalten, mit anderen teilen und die
>besten Bilder gleich entwickeln lassen - GRATIS für den 1. Monat
>(exkl. Entwicklung)
>www.sunrise.ch/photoalbum
>_______________________________________________
>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