Announcement

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

    multiple selectitem linked to custom object does not work!

    Hi,

    Evaluating smart gwt EE (latest nightly build) and using Internet Explorer...

    The relevant field from my descriptor xml is the following:
    Code:
    <field name="theCountryLinks" title="theCountryLinks" multiple="true" type="silkCountryLink" javaClass="outpost.dto.SofLinkDTO" />
    Could it be that because field is set to MULTIPLE and I link this to a custom java class that it doesn't work? (In the DTO I return an ArrayList<SofLinkDTO>).
    When multiple set to "false" and returning a single SofLinkDTO it works fine.

    When I change from multiple "false" to "true" (and ofcourse change the return type of my DTO from SofLinkDTO to an ArrayList<SofLinkDTO> I don't get a javascript object anymore! But it reverts to a String [Object object].
    I tried casting to JavaScriptObject, Record, Map, LinkedHashMap, ArrayList, String[], etc. etc.

    It just seems that SmartGWT can't handle the field set to multiple and a custom object returned in an ArrayList.

    As you can see I have implemented my own simple type:

    Code:
    public class SilkCountryLink extends SimpleType {
    
      public final static String SIMPLETYPE_NAME = "silkCountryLink";
    	
      public SilkCountryLink() {	
        super(SIMPLETYPE_NAME, FieldType.ENUM);
        //get value map from a custom client cache
        super.setValueMap(SilkClientCache.getAllCountries());
    						
        this.setNormalDisplayFormatter(new Formatter());
        this.setShortDisplayFormatter(new Formatter());
       }
    	
       private class Formatter implements SimpleTypeFormatter {
    		
           public String format(Object value, DataClass field, 
                    DataBoundComponent component, Record record) {
    			
    	if(value == null){
    	  return "";
    	}
    			
                 //THIS ONLY WORKS IN CASE MULTIPLE=false
    	if(value instanceof JavaScriptObject){
      	   JavaScriptObject object = (JavaScriptObject) value;
    	   Integer id = JSOHelper.getAttributeAsInt(object, "id");
    			
    	    if(id != Integer.MIN_VALUE){
    	      LinkedHashMap<String, String> values = LinkedHashMap<String, String>)  JSOHelper.getAttributeAsMap(field.getJsObj(), "valueMap");
           return values.get (String.valueOf(id));			
          }
        return "";
        }
    			
        return (String) value;
       }
    }
    Please don't answer with OptionalDataSource... not relevant for this case ;-)

    Thanks a lot!

    #2
    It should work to set multiple=true and return a Collection of anything you like. Look in the RPC tab to see what's actually coming from the server in these cases so there is no confusion as to whether the formatter is at fault. For one, the server can never end up sending the String [Object object].

    Comment


      #3
      Thanx for the quick response... must be a new record ;-)

      What you said is exactly what I'm expecting... and as you can see it is indeed returning the correct values in the RPC console.

      Code:
                      theCountryLinks:[
                          {
                              id:159, 
                              representation:"", 
                              status:0, 
                              sysRepObjectID:13, 
                              sysRepRelationID:735
                          }
                      ],
      When I click the map open, I can see all the values from my map (see screenshot).
      But it's the initial formatting that's going wrong... any idea to what I should cast? It's just weird that it isn't returned as a javascript object isn't it?

      I also added a screenshot from my eclipse to show you I'm not lying ;-)

      Let me know if you need anything else and I appreciate the help.
      Attached Files

      Comment


        #4
        Actually the record is about 30 seconds :)

        What might be wrong with your formatter is that you seem to be expecting to be called once for each element in the array. In fact you'll be called once and passed the Array, which in GWT is also a JavaScriptObject but allows iteration.

        Comment


          #5
          Alright... started today with a fresh mind and found out the following:

          When used in a LISTGRID I get an Array (instanceof JsArray)... this is in the ShortDisplayFormatter that is called. Perfect.

          BUT

          When using my simpletype in a FORM, I get an [Object object]... and this is when the NormalDisplayFormatter is called. I can't cast it to the same JsArray... any other thoughts?

          Thanx

          Comment


            #6
            How are you populating the form with data?

            Comment


              #7
              The form is populated by a client-side datasource linked to a custom serverobject (we used your DMI showcase initially as a starting point).

              Don't know if it is relevant but our DataSources are generated (we extend your datasource loader and IDACall).

              However, the same system is used for the listgrid (where it works).

              Here is the (relevant) generated ds.xml

              Code:
              <DataSource ID="106">
              <fields>
              <field name="lcompany_id" title="id" primaryKey="true" canEdit="false" type="integer" required="true" >
              </field>
              <field name="name" title="name" type="text" required="true" >
              </field>
              <field name="fixednumberofdays" title="fixedNumberOfDays" type="integer" >
              </field>
              <field name="deviationpercondistance" title="deviationPercOnDistanceAllowed" type="float" emptyCellValue="0.1" >
              </field>
              <field name="expirationperiod" title="quoteExpirationPeriod" type="silkDuration" javaClass="parameter.Duration" >
              </field>
              <field name="defaultdurationunit_enumid" title="defaultDurationUnitEnumID" type="silkEnum" javaClass="parameter.SofEnum" >
              <valueMap>
              <value ID="72">Months</value>
              <value ID="71">Weeks</value>
              <value ID="70">Days</value>
              <value ID="257">Hours</value>
              <value ID="73">Years</value>
              <value ID="74">Minutes</value>
              </valueMap>
              </field>
              <field name="defaultdistanceunit_enumid" title="defaultDistanceUnitEnumID" type="silkEnum" javaClass="parameter.SofEnum" >
              <valueMap>
              <value ID="165">Km</value>
              <value ID="166">Mls</value>
              <value ID="167">Hours</value>
              </valueMap>
              </field>
              <field name="reliefvehicletype_enumid" title="reliefVehicleTypeEnumID" type="silkEnum" javaClass="parameter.SofEnum" required="true" >
              <valueMap>
              <value ID="1301">Internal</value>
              <value ID="1302">External</value>
              <value ID="1303">Both</value>
              </valueMap>
              </field>
              <field name="timestamp" title="timeStamp" type="text" >
              </field>
              <field name="dynAttributes" title="dynAttributes" multiple="true" type="Object" hidden="true" javaClass="outpost.dto.DynamicAttributeDTO" />
              <field name="theDefaultLanguageLinks" title="theDefaultLanguageLinks" multiple="false" type="silkLanguageLink" editorType="comboBox" />
              <field name="theDefaultCurrencyLinks" title="theDefaultCurrencyLinks" multiple="false" type="silkCurrencyLink" target="javascript" javaClass="outpost.dto.SofLinkDTO" />
              <field name="theCountryLinks" title="theCountryLinks" multiple="true" type="silkCountryLink" javaClass="outpost.dto.SofLinkDTO" />
              </fields>
              <serverObject lookupStyle="new" className="server.stores.useraccount.LeasingCompanyStore"/>
              </DataSource>
              Do you need anything else?

              Comment


                #8
                The key thing is actually how the data gets into the form, eg, is the form populated from a grid via eg editRecord()? Or does the form do a fetchData() and if so, if you inspect the data on the wire, is it a perfect match for what you are providing to the grid?

                Comment


                  #9
                  The form is populated via a fetchData...

                  I will do the following:

                  1) Inspect if what's going to the grid is identical to what is going to the form.
                  2) I will setup an example with a grid and let the form be populated via the (editRecord).

                  I will let you know asap!
                  Last edited by bade; 30 Jun 2010, 05:51.

                  Comment


                    #10
                    Using a listgrid with a form being populated by the editRecord didn't make any difference (same issue).

                    The only difference in the response to the grid vs. form was the endRow.
                    All other data was identical (used a file compare tool). I can give you the entire output if you want.

                    Code:
                    FORM response
                         --->   endRow:-1, <----
                            status:0, 
                            startRow:0, 
                            totalRows:1, 
                            isDSResponse:true
                    Code:
                    GRID response
                            endRow:1, 
                            status:0, 
                            startRow:0, 
                            totalRows:1, 
                            isDSResponse:true
                    However, found more differences between the two DSRequests.
                    Following differences, don't know if they are really relevant.

                    "textMatchStyle":"exact"
                    "oldValues":null
                    "criteria":null

                    Code:
                    FORM
                    {
                        "actionURL":"http://127.0.0.1:8888/silkroad/sc/IDACall", 
                        "showPrompt":true, 
                        "transport":"xmlHttpRequest", 
                        "promptStyle":"dialog", 
                        "bypassCache":true, 
                        "data":{
                            "criteria":null, 
                            "operationConfig":{
                                "dataSource":"106", 
                                "repo":null, 
                                "operationType":"fetch"
                            }, 
                            "componentId":"isc_SilkDynamicForm_0", 
                            "appID":"builtinApplication", 
                            "operation":"106_fetch", 
                            "oldValues":null
                        }
                    }
                    Code:
                    LISTGRID
                        "actionURL":"http://127.0.0.1:8888/silkroad/sc/IDACall", 
                        "showPrompt":true, 
                        "prompt":"Finding Records that match your criteria...", 
                        "transport":"xmlHttpRequest", 
                        "promptStyle":"dialog", 
                        "bypassCache":true, 
                        "data":{
                            "criteria":{
                            }, 
                            "operationConfig":{
                                "dataSource":"106", 
                                "repo":null, 
                                "operationType":"fetch", 
                                "textMatchStyle":"exact"
                            }, 
                            "startRow":0, 
                            "endRow":75, 
                            "componentId":"isc_SilkListGrid_1", 
                            "appID":"builtinApplication", 
                            "operation":"106_fetch", 
                            "oldValues":{
                            }
                        }
                    }
                    Last edited by bade; 1 Jul 2010, 01:34.

                    Comment


                      #11
                      Can you try creating this as a runnable test case? Note that we don't need the server code, just save your servlet's responses and use dataURL to point at them.

                      Comment

                      Working...
                      X