2014-02-10 1 views
1

Request Factory의 dynatableref 예제로 시작했습니다. 요청 공장 문서를 읽습니다. 하지만 여전히 서버에 대한 클라이언트의 라이프 사이클이나 흐름에 대해 명확하지 않습니다. 서버를 호출하고 싶습니다. 데이터를 삽입하고 그리드를 업데이트하십시오. RPC 호출은 쉽습니다. 하지만 Request Factory를 사용하는 방법을 이해할 수 없습니다. 이것은 요청 팩토리의 한 방법입니다. 자동으로 서버의 persist 메소드를 호출합니다. 그리드도 자동으로 새로 고침됩니다. 아무도 그것이 어떻게 작동하는지 말할 수 있습니까?요청 팩토리를 사용하여 개체를 저장/편집하고 DataGrid를 새로 고치는 방법

context.fire(new Receiver<Void>() { 
     @Override 
     public void onConstraintViolation(Set<ConstraintViolation<?>> errors) { 
     // Otherwise, show ConstraintViolations in the UI 
     dialog.setText("Errors detected on the server"); 
     editorDriver.setConstraintViolations(errors); 
     } 

     @Override 
     public void onSuccess(Void response) { 
     // If everything went as planned, just dismiss the dialog box 
     dialog.hide(); 
     } 
    }); 

그리드에도 일부 데이터를 편집하고 싶습니다. 이 방법이 나를 도울까요? 또는 다른 방법을 써야합니다. 나는

requestFactory.schoolCalendarRequest().savePerson(personProxy).fire(new Receiver<PersonProxy>() { 
     @Override 
     public void onSuccess(PersonProxy person) { 
      // Re-check offset in case of changes while waiting for data 
      dialog.hide(); 
     } 
     }); 

처럼 다른 방법을 쓴이 상쾌한 격자 없습니다. 왜?

답변

1

RuequestFactory의 흐름은 클라이언트 - 서버 RPC 비슷하거나이 요청 XMLHTTP

1)는 서버에서 원격 메소드를 호출한다.

2) Receiver 개체 (Callback 개체)에서 응답을받습니다. 에서 모두가 잘되면 onSeccess 메서드는 반환 된 개체를 얻을. onFailure 뭔가 잘못되었을 때 오류가 발생합니다.

그래서 당신은 사람을 편집 할 때 코드가 초기화 될 때까지 같은 RequestContext을 사용하는 것이 중요합니다 (예 : 이름) 이제이

requestFactory.schoolCalendarRequest().getPersonList(param1).fire(new Receiver<List<PersonProxy>>() { 
    @Override 
    public void onSuccess(List<PersonProxy> personList) { 
     personTable.getDataProvider().setList(personList); 
    } 
    }); 

처럼 보일 것이다 서버에서 검색 데이터로부터 Person 테이블을 채 웁니다 요청시 fire으로 전화하십시오. 그래서 당신은 그 사람의 이름을 업데이트하는 부분은 아마 MVP 패턴을 구현하는 것을 고려해야 있도록 RequestFactory과의 상호 작용이 Presenter에 배치해야이

column.setFieldUpdater(new FieldUpdater<Person, String>() { 
    @Override 
    public void update(PersonProxy personProxy, String value) { 
    RequestContext requestContext = requestFactory.schoolCalendarRequest() 
    PersonProxy personProxy= requestContext.edit(personProxy); 
    personProxy.setName(value); 
     requestFactory.schoolCalendarRequest().savePerson(personProxy).fire(new Receiver<PersonProxy>() { 
     @Override 
     public void onSuccess(PersonProxy person) { 
      //Do something after the update 
     } 
     }); 
     } 
    }); 

처럼 보일 것이다.

관련 문제