Announcement

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

    Strange behaviour of ListGrid.setFieldState(fieldState)

    Hi,
    I'm using the ListGrid.setFieldState(fieldState) method to load the field state before the listgrid has been drawn. It does its job but the optiondatasources are not loaded as well. I first noticed this because some fields have a display value. If I comment the setFieldState the optionDataSources are loaded again and the fields with optiondatasource have their display values working again.

    This problem seems to appear only when I do the setFieldState before the listgrid has been drawn.

    It looks like a small bug.

    Thank you very much for you help.

    #2
    This could have a number of causes so it's not clear yet if it's a bug. Can you make this happen in any of the samples by making some small changes?

    Comment


      #3
      Here is what I'm currently doing.
      This is my ListGrid subclass, I'm adding a method to setup the default layout (persisted on DB).

      Code:
      public class StandardListGrid extends ListGrid{
      	private String panelID;
      
      
      	public StandardListGrid(String panelID){
      		super();
      		this.panelID=panelID;
      		this.setCanAddFormulaFields(true);
      		this.setCanAddSummaryFields(true);
      
      		final StandardListGrid me=this;
      }
      
      	public  void loadDefaultState(){
      		String fieldState=Privileges.getControlLayout(panelID);
      		String fieldhilite=Privileges.getControlHilite(panelID);
      		if(fieldState!=null)if(!fieldState.equalsIgnoreCase(""))this.setFieldState(fieldState);
      		if(fieldhilite!=null)if(!fieldhilite.equalsIgnoreCase(""))this.setHiliteState(fieldhilite);
      		this.markForRedraw();
      	}
      }
      And here is the code of the main application.

      Code:
      	mainGrid.setDataSource(pmptinstreq);
      		mainGrid.setShowDetailFields(true);
      		mainGrid.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
      		mainGrid.setShowFilterEditor(true);
      		mainGrid.setDataPageSize(40);
      		mainGrid.setModalEditing(true);
      		mainGrid.setFilterOnKeypress(false);
      		mainGrid.setListEndEditAction(RowEndEditAction.NEXT);
      		mainGrid.setAutoSaveEdits(true);
      		mainGrid.setAutoFetchData(true);
      		mainGrid.setEditEvent(ListGridEditEvent.NONE);
      		SelectItem standardSelectItem = new SelectItem();
      		standardSelectItem.setAllowEmptyValue(true);
      
      		Criteria crit = new Criteria();
      		crit.addCriteria("STATUS", "E");
      		mainGrid.setInitialCriteria(crit);
      
      		ListGridField instridField = new ListGridField("INSTRID");
      		ListGridField instrnameField = new ListGridField("INSTRNAME");
      		instrnameField.setOptionDataSource(pmptinstreq);
      		instrnameField.setFilterOperator(OperatorId.ICONTAINS);
      		ListGridField classcodeField = new ListGridField("CLASSCODE");
              classcodeField.setFilterOperator(OperatorId.IEQUALS);
      		ListGridField riccodeField = new ListGridField("RICCODE");
      		ListGridField isincodeField = new ListGridField("ISINCODE");
      		ListGridField bloombField = new ListGridField("BLOOMBCODE");
      		ListGridField marketcodeField = new ListGridField("MARKETCODE");
      		ListGridField currField = new ListGridField("CURRENCY");
      		ListGridField listnameField = new ListGridField("LISTNAME");
      		ListGridField instrtypeField = new ListGridField("INSTRTYPE");
      		ListGridField instrStypeField = new ListGridField("INSTRSTYPE");
      		ListGridField sgmcodeField = new ListGridField("SGMCODE");
      		ListGridField diviscodeField = new ListGridField("DIVISCODE");
      		ListGridField supersectField = new ListGridField("SUPERSECT");
      		ListGridField industryField = new ListGridField("INDUSTRY");
      		ListGridField rccodeField = new ListGridField("RCCODE");
      		rccodeField.setOptionDataSource(pmptrc);
      		rccodeField.setDisplayField("RCDESC");
      		rccodeField.setFilterEditorProperties(standardSelectItem);
      		ListGridField comparableField = new ListGridField("COMPARABLE");
      		ListGridField issuerField = new ListGridField("ISSUER");
      		ListGridField divtypeField = new ListGridField("DIVTYPE");
      		ListGridField addrstreetField = new ListGridField("ADDRSTREET");
      		ListGridField addrcityField = new ListGridField("ADDRCITY");
      		ListGridField addrdistField = new ListGridField("ADDRDIST");
      		ListGridField addrrpcField = new ListGridField("ADDRPC");
      		ListGridField addrstateField = new ListGridField("ADDRSTATE");
      		ListGridField addrcountField = new ListGridField("ADDRCOUNT");
      		ListGridField addrwebField = new ListGridField("ADDRWEB");
      		ListGridField histvolaField = new ListGridField("HISTVOLAID");
      		histvolaField.setOptionDataSource(pmptinstr_ed);
      		histvolaField.setDisplayField("INSTRNAME");
      		histvolaField.setFilterEditorProperties(standardSelectItem);
      		ListGridField statusField = new ListGridField("STATUS");
      		ListGridField delistdateField = new ListGridField("DELISTDATE");
      		ListGridField mktlistdateField = new ListGridField("MKTLSTDATE");
      		ListGridField ccplistdateField = new ListGridField("CCPLSTDATE");
      		ListGridField delistreasField = new ListGridField("DELISTREAS");
      		ListGridField deldaysField = new ListGridField("DELDAYS");
      		ListGridField disabreasField = new ListGridField("DISABREAS");
      		ListGridField marginthField = new ListGridField("MARGINTH");
      		ListGridField upddateField = new ListGridField("UPDDATE");
      		ListGridField updusrField = new ListGridField("UPDUSR");
      		ListGridField updtypeField = new ListGridField("UPDTYPE");
      		ListGridField noteField = new ListGridField("NOTE");
      		ListGridField formatField = new ListGridField("FORMAT");
      		ListGridField bmknameField = new ListGridField("BMKNAME");
      		ListGridField bmkricField = new ListGridField("BMKRIC");
      		ListGridField bmkretField = new ListGridField("BMKRETURN");
      		ListGridField bmkstyField = new ListGridField("BMKSTYLE");
      		ListGridField bmkareaField = new ListGridField("BMKAREA");
      		ListGridField bmkdescField = new ListGridField("BMKDESCR");
      		ListGridField bmkcompField = new ListGridField("BMKCOMP");
      		ListGridField bmkspecField = new ListGridField("BMKSPEC");
      		ListGridField bmkcurrField = new ListGridField("BMKCURR");
      		ListGridField bmkninstrField = new ListGridField("BMKNINSTR");
      		ListGridField composField = new ListGridField("COMPOS");
      		
      		marketcodeField.setOptionDataSource(pmptmarket);
      		instrtypeField.setOptionDataSource(pmpttyp);
      		instrStypeField.setOptionDataSource(pmptsubtyp);
      		sgmcodeField.setOptionDataSource(pmptsegm);
      
      		instrtypeField.setDisplayField("TYPEDESC");
      		instrStypeField.setDisplayField("STYPEDESC");
      
      		marginthField.setCellFormatter(new CellFormatter() {
      			public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
      				if (value == null)
      					return null;
      
      				String val = null;
      				try {
      					NumberFormat nf = NumberFormat.getFormat("0.00");
      					val = nf.format(((Number) value).doubleValue());
      				} catch (Exception e) {
      					return value.toString();
      				}
      				return val + "%";
      			}
      		});
      		
      		mainGrid.setFields(instridField, instrnameField, classcodeField, riccodeField, isincodeField, bloombField, marketcodeField, currField,
      				listnameField, instrtypeField, instrStypeField, sgmcodeField, diviscodeField, supersectField, industryField,
      				rccodeField,comparableField,issuerField,
      				divtypeField, addrstreetField, addrcityField, addrdistField, addrrpcField, addrstateField, addrcountField, addrwebField,
      			    histvolaField, statusField, delistdateField, mktlistdateField, ccplistdateField, delistreasField, deldaysField,
      				disabreasField, marginthField,bmknameField,bmkricField,bmkretField,bmkstyField,bmkareaField,bmkdescField,bmkcompField,bmkspecField,
      				bmkcurrField,bmkninstrField,composField,upddateField, updusrField, updtypeField, noteField, formatField);
      
      		workingArea.addMember(mainGrid);
      		mainGrid.setContextMenu(createContextMenu(mainTabSet));
      		mainGrid.markForRedraw();
      
      		//Calling the method
      		mainGrid.setDefaultState();
      Well, if I launch the last method the layout is correctly loaded but the fields with OptionDataSource diplay the value field.

      If call the same method in a click event, after the table has been drawn the first time, it works correctly.

      Comment


        #4
        To really find the cause here, we'd need to be able to see all the fetches involved with the optionDataSources and many other things. So, two approaches:

        1. put together a test case that we can actually run in order to be able to see the problem. The best way to do this is usually to modify an existing sample to see if you can reproduce the problem

        2. just use the approach that you've already discovered fixes the problem in your application - don't call setFieldState until after draw.

        Comment


          #5
          We found the same problem with the grid.setViewState and its option datasources.
          We use: smartgwtpower-3.0p.2012-05-02

          Comment


            #6
            We're in the same position of needing to be able to reproduce the problem. If you have a test case, please share.

            Comment

            Working...
            X