Announcement

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

    SelectItem displays the 1st item only out of 4?

    We are on a nightly build dated 12-7-2010 and we're seeing some strange behavior with SelectItem:

    Code:
    Criteria c = new Criteria();
            c.setAttribute("ClientId", Long.toString(getUser().getId()));
            timeFrameSelectItem = new SelectItem("postTradeTimeFrame", "Time Frame");
            timeFrameSelectItem.setOptionDataSource(DataSource.get("post-trade-time-frame"));
            timeFrameSelectItem.setValueField("id");
            timeFrameSelectItem.setOptionCriteria(c);
            timeFrameSelectItem.setAutoFetchData(Boolean.TRUE);
            timeFrameSelectItem.setDefaultToFirstOption(true);
            
            timeFrameSelectItem.setWidth(200);
    
    
            timeFrameSelectItem.addFocusHandler(new FocusHandler(){
                public void onFocus(FocusEvent event) {
                    ListGridRecord record = timeFrameSelectItem.getSelectedRecord();
                    if(record != null && !record.getAttribute("name").startsWith("Custom")) {
                        timeFrameStartDate = record.getAttributeAsDate("startPoint");
                        timeFrameEndDate = record.getAttributeAsDate("endPoint");
                    }
                }
            });
    
    
            timeFrameSelectItem.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event){
    logAtClient("onClicked timeFrameSelect");
                    ListGridRecord record = timeFrameSelectItem.getSelectedRecord();
                    if(record != null) {
                        String name = record.getAttributeAsString("name");
                        if(name.startsWith("Custom Dates")){
                            timeFrameSelectItem.clearValue();
                        }
                    }
                }
            });
    
            timeFrameSelectItem.addChangedHandler(new ChangedHandler() {
                public void onChanged(ChangedEvent event) {
                    if(benchmarksWindow != null) benchmarksWindow.close();
                    ListGridRecord record = timeFrameSelectItem.getSelectedRecord();
                    if(record != null) {
                        String name = record.getAttributeAsString("name");
                        if(name.startsWith("Custom Dates")){
                            //parse the custom dates and prime the popup dates
                            if(name.contains("(")) {
                                int first = name.lastIndexOf("(");
                                int last  = name.lastIndexOf(")");
                                String dateString = name.substring(first + 1, last);
                                String[] dates = dateString.split(" - ");
                                DateTimeFormat sdf = DateTimeFormat.getFormat("MM/dd/yy");
                                timeFrameStartDate = sdf.parse(dates[0]);
                                timeFrameEndDate = sdf.parse(dates[1]);
                            }
                            createCustomTimeFrameWindow();
                        }
                        else {
                            PostTradeCubeDimensionView postTradeCubeDimensionView = (PostTradeCubeDimensionView)baseCubeDimensionView;
                            postTradeCubeDimensionView.setStartDate(record.getAttributeAsDate("startPoint"));
                            postTradeCubeDimensionView.setEndDate(record.getAttributeAsDate("endPoint"));
                            postTradeCubeDimensionView.refreshAllDimensions();
    
                        }
                    }
                }
            });
    Almost every other time we create this instance only the first (out of 4 options) are displayed in the pick list. In other words, every other instance that is created will display the 4 intended available options. Some do, and some don't (only displaying the first out of four options).

    Is this a defect related to a nightly build? Has anyone seen this behavior before? This code was working consistently before we upgraded SmartGWT versions.

    #2
    I think I found the culprit:

    Code:
    timeFrameSelectItem.setValue(cubeMeta.getTimeFrameId());
    When I comment out the code above, all 4 options now appear in the pick list consistently. Strange how setting the value would cause other items in the pick list to disappear?

    Comment


      #3
      This certainly isn't a known problem and it's difficult to image a mechanism that could cause it. But then, there's lots of other stuff going on in your code sample, and we can't run it.

      We'd first of all suggest upgrading to a recent nightly (tonight's is a release candidate) and seeing if you get the issue there. Then, if you do, narrow it down to a runnable test case so we can take a look.

      Comment


        #4
        Agreed. Good luck with your new release!

        Comment


          #5
          I've upgraded to the nightly dated 2011-01-06 and I'm still seeing this issue?

          Comment


            #6
            OK, then please narrow this down to a minimal, runnable test case so that we can see the issue.

            Comment


              #7
              I have been trying to reproduce this issue in a stand alone test case, but I'm not having much luck doing so. Upon further debugging, I am seeing some strange behavior:

              Code:
              timeFrameSelectItem.addFocusHandler(new FocusHandler(){
                          public void onFocus(FocusEvent event) {
              logAtClient("==>onFocus fired. count:" + timeFrameSelectItem.getClientPickListData().length);
                              ListGridRecord record = timeFrameSelectItem.getSelectedRecord();
                              if(record != null && !record.getAttribute("name").startsWith("Custom")) {
                                  timeFrameStartDate = record.getAttributeAsDate("startPoint");
                                  timeFrameEndDate = record.getAttributeAsDate("endPoint");
                              }
                          }
                      });
              When there is only 1 item in the picklist, the log statement shows count=4, and when there are 4 items in the picklist (what we expect) the count=1. The picklist seems to work every-other-time we use it, the first time we instantiate it, there is only 1 item in the picklist, the 2nd time we instantiate it, there are 4. It goes back and forth pretty consistently.

              Any thoughts?

              Comment


                #8
                OK, I realized I left out 1 important line of code from the first posting, so I will repost the entire code involved and explain some further observations:
                Code:
                private SelectItem timeFrameSelectItem = null;
                     private Date timeFrameStartDate = null;
                     private Date timeFrameEndDate = null;
                    @Override protected Layout createHeaderFormPanel() {
                        timeFrameSelectItem = new SelectItem("postTradeTimeFrame", "Time Frame");
                        timeFrameSelectItem.setOptionDataSource(DataSource.get("post-trade-time-frame"));
                        timeFrameSelectItem.setOptionCriteria(new Criteria("ClientId", Long.toString(getUser().getId())));
                        timeFrameSelectItem.setAutoFetchData(Boolean.TRUE);
                        timeFrameSelectItem.setWidth(200);
                
                
                        timeFrameSelectItem.addFocusHandler(new FocusHandler(){
                            public void onFocus(FocusEvent event) {
                logAtClient("==>onFocus fired. count:" + timeFrameSelectItem.getClientPickListData().length);
                                ListGridRecord record = timeFrameSelectItem.getSelectedRecord();
                                if(record != null && !record.getAttribute("name").startsWith("Custom")) {
                                    timeFrameStartDate = record.getAttributeAsDate("startPoint");
                                    timeFrameEndDate = record.getAttributeAsDate("endPoint");
                                }
                            }
                        });
                
                
                        //cliu 6-2-2010  bug no. 363
                        timeFrameSelectItem.addClickHandler(new ClickHandler() {
                            public void onClick(ClickEvent event){
                logAtClient("==>onClicked fired.");
                                ListGridRecord record = timeFrameSelectItem.getSelectedRecord();
                                if(record != null) {
                                    String name = record.getAttributeAsString("name");
                                    if(name.startsWith("Custom Dates")){
                                        timeFrameSelectItem.clearValue();
                                    }
                                }
                            }
                        });
                
                        timeFrameSelectItem.addChangedHandler(new ChangedHandler() {
                            public void onChanged(ChangedEvent event) {
                logAtClient("==>onChanged fired.");
                                if(benchmarksWindow != null) benchmarksWindow.close();
                                ListGridRecord record = timeFrameSelectItem.getSelectedRecord();
                                if(record != null) {
                                    String name = record.getAttributeAsString("name");
                                    if(name.startsWith("Custom Dates")){
                                        //parse the custom dates and prime the popup dates
                                        if(name.contains("(")) {
                                            int first = name.lastIndexOf("(");
                                            int last  = name.lastIndexOf(")");
                                            String dateString = name.substring(first + 1, last);
                                            String[] dates = dateString.split(" - ");
                                            DateTimeFormat sdf = DateTimeFormat.getFormat("MM/dd/yy");
                                            timeFrameStartDate = sdf.parse(dates[0]);
                                            timeFrameEndDate = sdf.parse(dates[1]);
                                        }
                                        createCustomTimeFrameWindow();
                                    }
                                    else {
                                        PostTradeCubeDimensionView postTradeCubeDimensionView = (PostTradeCubeDimensionView)baseCubeDimensionView;
                                        postTradeCubeDimensionView.setStartDate(record.getAttributeAsDate("startPoint"));
                                        postTradeCubeDimensionView.setEndDate(record.getAttributeAsDate("endPoint"));
                                        postTradeCubeDimensionView.refreshAllDimensions();
                //                        refreshDimensionFilterValues(getDimensionFilterValue());
                //                        fetchCubeData(postTradeCubeDimensionView.getCriteria());
                                    }
                                }
                            }
                        });
                        timeFrameSelectItem.setValueField("id");
                        timeFrameSelectItem.setDisplayField("name");
                        timeFrameSelectItem.setDefaultToFirstOption(Boolean.TRUE);
                        
                        if(cubeMeta.getTimeFrameId() > 0) {
                            timeFrameSelectItem.setValue((int)cubeMeta.getTimeFrameId());
                        }
                The code above has 2 calls that alter the problematic behavior:
                Code:
                timeFrameSelectItem.setValue((int)cubeMeta.getTimeFrameId());
                Code:
                timeFrameSelectItem.setDefaultToFirstOption(Boolean.TRUE);
                When I take out the SelectItem.setValue() call, the SelectItem will render the 4 pick list items correctly. When I put the setValue call back, we get back to the back and forth behavior of rending 1 or 4 items in the pick list, with the count debug statement showing 1 for 4 items in pick list and 4 for 1 item in pick list.

                When I take the setDefaultToFirstOption out, the 4 items render correctly consistently.

                Comment


                  #9
                  Unfortunately, without runnable code where we can see all the fetches happening in the DataSource layer and the returned data, we can really only speculate; if you can isolate this as a test case we can give a definitive answer.

                  All we can suggest for now is that using the DataArrived event's access to the ResultSet is a more definitive way of seeing what the available data is. getClientPickListData() is more of an override point.

                  Comment

                  Working...
                  X