Announcement

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

    Evaluting SmartClient

    Hi all,

    Good work. I am new to this forum and I have couple of questions regarding the API and its capabilities.. I read the documentation and I am aware of some details.. I appreciate any help on below questions:

    1- Data Binding: The SmartClient Server delivers a logic to use servlets or dmi calls. However, I have seen that we need to pass a new list of data with every operation. For example, if I need to fetch.. then, I need to construct a new list of data from the persistence layer which already has objects fetched. in it. That means, I am getting data from persistence then building same data into new objects again.
    Code:
    public class SupplyItemFetch {
    
        public DSResponse fetch(SupplyItem criteria, DSRequest dsRequest) 
            throws Exception 
        {
            DSResponse dsResponse = new DSResponse();
    -->        List matchingItems = SupplyItemStore.findMatchingItems(criteria.getItemID(), 
                                                                   criteria.getItemName());
            dsResponse.setData(matchingItems);
    
            return dsResponse;
        }
    }
    Why am I obliged to build a new list? why not passing a generic bean which gets data based on the predefined datasource xml file? for example, why not passing that bean to the client and it gets fields based on the field name.. bean.get("ItemName"), bean.get("description") etc.... Is there a way to do that instead of being obliged to pass a list?! In GWT RPC, I could write any callback service and pass required info.. is this possible with smartclient ?

    2- Is there a way to find the dictionary of the metadata in one call. For example, I already have the definition of the dictionary for every field (length, scale, required, readonly, type, etc) in the persistence layer.. why would I need to rebuild xml files.. is there a way to pass a call to external datasource to find out the object definition or dictionary?

    3- What is the difference between GWT RPC and SmartClient RPC?
    Last edited by ammours; 5 Apr 2009, 08:11.

    #2
    I think the sticky "GWT-RPC DataSource implementation" answered major questions.. Thanks

    Comment


      #3
      On #1, the example is intended to demonstrate how you might connect to an ORM system which can return collections of beans. The SupplyItem & SupplyItemStore objects are intended to be an example of a pre-existing bean and DAO. The actual SmartClient-specific code involved in DMI is about as short as it can be, much shorter than equivalent GWT-RPC implementation, which also accomplishes less (eg, no server-side validation, no queuing, to name just a couple).

      On #2, SmartGWT EE allows you to generate the .ds.xml files from pre-existing metadata, including a Java class. This is available as a wizard in the Visual Builder. In this way, you never need to write code, client or server side, to create a DataSource and define it's fields.

      On #3, GWT-RPC delivers data to/from server only, and even that typically requires the creation of separate DTOs (data transfer objects) which are unnecessary in SmartGWT EE. However the part of SmartGWT EE which is comparable to GWT-RPC is something like 1/20 of the overall functionality delivered - see the SmartClient Server Summary from the SmartClient docs, but be aware this does not include the many new features announced on the blog.

      Comment


        #4
        Thank you. That's impressive.. Really.

        I need to check how can I achieve a field level validation based on a field update TabOut.. How can I throw an exception on the server (then pass it to the client for sure) based on a business validation on the persistence later?

        I know that this happens on the save of a button.. is there an example for a field tab out after altering it ? Thanks again!

        Comment


          #5
          The approach varies a little based on whether you want to actually save if validation passes, and whether you want to block the UI while you validate.

          Assuming you want to run some kind of validation that *must* run on the server (eg check unique user id against large user database), and you want the same validation logic to kick in whether these records are being saved, but you don't want to save if validation passes:

          Implement the custom validation logic as a Java subclass of whatever server-side DataSource you are using (eg com.isomorphic.hibernate.HibernateDataSource if using built-in Hibernate integration). Just override validate() in the subclass, nothing else is required, it all still comes from the .ds.xml file. In your .ds.xml file indicate that you want to use this class via the serverConstructor attribute. Now your validation logic will kick in for all "add" and "update" attempts.

          To validate just one field on the fly without attempting a save, call DataSource.addData() with operationId set to a special value, eg, "validateOnly". Implement a DMI method for this operationId that is just empty. This prevents the default action of saving to Hibernate in the case that validation passes (validation is triggered automatically).

          On the client-side, check for dsResponse.getErrors() being non-null, and apply them to the form with form.setErrors(). If you want to make validation block interactivity, set showPrompt:true in the DSRequest Properties of addDate(), and use focusInItem to force focus back if there are errors.

          This is something we'll shortly be making an example for. We may also simplify the client side of it via something like a serverValidateOnChange flag.

          Comment


            #6
            Hi Isomorphic,

            At this stage, I have sucessfully implemented the integration using standard operations and it is the time to better understand how to achieve these custom validations. I will explain in more details so that you can help me better..

            * for Fetch operation: works great no need to validate.
            * For Add: My requirement is to add an object on the UI without any value in the dynamic form. That means, an object is added first then fields are filled in then we save the object. This is good for the performance since I call the server on every update (and validate values with every update) instead of making the user waits for the save after filling the whole form (that takes time to loop for values and validate them all at a time).

            * For update operation: as I mentioned, update field is going to call the server to validate the value based on business logic rules.

            * For delete operation: simple delete.

            I am also confused about the out of the box validation on the client side and server side.. What is that OTTB validation on the server and client... what is the difference? What does it do? validate() method doesn't exist on the datasource.. However, another version is there with DSRequest as an argument.

            Finally, did you get the chance to write example about that or adding the "serverValidateOnChange" flag?

            Thanks for you on going help!

            Comment


              #7
              Peppering the server with every field change is *not* generally considered good for performance :)

              Take a look at DataSourceField.validators for the set of available built-in validators - these are automatically executed both client and server, which is the best approach for performance.

              If there are validations that must be performed on the server, these can be postponed until save is attempted - just add business logic in the DMI method that performs any validations that are not covered by built-in validators, and call setErrors() on the DSResponse to convey these to the client side.

              Comment


                #8
                Well, users will give up correcting delayed validations (imagine you have 25 or even more fields all interlinked with upper and child object). That is considered a nightmare for a user. These are business validations which are not safe to be done on server. I still see that field validation is the best way to go for my framework.

                Comment


                  #9
                  Didn't really follow that. Take a look at the built-in set of validators, they offer field-by-field validation that takes places instantaneously in the browser.

                  Comment


                    #10
                    Ok. more details:

                    I have to insert a new record on the page and that record can have a linked children list for insertion too. The user made mistakes and inserted wrong values in the list (containing about 100 records).. Some of which had errors ( say 50 records of 100). Using delayed BUSINESS VALIDATION ON SERVER (not browser built-in low level validation), Will the user have to visit the 50 records and correct them one by one?!
                    Thank you :)
                    Last edited by ammours; 24 Apr 2009, 13:31.

                    Comment


                      #11
                      Have you actually looked at the Validators support yet? You're referring to "browser built-in low level validation". There is no such thing (unless you mean length restrictions in text fields), but SmartClient does support a wide variety of built-in validators that cover most use cases.

                      By using databound SelectItems / ComboBoxItems you cover many more possible error cases (eg, the user can only pick a valid related entity, such as a Contact or Account).

                      Finally there are some cases where a server-trip is required (like whether a new, user-chosen userId is unique), and you can choose whether to do these immediately or not. If you want the server validation performed immediately you would, for example, call DynamicForm.validateData().

                      Comment


                        #12
                        Yes, probably that makes sense now. I will have to investigate these.. It would be a good approach to strict the user to choose from a valid bound valuelist.. Do we have a concept of lookup in smartclient? I mean is there such a possibility to show the user the list of values on a new window (lookup dialog instead of combobox).. I am asking for too much but if this doesn't exist, it is not a big deal... just learning and thanks for your great support!

                        Comment


                          #13
                          SelectItem/ComboBoxItem with optionDataSource is effectively an inline "lookup", especially with the ability to set pickListFields to show multiple columns.

                          There isn't a built-in "lookup" dialog but it's very easy to build based on the Window class containing a ListGrid bound to a DataSource, ideally with showFilterEditor:true to get "query by example".

                          FormItem.icons is a good way to provide an icon to launch a lookup dialog.

                          Comment

                          Working...
                          X