Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    setTabIndex on FormItem

    Hi,

    We are using
    a) SmartClient Version: v9.1p_2014-05-15/Pro Deployment (built 2014-05-15)
    b) Testing using IE 11.0.9600.17126

    In our application, we disallow a user from tabbing into a non-editable form item. This form item may or may not start off being editable, but under some condition, at run time, we make it editable or non-editable.

    We do this by allowing smartgwt to generate the tab index. So we save the generated tab index value, and then we remove it or set it back again depending on the scenerio. The setTabIndex method simply ignores the value that we reset it to. Below you will find our code. If this is not what we should be doing please let me know how we can accomplish this.

    Thanks,
    Voula

    Code:
    package com.example.myproject.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.PasswordItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    
    public class Testbutton implements EntryPoint {
    
    
    	private TextItem usernameItem;
    	private TextItem emailItem;
    	private PasswordItem passwordItem;
    	private PasswordItem password2Item;
    	private Integer emailItemTabIndex;
    
    	public void onModuleLoad() {
    		VLayout layout = new VLayout(20);  
    
    		final DynamicForm form = new DynamicForm();  
    		form.setWidth(250);  
    
    		usernameItem = new TextItem();  
    		usernameItem.setTitle("Username");  
    		usernameItem.setDefaultValue("bob");  
    
    		emailItem = new TextItem();  
    		emailItem.setTitle("Email");  
    		emailItem.setDefaultValue("bob@isomorphic.com");  
    		
    		passwordItem = new PasswordItem();  
    		passwordItem.setTitle("Password");  
    
    		password2Item = new PasswordItem();  
    		password2Item.setTitle("Password again");  
    		password2Item.setType("password");  
    
    		
    		form.setFields(new FormItem[] {usernameItem, emailItem, passwordItem, password2Item});  
    
    		IButton btnDisable = new IButton("Disable Item");  
    		btnDisable.addClickHandler(new ClickHandler() {  
    			public void onClick(ClickEvent event) {
    
    				disableEmail();
    			}  
    		});  
    
    		IButton btnEnable = new IButton("Enable Item");  
    		btnEnable.addClickHandler(new ClickHandler() {  
    			public void onClick(ClickEvent event) {
    
    				enableEmail();
    			}  
    		});  
    		layout.addMember(form);  
    
    		HLayout buttonLayout = new HLayout(10);
    		buttonLayout.addMember(btnDisable);  
    		buttonLayout.addMember(btnEnable); 
    		layout.addMember(buttonLayout);  
    		layout.draw();  
    
    		SC.say("emailItem:TabIndex: "+emailItem.getTabIndex()+"");
    		emailItemTabIndex = emailItem.getTabIndex();
    
    	}
    
    	void enableEmail(){
    		emailItem.setCanEdit(true);
    		emailItem.setCanFocus(true);
    		emailItem.setTabIndex(emailItemTabIndex);
    
    		SC.say("emailItem:TabIndex: "+emailItem.getTabIndex()+"");
    	}
    
    	void disableEmail(){
    		emailItem.setCanEdit(false);
    		emailItem.setCanFocus(false);
    		emailItem.setTabIndex(-1);
    		SC.say("emailItem:TabIndex: "+emailItem.getTabIndex()+"");
    	}
    
    }
    Last edited by Isomorphic; 25 Jul 2014, 12:29. Reason: formatted code block

    #2
    Just a quick note to let you know this is under investigation and we'll let you know when we have more information.

    Regards
    Isomorphic Software

    Comment


      #3
      This has been fixed in SGWT 5.0d and 4.1p; check the next nightly builds.

      Comment


        #4
        Regression?

        Originally posted by Isomorphic View Post
        This has been fixed in SGWT 5.0d and 4.1p; check the next nightly builds.
        Hi, Voula's colleague here...

        I tried using the 2004-08-03 nightly and that fixed the issue.

        Not trying to hijack the thread but I noticed that the FormItem.setHoverWidth() method now throws a NullPointerException if invoked with a null (the default value according to the JavaDoc.)

        Caused by: java.lang.NullPointerException
        at com.smartgwt.client.widgets.form.fields.FormItem.setAttribute(FormItem.java:5124)
        at com.smartgwt.client.widgets.form.fields.FormItem.setCellHeight(FormItem.java:553)

        The same code was working perfectly fine using the 2014-07-09 nightly.

        It appears to be only an issue with non-String properties - Example with a Boolean property:

        Caused by: java.lang.NullPointerException
        at com.smartgwt.client.widgets.form.fields.FormItem.setAttribute(FormItem.java:5124)
        at com.smartgwt.client.widgets.form.fields.FormItem.setCellHeight(FormItem.java:553)

        FormItem.setAccessKey(null) does not throw a NullPointerException.

        Please confirm that this is the expected behavior with null values or if this is a regression.

        Thanks,

        Frederic

        Comment


          #5
          We see this and it will be resolved by tonight's nightly builds. It was a result of the recent restructuring of the setAttribute() APIs in DataClass.java and FormItem.java.

          Comment


            #6
            Just a heads up...

            Originally posted by Isomorphic View Post
            We see this and it will be resolved by tonight's nightly builds. It was a result of the recent restructuring of the setAttribute() APIs in DataClass.java and FormItem.java.
            Good to know!

            On a related note, the Record.getAttributeAsBoolean(String property) method used to return Boolean.FALSE if the attribute was never set.
            This does not seem to be the case anymore - the method returns null instead.

            What is the expected/official behavior when the attribute was never set?

            Even worse, the Record.getAttributeAsBoolean(String property) method throws an exception when the attribute was set.

            Code:
            Record record = new Record();
            record.setAttribute("true", Boolean.TRUE);
            record.setAttribute("false", Boolean.FALSE);
            
            // This used to return false but now returns null
            SC.say( "undefined:" + record.getAttributeAsBoolean("undefined"));
            
            // This works fine
            SC.say( "true :" + (((Boolean)record.getAttributeAsObject("true")) == true) + "<br>" +
                    "false:" + (((Boolean)record.getAttributeAsObject("false")) == true));
            
            // This fails with an exception...
            SC.say( "true :" + record.getAttributeAsBoolean("true") + "<br>" +
            	"false:" + record.getAttributeAsBoolean("false"));
            Exception:
            Code:
            java.lang.IllegalArgumentException: Something other than a Java object was returned from JSNI method '@com.smartgwt.client.core.DataClass::getAttributeAsBoolean(Ljava/lang/String;)': JS value of type boolean, expected java.lang.Object 
            	at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:178)
             	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:271)
             	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
             	at com.smartgwt.client.core.DataClass.getAttributeAsBoolean(DataClass.java)

            Hope this is useful to you.
            Regards,

            Frederic

            Comment


              #7
              On a related note, the Record.getAttributeAsBoolean(String property) method used to return Boolean.FALSE if the attribute was never set.
              This does not seem to be the case anymore - the method returns null instead.

              What is the expected/official behavior when the attribute was never set?
              Grabbing a random unset property of a Record as a Boolean should return null. There was a bug (reported by another customer) whereby the logic was flowing through a boolean, which caused it to be converted to false.

              Editor's Note: See post http://forums.smartclient.com/showth...d=1#post122856

              Even worse, the Record.getAttributeAsBoolean(String property) method throws an exception when the attribute was set.
              Are you saying this is happening in today's build or yesterday's build where you saw the other problem? By "Good to Know," it's not clear whether you've installed today's build.
              Last edited by Isomorphic; 6 Aug 2014, 08:49.

              Comment


                #8
                Originally posted by Isomorphic View Post
                Are you saying this is happening in today's build or yesterday's build where you saw the other problem? By "Good to Know," it's not clear whether you've installed today's build.
                Sorry, I should have been more specific. This behavior was last observed with the 2014-08-03 nightly as I was waiting for a confirmation (along the lines of 'This has been fixed in SGWT 5.0d and 4.1p; check the next nightly builds. ') that the fix was included as part of the latest nightly.

                Frederic

                Comment


                  #9
                  Fixed in the 2014-08-06 Nightly

                  Hi,

                  I can confirm that all the issues raised with regards to the getAttribute_ methods have been fixed in the 2014-08-06 Nightly build.
                  Thanks,

                  Frederic

                  Originally posted by fkamthong View Post
                  Sorry, I should have been more specific. This behavior was last observed with the 2014-08-03 nightly as I was waiting for a confirmation (along the lines of 'This has been fixed in SGWT 5.0d and 4.1p; check the next nightly builds. ') that the fix was included as part of the latest nightly.

                  Frederic
                  Last edited by fkamthong; 6 Aug 2014, 08:02. Reason: fixed typos

                  Comment


                    #10
                    Originally posted by fkamthong View Post
                    Sorry, I should have been more specific. This behavior was last observed with the 2014-08-03 nightly as I was waiting for a confirmation (along the lines of 'This has been fixed in SGWT 5.0d and 4.1p; check the next nightly builds. ') that the fix was included as part of the latest nightly.

                    Frederic
                    That's what this was:
                    We see this and it will be resolved by tonight's nightly builds. It was a result of the recent restructuring of the setAttribute() APIs in DataClass.java and FormItem.java.

                    Comment


                      #11
                      Originally posted by fkamthong View Post
                      What is the expected/official behavior when the attribute was never set?
                      Sorry, we misstated the earlier answer. What we meant was that developers need the ability to detect null. The current behavior of getAttributeAsBoolean() - converting null to false - is actually the most convenient behavior for checking boolean fields, since most boolean fields treat null the same as false.

                      To detect null when null should be treated differently from false, you can use getAttributeAsObject(). In versions from 9.1 onward, we will also add a second convenience method which returns Boolean, but will not convert null to false, returning null directly instead.

                      Comment


                        #12
                        Just to be clear...

                        Originally posted by Isomorphic View Post
                        Grabbing a random unset property of a Record as a Boolean should return null. There was a bug (reported by another customer) whereby the logic was flowing through a boolean, which caused it to be converted to false.
                        The following seems to indicate that the recent change alluded above will be reversed since both getAttributeAsObject() and getAttributeAsBoolean() currently (with the 2014-08-06 build) return null if the attribute was never set.

                        Originally posted by Isomorphic View Post
                        Sorry, we misstated the earlier answer. What we meant was that developers need the ability to detect null. The current behavior of getAttributeAsBoolean() - converting null to false - is actually the most convenient behavior for checking boolean fields, since most boolean fields treat null the same as false.

                        To detect null when null should be treated differently from false, you can use getAttributeAsObject(). In versions from 9.1 onward, we will also add a second convenience method which returns Boolean, but will not convert null to false, returning null directly instead.
                        Should we be expecting the getAttributeAsBoolean() method to treat null values as FALSE in the future builds?

                        Thanks,

                        Frederic

                        Comment


                          #13
                          Yes, Record.getAttributeAsBoolean() will resume returning false for unset values in the next nightlies.

                          Comment


                            #14
                            Thank you for the clarification.

                            Originally posted by Isomorphic View Post
                            Yes, Record.getAttributeAsBoolean() will resume returning false for unset values in the next nightlies.

                            Comment

                            Working...
                            X