Announcement

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

    How can I improve my SmartGWT LGPL ListGrid server connection/Datasource?

    To expand my question, you could say that I want to program in SmartGWT instead of programming into SmartGWT ( http://msmvps.com/blogs/jon_skeet/archive/2008/04/23/programming-quot-in-quot-a-language-vs-programming-quot-into-quot-a-language.aspx ).

    I have a 2 column ListGrid, populated with data from the 5 column database table. I don't use a DataSource (more on that later), instead I get the data from the async service and populate it on success like this
    Code:
    predmetiGrid.setData(PredmetRecord.convertToContractRecordArray(result));
    . The user can edit the data and press the Save button to save it. The way I have implemented the save is:
    Code:
        // repeat this for each edited field 
        for (int i=0; i < predmetiGrid.getAllEditRows().length; i++){
    			
    			int editedRowIndex = predmetiGrid.getAllEditRows()[i];
                
                // for each edite get the full record
    
    			PredmetRecord editedRecord = (PredmetRecord)predmetiGrid.getRecord(editedRowIndex);
    
    			// create a new DomainObject - Predmet, and set the ID from the 
                // Row so I have the ID to use for update later
    
    			Integer predmetID = editedRecord.getAttributeAsInt("predmetID");
    			Predmet predmet = new Predmet(predmetID);
    
    			// fill Predmet object with either the edited value, or the
                // original value (if only one of the fields was changed and not both)
    
    			String editedNazivPredmeta = (String)predmetiGrid.getEditValues(editedRecord).get("nazivPredmeta");
    			boolean isNazivChanged = editedNazivPredmeta != null;
    			if (!isNazivChanged){
    				editedNazivPredmeta = editedRecord.getAttribute("nazivPredmeta");
    			} 
    			predmet.setNazivPredmeta(editedNazivPredmeta);
    			
    			String editedOpisPredmeta = (String) predmetiGrid.getEditValues(editedRecord).get("opisPredmeta");
    			boolean isOpisChanged = editedOpisPredmeta != null;
    			if (!isOpisChanged){
    				editedOpisPredmeta = editedRecord.getAttribute("opisPredmeta");
    			}
    			predmet.setOpisPredmeta(editedOpisPredmeta);
    			
    			predmetiList.add(predmet);
    			
    		}
    In another method I call the async service:
    Code:
    	public void updatePredmeti(List<Predmet> predmeti) throws RpcException, IllegalArgumentException {
    		
    		for (int i=0; i<predmeti.size();i++){
    			JdbcPredgledPredmetaDAO.getInstance().updatePredmet(predmeti.get(i));
    		}
    		
    	}
    Now there are a few problems with this implementation. The most obvious ones are:

    a) I'm not using a Datasource conected with the ListGrid. I don't use it because I don't understand how to use it in my case since the examples are written either for an XML DataSource or for the SmartGWT Pro (or higher) integrated server.

    b) The async method needs to have a rollback mechanism if one of the inserts fail, though there could be a smarter implementation of this (e.g. do all inserts in one transaction).

    c) I'm "hacking" to get and update the data instead of using object methods/properties but this is, currently, the best I got form the JavaDoc; I'd prefer to see best practice way to write this and learn

    I'm using SmartGWT LGPL 3.0, Tomcat 7.0, Java 1.6

    #2
    Did I make the questions too difficult to understand or is there another problem? The question doesn't seem obscure or not worth answering, though I could be wrong.

    Comment


      #3
      You're posting in the wrong forum (we'll move the thread).

      You need to read the QuickStart Guide as you have giant misconceptions about DataSources. You need to be using them.

      You should read the FAQ about why you shouldn't use GWT-RPC.

      Comment


        #4
        Originally posted by Isomorphic View Post
        You're posting in the wrong forum (we'll move the thread).

        You need to read the QuickStart Guide as you have giant misconceptions about DataSources. You need to be using them.

        You should read the FAQ about why you shouldn't use GWT-RPC.
        I apologize, I thought about where to post, but I guess I thought wrong.

        I've read the Quickstart guide a few times, both the Javascript and Java version and I'm "stuck". Rereading won't help me, I need someone to point me a bit more specific in the right way, but thank you anyway. if

        I'll reread the FAQ though - I'm using the RPC because that's the only implementation I've managed to find that I could implement.

        Comment

        Working...
        X