1. #1
    Ext User
    Join Date
    Jan 2009
    Posts
    3
    Vote Rating
    0
    bgranvea is on a distinguished road

      0  

    Default Hibernate integration: CRUD operations

    Hibernate integration: CRUD operations


    Hi,

    I would like to load my Hibernate objets in an editable Grid or a Tree and send the changes (updates/deletion/insertion) back to the server. I'm not sure what is the best way to do this with GXT.

    I've played a little bit with SmartGWT and they have a nice concept of Datasource which encapsulates the CRUD operations. You just have to implement a RPCDatasource and to give it to a grid.

    I don't see the equivalent of this in GXT.

    There is the RpcProxy but AFAIK it only handles loading of remote objects. I've seen that there is a StoreListener to be notified of the modifications in the local store and send them to the backend, is that the way to go?

    Of course, I don't want to send directly my persistent objects. I've implemented all the necessary DTOs.

    Thanks for your help.

  2. #2
    Ext User
    Join Date
    Dec 2009
    Location
    Beijing, China
    Posts
    8
    Vote Rating
    0
    jackielii is on a distinguished road

      0  

    Default


    I have the same question.

  3. #3
    Ext User danielbertini's Avatar
    Join Date
    Oct 2007
    Posts
    77
    Vote Rating
    0
    danielbertini is on a distinguished road

      0  

    Default


    Anyone can help?

  4. #4
    Ext GWT Premium Member
    Join Date
    Jul 2009
    Posts
    80
    Vote Rating
    0
    terciofilho is on a distinguished road

      0  

    Default


    The Grid itself is just a Render. You have to work directly inside a Store.

    In your store you have a Loader, that is responsible to load the Store Data. This is easy, just implement a RpcProxy and you are done.

    To work with modifications, like insert, update and delete, you must implement the way is more easy to you.

    I'll explain my implementation

    I have a object MyStore, that extends a ListStore<ModelData>. In this store I set a Loader(With a RpcProxy), so it can be loaded without any work.

    To insert a record I have a Toolbar with a New Record button that call this method in MyStore:

    Code:
    	public ModelData createNewRecord()
    	{
    		final ModelData modelData = new ModelData();
    		this.store.insert(modelData, 0);
    		// I create a field(That I use as Primary Key) just to flag this modelData as Dirty, so I know it's a new one.
    		final Record record = this.store.getRecord(modelData);
    		record.beginEdit();
    		record.set(RecordConstant.PRIMARY_KEY, null);
    		record.endEdit();
    		return modelData;
    	}

    This will create an empty ModelData, and will return it, so I can start editing by doing this(I use a Row Editor):

    Code:
    int modelIndex = this.store.indexOf(this.store.createNewRecord());
    this.rowEditor.startEditing(modelIndex, false);
    Well, this will start editing this new record.

    To save the modified records I do this(I use the Command Pattern, so I wrap the action inside an Action object):

    Code:
    	public void saveModifiedRecords(final AsyncCallback<Integer> callback)
    	{
    		if (callback == null)
    		{
    			throw new IllegalArgumentException("callback cannot be null!");
    		}
    
    		final List<Action<?>> actions = new ArrayList<Action<?>>();
    
    		// Create an SaveStoreAction for every modified Record
    		final List<Record> modifiedRecords = this.store.getModifiedRecords();
    		if (modifiedRecords.size() > 0)
    		{
    			for (final Record record : modifiedRecords)
    			{
    				final int documentId = this.document.getId();
    				actions.add(new SaveStoreAction(documentId, this.parentModelData, (ModelData) record.getModel()));
    			}
    
    			// Create a Batch Action
    			final BatchAction batchAction = new BatchAction(OnExceptionType.IGNORE, actions);
    
    			this.actionService.executeAction(batchAction, new AsyncCallback<BatchResponse>()
    			{
    				public void onFailure(final Throwable caught)
    				{
    					// Action failed!
    					callback.onFailure(caught);
    				}
    
    				public void onSuccess(final BatchResponse result)
    				{
    					int unsavedRecords = 0;
    					for (int i = 0; i < result.getResponses().size(); i++)
    					{
    						final SaveStoreResponse saveResponse = (SaveStoreResponse) result.getResponses().get(i);
    						final Exception saveException = result.getExceptions().get(i);
    						// If no Exception, commit the modification
    						if (saveException == null)
    						{
    							final Record record = modifiedRecords.get(i);
    							record.commit(false);
    						}
    						else
    						{
    							unsavedRecords++;
    						}
    					}
    					callback.onSuccess(unsavedRecords);
    				}
    			});
    		}
    		else
    		{
    			// No Modified Records to save!
    		}
    	}
    This method when called, will create a Action object for every Modified Record in the Store, this Action is dispatched to the Server, that will update the Hibernate Objects based on the ModelData and will commit to Database, if an error occurs, the Action will return it to Client so the Client knows that that record has not been saved.

    The deletion is basically the same, but you send the "this.grid.getSelectionModel().getSelectedItem();" to the Server.

    Hope it helps.

  5. #5
    Ext User danielbertini's Avatar
    Join Date
    Oct 2007
    Posts
    77
    Vote Rating
    0
    danielbertini is on a distinguished road

      0  

    Default


    Hello terciofilho!
    Thank you for help!

  6. #6
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Exclamation press event of the "Save" button of the row editor

    press event of the "Save" button of the row editor


    Hi, when is called your save metod? Is it possible to call it on press event of the "Save" button of the row editor?
    Or what event is fired whe the "Save" button of the row editor is pressed?
    There are some example with a Save button on a toolbar on the bottom of the grid and use this to save data!
    I don't wont to use another button like this but just the "Save" button of the row editor!
    How can i catch with a listener the event of the "Save" button of the row editor like the following wrong example?

    Code:
    final RowEditor<RecapitiModel> re = new RowEditor<RecapitiModel>();
            re.setClicksToEdit(ClicksToEdit.TWO);
            re.addListener(Events.Submit, new Listener<BaseEvent>() {
                @Override
                public void handleEvent(BaseEvent be) {
                
            //call method to save modified data...
                    
                }
    There is any way to do it?
    Please help, Thanks

  7. #7
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    The RowEditor fires an Events.AfterEdit event editing.

  8. #8
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Default


    thanks, i will try!

  9. #9
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Default


    I have try this simple example but it doesn't works! It is correct? What is the problem?

    Code:
      
     final RowEditor<RecapitiModel> re = new RowEditor<RecapitiModel>();
            re.setClicksToEdit(ClicksToEdit.TWO);
            
            re.addListener(Events.AfterEdit, new Listener<BaseEvent>() {
    
                @Override
                public void handleEvent(BaseEvent be) {
                
                Window.alert("hello");
                    
                }
            });

    Thanks

  10. #10
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Default


    it works!

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar