Announcement

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

    dynamicform.savedata and listGrid update problem

    hi,
    I have a problem with listgrid displaying a wrong newly added entry. Here is what i did to try to do a "New User Form"
    1) created a listgrid with a database-backed datasource
    2) create a form with the same data-source
    3) the form doesn't show all fields (like it hides database row id)
    4) call form.editNewRecord() to clear everything
    5) let user enter in the data
    6) call form.savedata()

    the data is actually saved in the db. one would expect the listgrid to display a new row with the new data. It did show a new row, but the data is incorrect, it picked the first row of the list and show that as the new row. So the listgrid has two rows that's the same.

    Maybe i'm using the forms incorrectly?

    when I close the listgrid and re-opens it, the right data shows-up.

    #2
    The data you return from your server when the "add" operation completes is the data the ListGrid integrated into it's cache. Sounds like you have a server bug where you always return the first row, instead of the row that was just added.

    Comment


      #3
      thanks for the quick reply. But I don't have any server code. :) the datasource is a postgres-db datasource with a standard settings. Here might be something. essentially the has 3 columns:

      user_id, login and email

      I don't want to expose user_id to users. so the add form only shows login and email. and the user_id is supposed to get generated by the database itself. maybe this is what's confusing ListGrid?

      how do I force a refresh on ListGrid? tried ListGrid.fetchData(), doesn't seem to do anything.

      Comment


        #4
        It doesn't matter what's in the form. If the sequence field is declared in the database as the primaryKey, a new sequence value will be generated in the database, the server will automatically select the newly inserted row and return it.

        If you think your declarations are already correct with respect to the above description, post:

        1. the .ds.xml file
        2. contents of the RPC tab: request and response
        3. complete server log for the "add" request and response

        Comment


          #5
          ds.xml file

          Code:
          <!-- Auto-generated from database table users -->
          
          <DataSource 
          	schema="public"
          	testFileName="users.data.xml"
          	dbName="PostgreSQL"
          	tableName="users"
          	ID="users"
          	dataSourceVersion="1"
          	generatedBy="SC_SNAPSHOT-2011-02-28/EVAL Deployment 2011-03-01"
          	serverType="sql"
          >
          	<fields>
          		<field primaryKey="true" name="user_id" type="integer"></field>
          		<field name="login" length="40" type="text"></field>
          		<field name="password" length="40" type="text"></field>
          		<field name="email" length="40" type="text"></field>
          	</fields>
          </DataSource>
          from SQL logs

          Code:
          SQL query for the list grid display (before the add)
          
          2011-06-02 21:48:07 PDTLOG:  execute <unnamed>: SELECT COUNT(*) FROM public.users WHERE ('1'='1')
          2011-06-02 21:48:07 PDTLOG:  execute <unnamed>: SELECT users.email, users.user_id, users.login, users.password FROM public.users WHERE ('1'='1') OFFSET 0 LIMIT 75
          
          SQL query for the add command and after
          
          2011-06-02 21:48:54 PDTLOG:  execute <unnamed>: INSERT INTO public.users (email, login, password) VALUES ('n@n.com', 'n', 'n')
          2011-06-02 21:48:54 PDTLOG:  execute <unnamed>: SELECT users.email, users.user_id, users.login, users.password FROM public.users WHERE ('1'='1')

          Comment


            #6
            attached is a screenshot
            Attached Files

            Comment


              #7
              As previously indicated: your primary key is not declared to be a "sequence"

              Comment


                #8
                Originally posted by Isomorphic
                As previously indicated: your primary key is not declared to be a "sequence"
                I tried doing that (changing the ds.xml file's user_id type to sequence), but that's yielding an error. "ERROR: relationship public.users_user_id doesn't exist"

                I am using postgres 8.4 and here is how I declare the table

                Code:
                CREATE SEQUENCE users_seq
                    START WITH 1
                    INCREMENT BY 1
                    NO MAXVALUE
                    NO MINVALUE
                    CACHE 1;
                
                SELECT pg_catalog.setval('users_seq', 32, true);
                
                CREATE TABLE users (
                    user_id integer DEFAULT nextval('users_seq'::regclass) NOT NULL,
                    login character varying(40) NOT NULL,
                    password character varying(40) NOT NULL,
                    email character varying(40) NOT NULL
                );

                Comment


                  #9
                  Set dataSourceField.sequenceName to match the name of the sequence you created (there's no automatic way to figure this out). Note this is not required if you let SmartGWT generate the table and sequence for you using the Admin Console.

                  Comment


                    #10
                    Originally posted by Isomorphic
                    Set dataSourceField.sequenceName to match the name of the sequence you created (there's no automatic way to figure this out). Note this is not required if you let SmartGWT generate the table and sequence for you using the Admin Console.
                    tried this and it worked like a charm. Thank you very much for your quick help. you guys rock!

                    perhaps some improvement on the error messages would be useful. If a field is specified to be a sequence without a sequence name, that error message can be very specific.

                    Comment


                      #11
                      Oracle and Postgres are the only DBs where there's a separate sequence and hence sequenceName is required, and we don't know whether you've created the table by hand vs had us create it, so this error case is not easy to trap.

                      Comment


                        #12
                        the ds.xml file specifies exactly that this is a postgres database. and it should be easy to look at the datasource field to see if it's a sequence and if so whether a sequence name exists.

                        yes, I did create the database by hand. but you can't expect all or even most development to start with creating database schema from your tool set. I am thinking about using smartgwt to rewrite the GUI for a large existing app, there is no way we will touch the database schema, or even the backend logic.

                        btw, I am saying this only because I want to make it easier for other people that run into the same issue solve their problem themselves.

                        you guys have been very helpful.

                        Comment


                          #13
                          We obviously do not expect most development projects to start with new tables, hence the dozens of features that derive fields from existing tables (autoDeriveSchema) or compensate for weird storage paradigms (sqlStorageStrategy). It's just an FYI that if you *are* starting from scratch, you don't need to be writing SQL schema.

                          Comment

                          Working...
                          X