Announcement

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

  • leeyuiwah
    replied
    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.

    Leave a comment:


  • Isomorphic
    replied
    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.

    Leave a comment:


  • jay.l.fisher
    replied
    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.

    Leave a comment:


  • jay.l.fisher
    replied
    Thanks for the lightning fast response. That did the trick.

    Leave a comment:


  • Isomorphic
    replied
    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.

    Leave a comment:


  • jay.l.fisher
    replied
    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?

    Leave a comment:


  • jay.l.fisher
    replied
    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.

    Leave a comment:


  • webashlar
    replied
    @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?

    Leave a comment:


  • jay.l.fisher
    replied
    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.

    Leave a comment:


  • webashlar
    replied
    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.

    Leave a comment:


  • webashlar
    replied
    @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.

    Leave a comment:


  • webashlar
    replied
    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.

    Leave a comment:


  • jay.l.fisher
    replied
    The first thing that stands out in your second set of examples is that you appear to be creating the DataSource javascript from an empty string. ??

    String xmlString = "";
    DataSource ds = DataSource.fromXML(xmlString);

    In your first example, as Isomorphic pointed out, you have no dataFormat or serverType specified so, although your data source has fields defined there are no operation bindings so it can't provide the standard fetch, update, remove or add methods.

    Leave a comment:


  • webashlar
    replied
    @jay.l.fisher
    @rathiandi

    Hello,

    Hoping for your valuable inputs also so i can get through this trivial but irritating problem.

    May be your already created code can help me out.

    Leave a comment:


  • webashlar
    replied
    Originally posted by Isomorphic
    Sorry, this code appears to be nonsense - follow the sample instead.
    Thanks for concern i will surely look after this trainings.

    But can you please tell why code appears to be nonsense? So i can update the code and release here.

    And i think it will be good for other developers also who can make same mistakes.

    Leave a comment:

Working...
X