Announcement

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

    Select Multiple Entries to be added to a Datasource

    SmartGwt 3.0p nightly 1/30/2012
    Gwt 2.4
    Firefox 6.0

    I have a form that has the following fields.......

    Employee
    StartDate
    EndDate

    I currently have the Employee Field as a dropdown that is being pulled from an OptionDataSource of employees. So all of the employees are populated in the SelectItem dropdown.

    The form in this simple state adds the employee to the ListGrid that I have properly. However, I would like to enable multipleselections through.....
    SelectItem.setMultiple(true), and have it add all the selected Employees to the list with the chosen Date for all of them.

    For example...

    Employees: John Smith, Jane Smith
    StartDate: 02/01/2012
    EndDate: 02/04/2012

    Both John and Jane Smith should each have their own entries in a ListGrid with the same Start/End Date.

    How can I accomplish this?

    #2
    I went ahead and created a server side DMI class with the method name
    MultiSelect which has the DSRequest object as its sole parameter.

    I was able to obtain the values for all of the Employees by using dsRequest.getFieldValue(Employees)

    I created a for loop and began iterating through the list of Employees and using the dsRequest.setFieldValue() function followed by dsRequest.execute()

    Code:
    DSResponse response = new DSResponse();
    ArrayList<Long> employeeIds =(ArrayList<Long>) dsRequest.getFieldValue("EmployeeId");
    
    		for(int i = 0; i < employeeIds.size(); i++)
    		{
    			dsRequest.setFieldValue("EmployeeId", employeeIds.get(i));
    			response = dsRequest.execute());
    		}
    Finally, I return the response to the clientSide.

    However, the ListGrid which shows my list of employees only gets updated with the last employee to have been "INSERT"ed into the database.
    If i were to manually refresh my list of employees I would see all of the employees that were actually added.

    Is there a way to have the DSResponse object return and update all of the employees which were "INSERT"ed during the DMI call?

    Comment


      #3
      You might be looking for dsResponse.addRelatedUpdate().

      Comment


        #4
        Thank you for the quick response.

        First, I could not find any documentation related to the "addRelatedUpdate()"
        in the DSResponse API. I would guess that it is missing and simply needs to be added given that its available for use.

        Secondly, the usage of that function seems to have given me the results that I am looking for, but I am still seeing something that is not completely right....

        below is my ds.xml file
        Code:
        	<fields>
        		<field name="ManifestId" type="sequence" primaryKey="true" hidden="true" />
        		<field name="EmployeeId" type="integer" hidden="true" foreignKey="Employees.EmployeeId" />
        		<field name="ProjectId" type="integer" hidden="true" foreignKey="Projects.ProjectId" />
        		<field name="CompanyId" type="integer" hidden="true" foreignKey="Companies.CompanyId" />
        		<field name="EmbarkDate" title="Embark Date" type="date" />
        		<field name="DisembarkDate" title="Disembark Date" type="date" />
        		<field name="VisaType" title="Visa Type" type="text" />
        		<field name="CabinNumber" title="Cabin" type="int" length="5"/>
        		<field name="CabinAssignments" title="Cabin Assignments" type="text"/>
        		<field name="LastEdited" title="Last Edited" type="datetime" />
        		<field includeFrom="Employees.FirstName" />
        		<field includeFrom="Employees.LastName" />
        		<field includeFrom="Employees.Position" />
        		<field includeFrom="Employees.DateOfBirth" />
        		<field includeFrom="Employees.SubContractorName" />
        		<field includeFrom="Employees.Sex" />
        		<field includeFrom="Employees.PrimaryEmail" />
        		<field includeFrom="Employees.CountryOfCitizenship" />
        		<field includeFrom="Employees.PassportNumber" />
        		<field includeFrom="Employees.PassportExpiration" />
        		<field includeFrom="Companies.CompanyName" />
        	</fields>
        I selected 2 employees to be added to my list and after the DMI performed its operation and completed, I saw the selected employees show up on my ListGrid, but I also saw an additional entry in my ListGrid at the end, that holds no information other than the values of the fields that were not from "Field Includes". I then checked my table from the SQL database and the 2 employees show up correctly, with no 3rd blank entry showing up.

        Why am I getting this 3rd "ghost" entry showing up in my ListGrid after I submit my form with the employee information?

        My complete DMI method is show below, which is nothing different than what I had previously posted.

        Code:
        	public DSResponse multiSelect_manifest(DSRequest dsRequest) throws Exception{
        		
        		DSResponse response = new DSResponse();
        		
        		ArrayList<Long> employeeIds =(ArrayList<Long>) dsRequest.getFieldValue("EmployeeId");
        		Long projectId = (Long)dsRequest.getFieldValue("ProjectId");
        		Long companyId = (Long)dsRequest.getFieldValue("CompanyId");
        		Date startDate = (Date)dsRequest.getFieldValue("EmbarkDate");
        		Date endDate = (Date)dsRequest.getFieldValue("DisembarkDate");
        		String cabAssign = (String)dsRequest.getFieldValue("CabinAssignments");
        		String visaType = (String)dsRequest.getFieldValue("VisaType");
        		
        		for(int i = 0; i < employeeIds.size(); i++)
        		{
        			dsRequest.setFieldValue("EmployeeId", employeeIds.get(i));
        			response.addRelatedUpdate(dsRequest.execute());
        		}
        		
        		return response;
        	}
        I am also attaching the log of the transaction because I am seeing within the log a statement that reads, "Clobbering existing FreeResourcesHandler of type 'com.isomorphic.sql.SQLD
        ataSource' with a 'com.isomorphic.sql.SQLDataSource'".

        In the end, I ultimately would like to know if the way I have implemented my DMI is the correct way to achieve my goal?

        Thank you for any assistance.
        Attached Files

        Comment


          #5
          This method was documented but a build problem was suppressing the docs. This is now fixed for future nightlies, but here they are:

          /*
          * Causes client-side components to react as though the provided DSResponse had just
          * successfully completed.
          * <P>
          * This API can be used to communicate additional changes that occur as a consequence of the
          * current DSResponse succeeding, such as changes to other records in the same DataSource or to
          * records from unrelated DataSources. For example, in CRM applications, Leads may be
          * converted to Accounts. In this case the "remove" operation on the Leads DataSource might
          * call <code>addRelatedUpdate()</code> with a DSResponse representing an "add" operation on
          * the Accounts DataSource. This would cause any client-side caches of Accounts (such as a
          * drop-down list for picking an Account) to automatically update.
          * <P>
          * If a DSResponse is passed with the DataSource or operationType unset, they will match the
          * current DSResponse.
          * <P>
          * This API can be called multiple times for multiple related updates. Each update is
          * processed by the client-side method DataSource.updateCaches().
          * <P>
          * This API should <b>NOT</b> be used simply to complete multiple requests in a single HTTP
          * turnaround, instead, use Queuing for this (see the client-side API
          * isc.RPCManager.startQueue()).
          *
          * @return the DSResponse
          * @param relatedUpdate <code>DSResponse</code> to add.
          */
          To troubleshoot the ghost entry, take a look at the updateCaches() doc mentioned above, as well as the FAQ on grids not updating properly.

          Comment


            #6
            Hi Isomorphic,

            the javadoc entry for addRelatedUpdate is still missing in
            http://www.smartclient.com/smartgwtee/server/javadoc/com/isomorphic/datasource/DSResponse.html

            Best regards,
            Blama

            Comment


              #7
              Grab a new build to get the updated JavaDoc.

              Comment

              Working...
              X