Announcement

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

    #16
    Originally posted by Isomorphic
    2) not true, the DataArrived event gives you access to what has been loaded

    1) use DataSource.fetchData() to retrieve a single record by passing the ID of the record as the only criteria (if it's not already loaded).
    Is there a full example on how this might be implemented? I've tried the following without success (the "key" field is displayed instead of "nickName"):

    Code:
        carDriverComboBox.setOptionDataSource(carDriverDS);
        carDriverComboBox.setValueField("key");
        carDriverComboBox.addDataArrivedHandler(new DataArrivedHandler() {
          
          @Override
          public void onDataArrived(DataArrivedEvent event) {
            ResultSet resultSet = event.getData();
            carDriverComboBox.setValueMap(new LinkedHashMap(resultSet.getValueMap("key", "nickName")));
          }
        });
    
        DataSourceTextField carDriver = new DataSourceTextField("carDriver", "Driver");
        carDriver.setEditorType(carDriverComboBox);
    
        myTripDataSource.addField(carDriver);
    Also, what's the difference between carDriverComboBox.setPickListProperties() and carDriverComboBox.setOptionDataSource() ? How should I use them?

    Comment


      #17
      Hi,

      optionalDataSource is a source for data whereas pickListProperties tells how to present them in the pick list.

      ValueFormatter cannot be used on its own since it has no access to related records from optionalDataSource. (Appart from selected record). You need to use pick list in order to format the rest of records fetched from optionalDataSource.

      I've got a working solution.

      Code:
      regionalManagerItem = new SelectItem("regionalManagerId", i18nConstants.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager());
      regionalManagerItem.setWidth(300);
      regionalManagerItem.setOptionDataSource(employeesDS);
      regionalManagerItem.setValueField("employeeId");
      ListGridField fullName = new ListGridField("fullName");
      fullName.setCellFormatter(new CellFormatter() {  
      	public String format(Object value, ListGridRecord record, int rowNum, int colNum) {  
      		String surname = record.getAttribute("surname");
      		String middleName = record.getAttribute("middleName");
      		String firstName = record.getAttribute("firstName");
      		if (middleName == null) {
      			return i18nMessages.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager_displayName(firstName, surname);
      		} else {
      			return i18nMessages.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager_displayFullName(firstName, middleName, surname);
      		}
      	}  
      });
      regionalManagerItem.setPickListFields(fullName);
      regionalManagerItem.setValueFormatter(new FormItemValueFormatter() {
      	@Override
      	public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
      		ListGridRecord selectedRecord = regionalManagerItem.getSelectedRecord();
      		if (selectedRecord != null) {
      			String surname = selectedRecord.getAttribute("surname");
      			String middleName = selectedRecord.getAttribute("middleName");
      			String firstName = selectedRecord.getAttribute("firstName");
      			if (middleName == null) {
      				return i18nMessages.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager_displayName(firstName, surname);
      			} else {
      				return i18nMessages.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager_displayFullName(firstName, middleName, surname);
      			}
      		}
      		return value.toString();
      	}
      });
      Cheers,
      Martin

      Comment


        #18
        Hi zdary,

        Specifying both CellFormatter (for selected record) and ValueFormatter (for the rest of records) allowed displaying the derived "fullName" attribute. However, I've noticed that once the item is selected, the SelectItem is filled with the "employeeId" instead of the "fullName". Are you seeing the same issue?

        Regards,

        Cheng

        Comment


          #19
          Hi Cheng,

          I had the same problem when I used ComboBoxItem but when I switched to SelectItem the problem went away.

          Try to put System.out.println() and find out where it goes wrong. Does the ValueFormatter get called? Do you get the attributes from a record? Is there any exception?

          Zdary

          PS: It's the other way round. ValueFormatter is for the selected record and CellFormatter is for the rest of records.

          Comment


            #20
            Just tried with SelecItem but there I hit the getSelectedRecord() is not a function problem I was facing a few days ago because I'm using SmartGWT 2.4 LGPL version. I'll try to get the latest LPGL snapshot and see if it's fixed already.

            Comment


              #21
              yes,

              you need to use the latest night build in order to make it work http://www.smartclient.com/builds/SmartGWT/2.x/EnterpriseEval/2011-04-27

              Even in the latest night build (2011-04-27) the ComboBoxItem is still broken and doesn't call ValueFormatter. That is way you need to use a SelectItem.

              Cheers,
              Zdary

              Comment


                #22
                SmartGWT 2.5 / Google Chrome

                Just wanting to share what I figured out after a long long struggle :
                this is a adapted version of [http://www.smartclient.com/smartgwt/showcase/#styled_combobox_category] using value/display fields for the styled ComboBox.
                For that purpose we need to use comboBoxItem.setValueField and comboBoxItem.setDisplayField.
                But changing only that in Isomorphic showcase is not working, because setCellFormatter is
                set for the ListGrid, and is obviously overriden by setDisplayField, thus not showing the styled cell anymore.
                The trick is to use comboBoxItem.setPickListFields (styledCell)

                Code:
                final DynamicForm form = new DynamicForm();  
                form.setWidth(250); 
                ComboBoxItem comboBoxItem = new ComboBoxItem("itemName", "Custom");  
                comboBoxItem.setOptionDataSource(ItemSupplyXmlDS.getInstance());  
                comboBoxItem.setWidth(260);
                // ---> add a ListGridField
                ListGridField styledCell = new ListGridField("styledCell");
                ListGrid pickListProperties = new ListGrid();  
                pickListProperties.setCellHeight(50);  
                pickListProperties.setCanHover(true);  
                pickListProperties.setShowHover(true);
                // ---> setCellFormatter on ListGridField instead of ListGrid
                styledCell.setCellFormatter(new CellFormatter() {  
                           
                	@Override
                	public String format(Object value, ListGridRecord record,
                					int rowNum, int colNum) {
                		String descStr = record.getAttribute("description");  
                                if (descStr == null) descStr = "[no description]";  
                  
                                String itemName = record.getAttribute("itemName");  
                                String unitCost = record.getAttribute("unitCost");  
                  
                                String styleStr = "font-family:arial;font-size:11px;white-space:nowrap;overflow:hidden;";  
                                String retStr = "<table>" +  
                                        "<tr><td ><span style='" + styleStr + "width:170px;float:left'>" + itemName + "<span></td>" +  
                                        "<td align='right'><span style='" + styleStr + "width:50px;float:right;font-weight:bold'>" + unitCost + "<span></td></tr>" +  
                                        "<tr><td colSpan=2><span style='" + styleStr + "width:220px;float:left'>" + descStr + "</span></td></tr></table>";  
                                return retStr;  
                	}  
                });  
                styledCell.setHoverCustomizer(new HoverCustomizer() {  
                        @Override  
                        public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {  
                                String descStr = record.getAttribute("description");  
                                if (descStr == null) descStr = "[no description]";  
                                return descStr;  
                        }  
                });  
                
                // --> most important part here : set the value field, the display field, and the styled ListGridField to display on picklist       
                comboBoxItem.setValueField("SKU");
                comboBoxItem.setDisplayField("itemName");
                comboBoxItem.setPickListFields(styledCell);
                comboBoxItem.setPickListProperties(pickListProperties);  
                // ---> just to check the real value
                comboBoxItem.addChangedHandler(new ChangedHandler() {
                			
                	@Override
                	public void onChanged(ChangedEvent event) {
                		SC.logWarn("Value changed =" + event.getValue());
                	}
                });
                        
                form.setFields(comboBoxItem);
                form.draw()

                Comment


                  #23
                  I am using SNAPSHOT_v9.0d_2013-06-09 and it still appears that the ComboBoxItem value formatter is never called. If I create the exact same FormItemValueFormatter for a SelectItem, it gets called but on a ComboBoxItem it never gets called.

                  Any advice?

                  Comment

                  Working...
                  X