2011-12-10 55 views
0

在更新期間,具有編輯器框架的實體從db調用中選擇兩次。 可能這不是問題,而是編輯器框架的一個特性?GWT編輯器:在更新前選擇兩次調用

下面的代碼片段:

public class UserActivity extends BasicActivity<UserActivity.Display> { 

... 

interface Driver extends RequestFactoryEditorDriver<UserProxy, UserPanel> { 
} 

private UserProxy user; 

private Driver driver; 

@Inject 
private Provider<UserRequestContext> userContextProvider; 

... 

@Inject 
public UserActivity(EventBus eventBus, Display display, PlaceController placeController, WmsRequestFactory requestFactory) { 

    super(display, eventBus, placeController); 

    driver = GWT.create(Driver.class); 
    driver.initialize(requestFactory, (UserPanel) display); 

} 

... 

@Override 
protected void onBind() { 

    UserRequestContext userRequestContext = userContextProvider.get(); 

    userRequestContext.updateUser(user); 

    driver.edit(user, userRequestContext); 

    registerHandler(display.getSaveButton().addClickHandler(
      new ClickHandler() { 
       public void onClick(ClickEvent event) { 

        RequestContext context = driver.flush(); 

        // Check for errors 
        if (driver.hasErrors()) { 
         display.getStatus().setHTML(
           "<b>Errors detected locally</b>"); 
         return; 
        } 

        // Send the request 
        context.fire(); 

       } 
      })); 

    ... 

休眠輸出保存按鈕後點擊:

[INFO] Hibernate: select user0_.ID as ID1_0_, user0_.CREATED as CREATED1_0_, user0_.MODIFIED as MODIFIED1_0_, user0_.version as version1_0_, user0_.BIRTH_DATE 
as BIRTH5_1_0_, user0_.EMAIL as EMAIL1_0_, user0_.FIRST_NAME as FIRST7_1_0_, user0_.LAST_NAME as LAST8_1_0_, user0_.LOGIN as LOGIN1_0_, user0_.PASSWORD as PASS 
WORD1_0_ from USER user0_ where user0_.ID=? 

[INFO] Hibernate: select user0_.ID as ID1_0_, user0_.CREATED as CREATED1_0_, user0_.MODIFIED as MODIFIED1_0_, user0_.version as version1_0_, user0_.BIRTH_DATE 
as BIRTH5_1_0_, user0_.EMAIL as EMAIL1_0_, user0_.FIRST_NAME as FIRST7_1_0_, user0_.LAST_NAME as LAST8_1_0_, user0_.LOGIN as LOGIN1_0_, user0_.PASSWORD as PASS 
WORD1_0_ from USER user0_ where user0_.ID=? 

[INFO] Hibernate: update USER set MODIFIED=?, version=?, BIRTH_DATE=?, EMAIL=?, FIRST_NAME=?, LAST_NAME=?, LOGIN=?, PASSWORD=? where ID=? and version=? 

它是正常的嗎?

回答

0

回答關於谷歌的GWT集團:https://groups.google.com/d/msg/google-web-toolkit/T4N1puddcS4/vV1wYZ6n9EUJ

複製在這裏以供參考和方便:

首先,這有什麼好做的編輯框架,但RequestFactory。

如果你不使用Locator,或者你不重寫你的LocatorisLive()方法,那麼這是預期的行爲:這是RequestFactory如何確定一個實體是否仍然「活着」發送響應之前,給客戶。如果不是,那麼它會告訴客戶該實體已被刪除(在EventBus上發送EntityProxyChange事件,並使用WriteOperation.DELETED)。 isLive(entity)的默認實現爲find(entity.get()) != null,這也是在實體不存在Locator時發生的情況(不同之處在於使用Locator可以重寫isLive()以更改默認實現,例如更優化的實現)。