Announcement

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

    #46
    Hello Jay,

    Nice to see your reply. I was waiting long for it. And also thanks for showing interest.

    Now about problem the xmlString is not blank. As its same as shown in my first example so i had not posted the xmlString again.

    And about dataFormat or servertype can you suggest which type of dataFormat i should set there? If possible please update the xmlString and post here so it will be clear to understand.

    Comment


      #47
      @Jay, Below description depicts my actual requirement. Please have a look at it.

      Originally posted by webashlar
      @Isomorphic

      I think i should depict my exact requirement so you will be the better person to tell which approach i should use.

      It will be more meaningful if you go through demo project (created by me) which is currently in GXT + GAE (low level API). I want to convert it in smartGWT + GAE (low level API).
      http://www.lunkadvipul.appspot.com/

      Brief about this project (it is same like Sharepoint List mechanism):
      Here user should be able to create model and after creating the model user should be able to perform CRUD operation on same model.
      ADD Model : To create new Model
      View Model : To view created model data and perform CRUD operations

      Now as you can see the project is basically dependent on dynamic modeling. There will be no datasource description will be known in advance. If i don't know datasource description in advance then how should i use custom datasource mechanism here.

      I have followed the approach provided in this thread but still i was not able to achieve the dynamic datasource description.

      Can you provide your valuable suggestions which approach i should use for dynamic datasource description?

      Please try to give replay in depth so i will not trouble you every time with my questions.

      Comment


        #48
        I think i should summarize some part of code here. So you will get to know the actual problem.

        Client Side Code:
        Code:
        DataSource dataSource = DataSource.getDataSource("dynamicEntity");
        ListGrid.setDataSource(dataSource);
        Code of class where IDACall extended:
        Code:
        public class SupplyMasterDS extends IDACall {
        
        public DSResponse handleDSRequest(DSRequest dsRequest, RPCManager rpc,
                    RequestContext context) throws Exception {
              DSResponse resp = new DSResponse();
              String xmlString = 
         "<DataSource\r" +
        			    "    ID=\"dynamicEntity\"\r" +
        			    ">\r" +
        			    "    <fields>\r" +
        			    "        <field name=\"fieldName\"    type=\"text\"     title=\"Name\"        required=\"true\"/>\r" +
        			    "        <field name=\"fieldType\"    type=\"text\"     title=\"Type\"        required=\"true\">\r" +
        			    "            <valueMap>\r" +
        			    "                <value>Number</value>\r" +
        			    "                <value>Text</value>\r" +
        			    "                <value>Long Text</value>\r" +
        			    "            </valueMap>\r" +
        			    "        </field>\r" +
        			    "        <field name=\"width\"  type=\"integer\"   title=\"Width\"/>\r" +
        			    "        <field name=\"alignment\" type=\"text\"   title=\"Alignment\">\r" +
        			    "            <valueMap>\r" +
        			    "                <value>Left</value>\r" +
        			    "                <value>Right</value>\r" +
        			    "                <value>Center</value>\r" +
        			    "            </valueMap>\r" +
        			    "        </field>\r" +
        			    "        <field name=\"viewField\"   type=\"text\"  title=\"View Field\">\r" +
        			    "            <valueMap>\r" +
        			    "                <value>Default</value>\r" +
        			    "                <value>Currency</value>\r" +
        			    "            </valueMap>\r" +
        			    "        </field>\r" +			    
        			    "        <field name=\"suggestionFields\"  type=\"text\" title=\"Suggestion Fields\"/>\r" +
        			    "    </fields>\r" +
        			    "</DataSource>\r";
              DataSource ds = DataSource.fromXML(xmlString);
              String operation = dsRequest.getOperationType();
              if (operation.equals(DataSource.OP_FETCH)) {
              }else if () {
              }else if () {
              }else if () {
              }
              return resp;
        }
        }
        Servlet Code:
        Code:
        public class SupportServlet extends HttpServlet {
              String xmlString = //Same xmlString as shown above;
              protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                DataSource ds;
        	ds = DataSource.fromXML(xmlString);
        	JSTranslater jst = new JSTranslater();
        	String js = jst.toJS(ds);
        	response.getWriter().write(js);
        }
        }
        Accordingly things have been changed in web.xml and .html files as specified in previous posts.

        Now this servlet will call once the application starts after that it will not be called again. Now if i want to update the whole xmlString then where to change the XML Description? (in IDACall or should i use another way?)

        As my requirement is for dynamic modelling. On click of menu Item new ListGrid will be generated for that selection (fields will be fetched from backend (Google App Engine)).

        That mean for each menu Item selection there will be new datasource description needed which must be generated dynamically.

        Now how to update the datasource description on each call? Above is the code created till now. I want to update the fields on every call.

        If possible please share your code so it can be much helpful.

        Comment


          #49
          In that case I think you'd be better off creating a new DataSource in client side code rather than trying to use the IDACall logic that retrieves DataSource.ds.xml files from the server. Something like this ...
          Code:
          myDS = new DataSource();
          DataSourceField fieldA = new DataSourceField("fieldA", FieldType.TEXT, "Field A");
          myDS.addField(fieldA);
          myDS.setDbName("whatever");
          etc.
          Once you create it you can assign it to new UI widgets and issue calls to myDS.fetchData(), etc. A DataSource is just an object that defines how the client should make calls to the server and what data structures are exchanged in the process (the DataSourceFields). If you want to use the built-in SmartClient server side features in the Pro or EE edition you would use myDS.setDataFormat("iscServer") and myDS.setServerType("sql"), etc. Otherwise you can specify your own serverConstructor class and do whatever you need.

          I've done similar things with client only data sources but I assume the same technique would work for server-based data sources.

          Comment


            #50
            @Jay,

            Thanks for quick reply. Now i have shifted the DataSource Fields on client side as per your instruction and it is working fine.

            As now datasource defined on client side only how ListGrid.saveData() will add data on server or how fetch, remove, update operations will be done?

            Should i override transformRequest() method?

            Comment


              #51
              Read up on data source operation bindings. That is the mechanism for specifying how the data source should handle the fetch, update, add, remove operations. Also dataFormat and serverType settings on the data source. You're now heading into a direction where I have little experience so I won't be able to give you much more help.

              Comment


                #52
                Originally posted by Isomorphic
                That's correct. Authentication checks both happen prior to DataSource.execute() in the request processing flow, because programmatically issued server-side DSRequests should be able to bypass authentication.
                I'm finally getting around to using this dynamically constructed datasource in server side code and find that it isn't working. On the server side, when I use com.isomorphic.datasource.DSRequest("MyDataSource", "fetch") and execute the request only fetches the fields that are in the base ds.xml.

                How do I get the server side code to load my modified ds.xml?

                Comment


                  #53
                  If you have both a .ds.xml file and a different, expanded DataSource definition for dynamic use, when you create a DSRequest, pass it directly to DataSource.execute() rather than calling dsRequest.execute(). The latter approach is going to look up the saved .ds.xml file, as you experienced.

                  Comment


                    #54
                    Thanks for the lightning fast response. That did the trick.

                    Comment


                      #55
                      One more question. In this particular case I needed to fetch a record from the same DataSource the code was in, so I could just do this.execute(dsRequest)

                      But how do I get an instance of a DataSource in server side code in a way that will use my custom serverConstructor. On the client side there is DataSource.get("dsname"). On the server side I suppose I could use com.isomorphic.datasource.DataSource.fromXML() and call my custom method that returns the modified XML.

                      But what is the DataSource.forName() method. It isn't in the javadocs. Is that something I should use? I'd like to find a way to instantiate DataSource on the server side that is consistent whether the datasource is "dynamic" or not so the code that uses it doesn't have to know.

                      Comment


                        #56
                        Just call your custom method that produces the DataSource via fromXML(), and, if you find the need, take whatever caching approach you like (this is unlikely to be necessary except at very high volume). DataSource.forName() has lifecycle semantics that have not been explained well enough for it to be externally used yet.

                        Comment


                          #57
                          How to see dynamically inserted fields in a data source?

                          Dear isomorphic,

                          Can you elborate you comment in #53?

                          Originally posted by Isomorphic View Post
                          If you have both a .ds.xml file and a different, expanded DataSource definition for dynamic use, when you create a DSRequest, pass it directly to DataSource.execute() rather than calling dsRequest.execute(). The latter approach is going to look up the saved .ds.xml file, as you experienced.
                          I presume you are talking about something like what is shown in #7 (done in a the method handleDSReqeuest() of a subclass of IDACall).

                          Code:
                          public class ItemMasterDS extends IDACall {
                          	/**
                          	 * 
                          	 */
                          	private static final long serialVersionUID = -1483088157905503631L;
                          
                          	public DSResponse handleDSRequest(DSRequest dsRequest,
                                      RPCManager rpc,
                                      RequestContext context)
                                        throws java.lang.Exception {
                          		DSResponse resp = new DSResponse();
                          		DataSource ds = DataSource.fromXML(new FileReader("IPItemMasterDS.ds.xml"));
                          		resp = ds.execute(dsRequest);
                          		return resp;
                          	}
                          }
                          However, later in #31, Jay concluded that instead of calling ds.execute(dsRequest), (in order to resuce the logic to handle 'requiresAuthentication' ) it is better to call simply

                          Code:
                          dsRequest.setDataSource(ds);
                          return super.handleDSRequest(dsRequest, rpc, context);
                          (In fact, only the latter version worked for me (the first version would give me NullPointerException when my databound visual component tried to access the database))

                          But then in this latter version, how do we pass "(a newly created) DSRequest to DataSource.execute() rather than calling dsRequest.execute()".

                          Thanks! This thread has been VERY USEFUL for me so far.

                          Comment

                          Working...
                          X