Announcement

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

  • learn_smartgwt
    replied
    Thanks you.

    Leave a comment:


  • smartgwt.dev
    replied
    Since there's no real "this" or "super" when it comes to setting the editor "type" to a FormItem instance that really represents the editor "properties", overriding of the getPickListFilterCriteria() method of ComboBoxItem is not applicable. Instead to accomplish this you need to use the alternate ComboBoxItem / SelectItem .setPickListFilterCriteriaFunction(..) API's on the editorType instance.

    The Grid Dependent Selects showcase sample has an example usage of this : http://www.smartclient.com/smartgwt/...t_selects_grid

    Leave a comment:


  • learn_smartgwt
    replied
    Hey! I understood about the behaviour of listgrid. We don't override the Editor Type directly but we override the ListGrid fiels which may contain it's own editor type. Below is the test code and editor is showing up but again problem is getPickListFilterCriteria() is not being invoked? Am i missing something here?

    ArrayList<ListGridField> overriddenListGridFields = new ArrayList<ListGridField>();
    for(DataSourceField dataSourceField : listGrid.getDataSource().getFields()) {
    String foreignKey = dataSourceField.getAttribute("foreignKey");
    if(foreignKey != null){
    ListGridField listGridField = new ListGridField(dataSourceField.getName());
    final ComboBoxItem employeeComboBoxItem = new ComboBoxItem(){
    @Override protected Criteria getPickListFilterCriteria() {
    GWT.log("Called getPickListFilterCriteria()");
    return super.getPickListFilterCriteria();
    }
    };
    employeeComboBoxItem.setPickListFields(getPickListFields());
    listGridField.setEditorType(employeeComboBoxItem);
    overriddenListGridFields.add(listGridField);
    }
    }
    ListGridField[] overriddenListGridFieldArr = new ListGridField[overriddenListGridFields.size()];
    listGrid.setFields(overriddenListGridFields.toArray(overriddenListGridFieldArr));

    Leave a comment:


  • learn_smartgwt
    replied
    Hi,

    Just to continue on same example - I tried to use same combo box in a same fashion with list grid cell editor but unfortunetly it doesn't call getPickListFilterCriteria() method? Is there any trick here too?
    Also unlike forms listGrid.getFields is empty in data bound grid. Although again fields are available in associated data source so is there any process for list grids to override there cell editors like we did for forms?

    Thanks,

    Leave a comment:


  • learn_smartgwt
    replied
    Thanks. All worked fine. You know what the problem was creating ComboBox using a JavaScript Object.
    For example -
    Creating the ComboBoxItem like below (Using constructor) does not override the data source field.
    ComboBoxItem comboBoxItem = new ComboBoxItem(dataSourceField.getJsObj())

    But if change the definition like below - all work out the way you pointed out and described in documentation.
    ComboBoxItem comboBoxItem = new ComboBoxItem(dataSourceField.getName())

    So the lesson is if you wana override the data bound field then create the visual field with same name instead of using constructor shortcut by passing a Javascript object.

    I will play around with forms little bit more specially with validation and will let you if i might need help.

    Thanks for your support.

    Leave a comment:


  • Isomorphic
    replied
    Override getPickListFilterCriteria on the ComboBoxItem (where the method exists) not the DataSourceField (where it doesn't). Try not to let the shortcut of specifying certain properties on DataSourceFields confuse you - it has limited applicability and does not apply to Java methods at all.

    Yes, the data binding system is designed around letting you overlay component-specific properties over generic DataSource schema to maximize reuse. See the Data Binding chapter of the QuickStart Guide for an overview.

    Leave a comment:


  • learn_smartgwt
    replied
    I tried to override getPickListFilterCriteria() but the methof is not being invoked. I also tried with other methods but all overridden below, non of them is being invoked.

    Just to provide context - This field is data source field but i am overriding it from visual field by calling setFields () on form.

    Code:
    final ComboBoxItem employeeComboBoxItem = new ComboBoxItem(dataSourceField.getJsObj()){
    	@Override public Criteria getOptionCriteria() {
    		GWT.log("Called getOptionCriteria()");
    		return super.getOptionCriteria();
    	}
    	@Override protected Criteria getPickListFilterCriteria() {
    		GWT.log("Called getPickListFilterCriteria()");
    		return super.getPickListFilterCriteria();
    	}
    	
    	@Override public void fetchData() {
    		GWT.log("Called fetchData()");
    		super.fetchData();
    	}
    	
    	@Override public void fetchData(DSCallback callback) {
    		GWT.log("Called fetchData(callback)");
    		super.fetchData(callback);
    	}
    	
    	@Override public void fetchData(DSCallback callback, DSRequest requestProperties) {
    		GWT.log("Called fetchData(callback, requestProperties)");
    		super.fetchData(callback, requestProperties);
    	}
    };

    A small observation, i don't know if it's the intended behavior or a bug. Please advise.
    Details- I have a field in data source file which is mapped with forigien key and this field come back as selectItem which is fine. But if you override it with a ComboBoxItem in your code then this field should render as combobox but no it stay as select till then you don't specify editorType="ComboBoxItem" attribute that means form.setFields() does not override data bound field instead just copy/merge the additional attributes/functions. Is it the intended behavior?
    Last edited by learn_smartgwt; 15 Dec 2010, 07:11.

    Leave a comment:


  • Isomorphic
    replied
    Use an override of getPickListFilterCriteria instead of this approach. See the DataBound dependent select examples (for both grid and form) for intended usage.

    "hidden" on a DataSource field means "never show to user". If you want some other behavior, consider detail="true" and also the ability to use or not use fields on a component-specific basis (see Data Binding chapter of the QuickStart Guide).

    Leave a comment:


  • learn_smartgwt
    replied
    Thanks. It clear up the picture little bit more in my head.

    On a same topic - What's your recontamination to deal with situation where this pick list might have to use more fields (Apart from the foreignKey) as option criteria?

    What i am considering is to seup an javascript function like below. Is it the right way to use other ds fields as criteria?
    Although this function is not working right now as Smart GWT is treating returned value as string and expects a Map.

    <field name="empId" type="integer" title= "Test Emp LookUp" width="250"
    foreignKey="employees.id" editorType="ComboBoxItem" optionOperationId="fetchCurrentEmployees"
    pickListWidth="650" valueField="empId" displayField="displayName" required="true"
    optionCriteria="function () { var salaryVal = this.form.getValue('salary'); return [{salary: salaryVal}];}"
    />
    <field name="salary" type="integer" hidden="true"/>


    I also noticed that hidden fields are not available in DynamicForm (although they are available in data source). Is there any property that can include these hidden fields into data bound form as well? Or am i missing something?

    Leave a comment:


  • Isomorphic
    replied
    Nice job - yes that's what was meant.

    Two nuances to consider:

    1. what you're doing is "cheating" by providing component-specific properties on a DataSourceField, which is really meant as a shared definition for all components. Every DataBoundComponent (ListGrid, DynamicForm, DetailViewer, Calendar, TileGrid, etc) that binds to this DataSource is going to receive those properties. In most cases they will be ignored by the component, but in some cases they could have unintended consequences (field.optionDataSource is the classic example - different meaning for a FormItem vs a ListGridField).

    So this is fine as long as you know exactly what you are doing.

    The cleaner way to do this is to extend the data binding system. For example, subclass DynamicForm, and when the default binding is complete, go through the DataSource definition / generated fields and augment them with additional settings based on organization-specific properties you add to DataSource fields. Then use your subclassed DynamicForm pervasively so the additional databinding features you've added are always available.

    2. When you specify properties that aren't official DataSourceField properties you are using the schemaless transform mode of the Component XML system. So be aware of the need (documented under Component XML / Component Schema) to explicitly specify types in some situations (eg boolean fields).

    Finally, on your validation/Velocity question - yes, related fields are available as the "record" Velocity variable. See this sample.

    Leave a comment:


  • learn_smartgwt
    replied
    Originally posted by Isomorphic
    The standard way to do this is to create an instance of SelectItem or ComboBoxItem and call setPickListFields() on it, then associate that with the DataSourceField via a call to setEditorType().

    It is actually possible to drive this from the .ds.xml file as well, but we can't recommend doing so until you're willing to dive more deeply into the underlying SmartClient engine - you'll need to understand quite a few more things to do this properly than with the standard approach mentioned above.
    I think i understand what you mean by smartClient engine. Every field in .ds.xml file represent a field (which is a javascript object essentially) and all xml attribute are available as javascript object attributes and and we can set any property/function using this technique.

    Btw, i got it working. Thanks a lot for your pointer.

    One more thing - Is it possible to use one ds field's value to other field's validation logic (Using velocity template) ?

    Leave a comment:


  • learn_smartgwt
    replied
    We would prefer to drive that picklist from da.xml files. We have requirement where a wizard has to open up different forms based on user's earlier selections.

    If we would decide to do it in GWt java code then we might ended up building form class structure and that would increase with number of forms. But if we could do it with ds.xml file then it would be as simple as creating a form and setting up data source. I think it would be too much code to go other way around.

    Please let me know if you might have any reference doc and i would create an example before i would send out my finding on this evaluation.

    Leave a comment:


  • Isomorphic
    replied
    The standard way to do this is to create an instance of SelectItem or ComboBoxItem and call setPickListFields() on it, then associate that with the DataSourceField via a call to setEditorType().

    It is actually possible to drive this from the .ds.xml file as well, but we can't recommend doing so until you're willing to dive more deeply into the underlying SmartClient engine - you'll need to understand quite a few more things to do this properly than with the standard approach mentioned above.

    Leave a comment:


  • learn_smartgwt
    replied
    @Isomorphic - Any pointer on how to add multiple option columns on a form field which is based with foreign key relation ship?

    Leave a comment:


  • learn_smartgwt
    replied
    Hey! It works.

    With my previous sample on data binding (Obviouslly with your help) i thinki can deal with criteria.

    The only question is how to get pick list grid for combobox. Any ds field attribute called "pickListFields"? Just a wild guess. :)

    Leave a comment:

Working...
X