Announcement

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

    #16
    Not sure if you realize that this sample is already showing this behavior? Dragged records acquire a project code that match the current criteria on the grid.

    So just match the sample. You probably have a typo or similar.

    Comment


      #17
      Hm, I did not realize this, and will try to match this closely. Was kind of 'distracted' by the employeeID, seeing that as the only extra data. Thanks

      Comment


        #18
        Alright, it works.

        This is what triggered it:

        On the Person datasource, the id field was set to hidden="true". I thought this would only mean it wouldn't show up in a form standardly. But appearantly it means more than that? Anyway, when removing the hidden="true" from the id field of Person, things worked.
        Last edited by Kah0ona; 16 Aug 2010, 04:40.

        Comment


          #19
          Hmm, it's intended to work regardless of whether it's marked hidden. We'll check on this.

          Comment


            #20
            In my system , (the example in this thread one was trimmed down a bit for clarity), I had the following UI structure:

            1) A list grid with persons
            2) When clicked on one row, the record loads into a DynamicForm, as a detail view. Thus, the grid and the form share the same datasource
            3) A grid with _all_ hobbies
            4) A grid where hobbies can be dragged onto, to connect them to Persons.

            The hidden="true" was on persons datasource, on the 'id' field. Now I just programmatically hide this field from the grid, and that works just fine.

            Comment


              #21
              Many-To-Many operation From Grid to Grid with Grid Selector

              Piggy-backing off this post since it got me 95% of the way there...

              Version: v8.3p_2012-11-25/PowerEdition Deployment (built 2012-11-25)

              I've successfully followed this post as well as the online sample http://www.smartclient.com/smartgwtee/showcase/#row_drag_save to do a Many-To-Many drag and drop operation.

              Unlike the example, instead of a ComboBox to set the foreign key "criteria" on the grid where the record is dragged, I have a grid.

              Quick description:
              Grid A - Students
              Grid B - Courses
              Grid C - Many to many grid show students in courses.

              If I select a course, I can then drag many students to grid C.

              Now I'd like to be able to select MORE THAN 1 course and drag 1 OR MORE students over to Grid C.

              This won't work using the sample code b/c my Criteria is now a list of IDs not a single Course Id.

              No problem I just send an Advanced Criteria into the fetch of Grid B.

              Then I got this error:
              Code:
              Criteria received from the client for add operation is missing the following non-sequence primary key fields: [course_id]. Either provide all primary key fields that are not sequences, or set allowMultiUpdate on the OperationBinding
              Well that make sense, I now have TWO course ids in my criteria and the auto-magic of Smart GWT can't find the id it should inject into the dropped records.

              So I added a DragEventHandler and did the data add myself. I loop through the dropped records (students) and for each selected course, I just add in [course_id] and [student_id] into the dropped record and add it to my grid.

              IT WORKS!

              So far so good...but now the issue. What happens if my many-to-many grid (Courses-Students) already contains one of the rows I'm trying to drag. In the past, the SmartGWT automagic could detect duplicates and display an informative error message (getDuplicateRecordMessage) to the user.

              Now, since I'm handling the drop event, adding the data myself, and cancelling the drag event, the SmartGWT automagic isn't checking for duplicate records and I get this error:

              Code:
              ERROR: duplicate key value violates unique constraint "course_student"
                Detail: Key (course_id, student_id)=(2, 3) already exists.
              This was previously handled by SmartGWT but since I'm now handling the drag and drop operation no smart checks are being done.

              So my question to Isomorphic/SmartGWT team is:

              1) Do you have any plans to support dropping multiple records onto a grid with a collection of foreign key values and just not a single one?

              2) If I wanted to do a check myself or handle the add data error, how would I do this?
              - I tried doing:
              datasource.addHandleErrorHandler and then calling event.getResponse().getErrors() but getErrors() is returning null. I thought it would return the primary key error.

              3) Is there any API call on either the grid or the datasource that would let me attempt validation and know whether an operation will succeed BEFORE actually doing the operation? And if so, will this handle the fact that the grid may not have fetched all the data in the database (if using paging and live scrolling).

              HELP!

              Comment


                #22
                1) what would you expect this to do? Create multiple records?

                2 / 3) you would basically replicate what the built-in logic does - check if the cache is full (use ResultSet APIs), if so, do a purely local check, otherwise, use DataSource APIs (eg DS.fetchData()) to check the server, then issue appropriate add/update operations if there are no duplicates.

                Comment


                  #23
                  Originally posted by Isomorphic View Post
                  1) what would you expect this to do? Create multiple records?
                  Yes, precisely. I'm not sure how complicated the internal SmartGWT code logic is...but if it could be replaced to handle a set or a collection of id's instead of just a single id then this would provide great functionality.

                  For example,
                  Grid B: I select two courses, Math and Science (this sets the course_id property to be either Math or Science in the Many-to-Many grid)
                  Grid A: I select two students, Bob and Mary.

                  I drag the selected Bob and Mary records over to the Courses-Students (Grid C) grid and I now have:
                  Science | Bob
                  Science | Mary
                  Math | Bob
                  Math | Mary

                  If the internal logic heavily relies on a single id this change could be onerous. But if it's just changing the course_id values injected into the records before being dropped by looping through Advanced Criteria set instead of just looking up the property on Criteria it seems easier to implement.

                  Originally posted by Isomorphic View Post
                  2 / 3) you would basically replicate what the built-in logic does - check if the cache is full (use ResultSet APIs), if so, do a purely local check, otherwise, use DataSource APIs (eg DS.fetchData()) to check the server, then issue appropriate add/update operations if there are no duplicates.
                  Ok, I assumed as much. Doesn't seem like it would be that difficult to test. I wasn't sure if there was a clever or efficient way SmartGWT checked to make sure a record is valid for a given datasource...but if it's just a matter of:

                  Is cache full?
                  Yes: Look in cache for matching record
                  No: Call DS.fetchData with AdvancedCriteria for the combined primary key.

                  Is there a reason why datasource.addDataErrorHandler didn't return any errors in the response object? Seems to me I could just let SmartGWT do the local cache/remote check and if the error is the one I've described, show the user the getDuplicateRecordMessage.

                  Thanks as always for the quick response! The Many-To-Many sample and this thread were instrumental in my success!

                  Comment


                    #24
                    1) so to rephrase - you are dropping Records onto a grid which has search criteria applied with multiple values for a given field (a logical OR). In this situation, if there are M criteria values for a field, and N records are dropped, create N*M records, each set of N records having a different value for the field that had multiple criteria values. Right?

                    2) Not clear what handler you mean (the API described doesn't exist..) but regardless the answer may be that this is a potentially asynchronous check so we can't tell you whether there are duplicates when the drop event fires.

                    Comment


                      #25
                      Originally posted by Isomorphic View Post
                      1) so to rephrase - you are dropping Records onto a grid which has search criteria applied with multiple values for a given field (a logical OR). In this situation, if there are M criteria values for a field, and N records are dropped, create N*M records, each set of N records having a different value for the field that had multiple criteria values. Right?
                      To confirm: Yes, a logical OR of a collection of multiple COURSE ids instead of just a single COURSE id.

                      Yes, so if you have selected M records and drag N records to the Many-To-Many table you would get N*M new records. (Unless of course one of those dragged records already existed in which case you would just get that nice getDuplicateRecordDrag message that I was trying to get to show all along). It's exactly like this example (http://www.smartclient.com/smartgwte...#row_drag_save) except instead of choosing a Team Project via comboBox you could choose MULTIPLE team projects by first selecting those in a grid.

                      Originally posted by Isomorphic View Post
                      2) Not clear what handler you mean (the API described doesn't exist..) but regardless the answer may be that this is a potentially asynchronous check so we can't tell you whether there are duplicates when the drop event fires.
                      I thought the easiest way to handle multiple record selection and drag in Many-To-Many and show a nice error message would be to use this handler (which appears documented in the API: http://www.smartclient.com/smartgwt/...rrorHandler%29).

                      According to the documentation, I should be able to get notified whenever DSResponse returns with a status code that is NOT success. I hooked into this handler and indeed it gets called. HOWEVER, the DSResponse.getErrors() field was null and I don't see how that's possible with a primary key conflict error from the DB. I could then detect this DB primary key conflict, and per the documentation show my error dialog and return false and everything would be fine. BUT the getErrors() field is null. Seems like it should be populated with something.
                      Last edited by chimpeenuts; 6 Feb 2013, 15:31.

                      Comment


                        #26
                        getErrors() returns per-field validation errors that are being reported by the server.

                        If you explicitly declared a validator to check for PK collision ("uniqueCheck"), validation errors would be expected.

                        If you are just letting the underlying DB throw an exception, you'd get a general failure, with no per-field errors. Our server code doesn't know the DB exception means a PK collision as opposed to something like SQL syntax error or DB is completely down.

                        Comment


                          #27
                          Originally posted by Isomorphic View Post
                          If you explicitly declared a validator to check for PK collision ("uniqueCheck"), validation errors would be expected.
                          To do a uniqueCheck on a ds.xml file representing a many-to-many table, would I have to create a virtual field for each of the many-to-many keys?

                          So if my current DS is:
                          Code:
                          <DataSource ID="trigger__device" tableName="trigger__device"
                          	serverType="sql" dropExtraFields="true">
                          	<fields> 
                          		<field name="device_id" type="integer"
                          			primaryKey="true" canEdit="false" foreignKey="device.id" />
                          		<field name="trigger_id" type="integer"
                          			primaryKey="true" canEdit="false" foreignKey="trigger.id" />
                          	</fields>
                          	
                              <operationBindings>  
                                  <operationBinding operationType="fetch">  
                                      <tableClause>trigger__device, trigger, device</tableClause>  
                                      <whereClause>trigger__device.trigger_id = trigger.id AND trigger__device.device_id = device.id AND ($defaultWhereClause)</whereClause>  
                                  </operationBinding>  
                              </operationBindings>  
                          </DataSource>
                          I would just need to add in something like this:
                          Code:
                          <field name="compositeKey" customSelectExpression="CONCAT(CONCAT(device_id, ' '), trigger_id)">
                          
                          <validators>
                               <validator type="isUnique"/>
                          </validators>
                          
                          </field>
                          ????

                          Comment


                            #28
                            So I just tried to implement a composite key with a isUnique validator like I described in my previous post and it doesn't work.

                            I'm not sure if it's the fact I'm using a customSelect and should instead use a customUpdate or customInsert?

                            I even added the compositeKey "property" and "value" to my record before calling:

                            datasource.add(record)

                            and I still don't get any isUnique errors or anything from the datasource.addHandleError handler.

                            Comment


                              #29
                              Hi Isomorphic,

                              I found this thread while re-building this sample http://www.smartclient.com/smartgwte...rag_save_pivot for my use-case.

                              There I use this piece of code:
                              Code:
                              assignedRolesGrid.fetchData(new Criteria("USER_ID", parent.getUserId().toString()));
                              // Not working:
                              // assignedRolesGrid.fetchData(new Criterion("USER_ID", OperatorId.EQUALS, parent.getUserId()));
                              Within your example you use teamSelectionForm.getValuesAsCriteria() (teamSelectionForm is a DynamicForm). With respect to this post in this tread:

                              Originally posted by Isomorphic View Post
                              Yes, it's because of the criteria. It knows you want to create a new record that can be displayed in the current grid. So it has to have a person_id value that conforms to the current criteria or else it would be immediately eliminated by the criteria.
                              I'd like to emphasize, that the signature is public Criteria DynamicForm.getValuesAsCriteria().

                              In my experiment Drag-and-Drop didn't work, because the ListGrid receiving the drop was filtered with "new Criterion(...)" and not "Criteria".

                              Could you please confirm that this is really the case and also intended? From my feeling, I'd like the "Criterion"-approach more, because it's more specific, and my ID is already an Integer. "Criteria" only has a "new Criteria(String fieldname, String value)"-constructor.

                              Thank you & best regards,
                              Blama

                              Comment


                                #30
                                Blama -

                                I can't answer some of your questions, but I can say that Criteria(string, string) for an numerical Id value does work and is ok since most of Smart GWT's underlaying objects are just json or javascript objects that use strings or can convert and compare strings with numerical values.

                                That being said a Criteria object does have an addCriteria method that takes a string an an integer value.

                                So you'd just have to do:
                                Code:
                                Criteria c = new Criteria();
                                c.addCriteria("USER_ID", parent.getUserId());

                                Comment

                                Working...
                                X