Announcement

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

    FormItem is not visible in the DynamicForm

    The FormItem is not visible in the SmartClient Version: v10.1p_2016-06-16/PowerEdition Deployment (built 2016-06-16) , but works just fine in the version 5.0.
    Code:
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.RecordList;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.HiddenItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    
    import java.util.LinkedHashMap;
    
    import com.smartgwt.client.data.DSCallback;
    import com.smartgwt.client.data.DSRequest;
    import com.smartgwt.client.data.DSResponse;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.RecordList;
    import com.smartgwt.client.rpc.RPCResponse;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    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.HiddenItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.layout.HLayout;
    
    public class NotificationWindow  extends Window{
        final private static int WINDOW_WIDTH = 450;
        final private static int WINDOW_HEIGHT = 200;
        final private static int NUM_COLUMNS = 2;
        final private static int COLUMN_WIDTH = 200;
        final private static int PADDING = 10;
    
    
        final private IButton cancelButton = new IButton( "cancel" );
        
        final private DynamicForm form = new DynamicForm();
        private SelectItem typeField; // global to allow hide/show/disable throughout code
        private final HiddenItem hiddenTypeItem = new HiddenItem( "alert_policy_type_id" );
        
        private RecordList recordList;
    
        /**
         * If non-null, contains an existing notification policy record that is to be used as a base for cloning into the
         * new record being created.
         */
        private Record cloneRecord = null;
    
        public NotificationWindow() {
    
            super();
        }
        
    
        /**
         * Instantiates a new notification window. This constructor is used for cloning and existing record.
         *
         * [USER="45788"]param[/USER] cloneRecord the clone record
         */
        public NotificationWindow( final Record cloneRecord ) {
    
            super();
            this.cloneRecord = cloneRecord;
        }
    
    
        public void doCreate(  final RecordList recordList ) {
    
    
            this.initLayout( recordList );
    
            this.show(); // [**ERROR**]
        }
    
        private void initLayout( final RecordList recordList ) {
    
            this.recordList = recordList;
    
            this.setIsModal( true );
            this.setShowModalMask( true );
            this.setWidth( NotificationWindow.WINDOW_WIDTH );
            this.setHeight( NotificationWindow.WINDOW_HEIGHT );
            this.setShowMinimizeButton( false );
            this.setShowMaximizeButton( false );
            this.setShowCloseButton( false );
            this.setDismissOnEscape( false );
    
            this.addItem( this.getForm() );
            this.addItem( this.getButtons() );
            this.centerInPage();
    
            this.form.clearValues();
            this.setTitle( "TITLE" );
            this.setKeepInParentRect( true );
            this.form.editNewRecord();
    
            if ( this.cloneRecord != null ) {
                this.typeField.setValue( this.cloneRecord.getAttribute( "alert_policy_type_id" ) );
                this.typeField.setDisabled( true );
    
            } else {
                this.typeField.setDisabled( false );
    
            }
        }
    
        private Canvas getButtons() {
        
    
            this.cancelButton.addClickHandler( new ClickHandler() {
    
                @Override
                public void onClick( final ClickEvent event ) {
    
                    NotificationWindow.this.returnAndClose( null );
                }
            } );
    
            final HLayout l = new HLayout();
            l.setLayoutAlign( Alignment.CENTER );
            l.setLayoutMargin( NotificationWindow.PADDING );
            l.setMembersMargin( NotificationWindow.PADDING );
            l.setAlign( Alignment.CENTER );
            l.setWidth100();
            l.setHeight( "20%" );
    
            final Canvas spacer = new Canvas();
            spacer.setWidth100();
            l.addMember( this.cancelButton );
    
            return l;
        }
    
        private void returnAndClose( final Record record ) {
    
            NotificationWindow.this.hide();
    
            NotificationWindow.this.markForDestroy();
        }
    
        private final FormItem name = new FormItem( "alert_policy_name" );
    
        private DynamicForm getForm() {
    
            //this.form.setDataSource( this.dsPolicySummary );
    
            this.form.setCellPadding( NotificationWindow.PADDING );
            this.form.setWrapItemTitles( false );
            this.form.setWidth( "*" );
            this.form.setNumCols( NotificationWindow.NUM_COLUMNS );
            this.form.setHeight( "80%" );
    
            final FormItem id = new FormItem( "alert_policy_id" );
    
            this.name.setWidth( NotificationWindow.COLUMN_WIDTH );
            this.name.setRequired( true );
            this.name.setTitle( "policy_name" );
            //this.name.setValidators( new UniqueValidator( new ValidationInfo( this.recordList, null, null ) ), new RequiredValidator() );
    
            this.typeField = new SelectItem( "temp_type_id" );
            this.typeField.setWidth( NotificationWindow.COLUMN_WIDTH );
            this.typeField.setRequired( true );
            this.typeField.setTitle( "alert_viewPolicySummary_title_alert_type_description" );
            LinkedHashMap< Integer, String > map = new LinkedHashMap< Integer, String >();
            map.put( 1, "describePolicyType1" );
            map.put( 2, "describePolicyType2" );
            this.typeField.setValueMap( map );
    
        
    
            this.form.setFields( id, this.name, this.typeField, this.hiddenTypeItem );
            
    
            id.setVisible( false );
    
            return this.form;
        }
    
    }
    The private
    Code:
     final FormItem name = new FormItem( "alert_policy_name" );
    is not visible, but if I change it to
    Code:
     final FormItem name = new TextItem( "alert_policy_name" );
    it works just fine and the item is visible.

    to call the window just call it this way:
    Code:
     final DynamicForm form = new DynamicForm();
            
      
            
                     final IButton button = new IButton("Hello");
            
                      
            
                     button.addClickHandler(new ClickHandler() {
    
                        @Override
                        public void onClick(ClickEvent event) {
          
                            final NotificationWindow notifWindow = new NotificationWindow();
                            notifWindow.doCreate(null);
                            
                        }
            
                     });
    The problem is the SmartGWT/5.1p/PowerEdition , but works just fine in the 5.0p.
    Last edited by aafros; 20 Jun 2016, 11:21.

    #2
    Please remember to always post your full version (not just 5.1) - full datestamp). If you have not already tested with the latest patched version, please do so now.

    Also, please clarify what you mean by "not visible" - smaller than expected? Totally absent? A screenshot would help clarify.

    Also, please indicate what skin you are using, and if you have customized your skin, please indicate whether you can reproduce the same problem using one of the skins that ships with SmartGWT, with no modifications.

    Comment


      #3
      I did provide the full time step of the version in first line of my previous message. The time step is: SmartClient Version: v10.1p_2016-06-16/PowerEdition Deployment (built 2016-06-16).
      I tested it on FireFox 24.8.1, Google Chrome 52.0.2743.41 and IE 11.0.9600.18350 all of them do not display the
      Code:
      private final FormItem name = new FormItem( "alert_policy_name" );
      at all.
      I did not do any modifications to the skin.
      Please see the attached image.
      Attached Files
      Last edited by aafros; 20 Jun 2016, 05:38.

      Comment


        #4
        We've made a fix to address this problem in SGWT 5.1p - it will be the nightly builds dated 2016-06-21 and beyond.

        However, note that if you ever use this.name again after the DynamicForm is created, you'll potentially be in a situation where you're not using the current SGWT wrapper for the underlying SC item instance. This is because that item ultimately ends up as a TextItem, and any handlers that are called will therefore return an actual SmartGWT TextItem wrapper.

        For this reason, you should not store the reference to the baseclass (FormItem) wrapper in a member variable. You can either use the correct constructor class (TextItem), or restrict the FormItem to a stack variable inside your getForm() method. More recent versions of SmartGWT will actually warn you about this situation.

        We haven't made any change that actually intentionally breaks anything in this situation, but the fact that you can end up with a wrapper that's not referenced by the underlying SC item instance (because it references the more recently created SGWT wrapper with the correct TextItem class) can lead to problems and is therefore not a supported use case.

        Comment


          #5
          Thank you. I tested the build 2016-06-21. Works as expected. The field is displayed. The issue is fixed.
          Thanks for your help and co-operation.
          Last edited by aafros; 21 Jun 2016, 06:57.

          Comment

          Working...
          X