来自@OneToOne的GWT新EntityProxy与来自服务器的另一个EntityProxy

时间:2012-02-26 01:56:51

标签: gwt

我只是在创建一个新的代理:

     LayoutExampleRequest r = requestFactory.employeeRequest();
     DepartmentProxy d  = r.create(DepartmentProxy.class);
     r.save(d);
     departmentEditor.editProxy(d, r);

然后将Proxy和Request(LayoutExampleRequest)传递给我的编辑器

      driver.edit(proxy, request);

直到这里!一切都如预期的那样有效。我可以使用null EmployeeProxy保存Department对象。现在我从服务器获得了一个建议框Proxys of EmployeeProxy。

        search = new SuggestBox(new SuggestOracle() {
        @Override
        public void requestSuggestions(final Request request,final Callback callback) {
            System.out.println(request.getQuery());

            //ignore less than 3
            if(request.getQuery().length() > 3){
                 requestFactory.employeeRequest().search(request.getQuery()).fire(new Receiver<List<EmployeeProxy>>(){
                    @Override
                    public void onSuccess(List<EmployeeProxy> response) {

                        List<MySuggestion<EmployeeProxy>> suggestions = new ArrayList<MySuggestion<EmployeeProxy>>();
                        for(EmployeeProxy e:response){
                            MySuggestion<EmployeeProxy> suggestion = new MySuggestion<EmployeeProxy>();
                            suggestion.setModel(e,e.getFirstName(),e.getFirstName()+" "+e.getLastName());
                            suggestions.add(suggestion);
                        }
                        callback.onSuggestionsReady(request, new Response(suggestions));
                    }
                 });
            }
        }
    });

MySuggestion是一个处理EmployeeProxy的包装类。

现在我想将这个EmployeeProxy添加到我的DeparmentProxy,因为我在JPA上有一个@OneToOne。

        search.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {

        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {             
            MySuggestion<EmployeeProxy> s = (MySuggestion<EmployeeProxy>)event.getSelectedItem();
            proxy.setSupervisor(s.getModel());
        }
    });

代理是部门的EntityProxy(我发送给我的编辑器)driver.edit(代理,请求);

然后我解雇了司机:

              departmentEditor.getDriver().flush().fire(new Receiver<Void>() {
        @Override
        public void onSuccess(Void response) {
            Window.alert("Success");


            // refresh the datagrid
            Range range = dataGrid.getVisibleRange();
            dataGrid.setVisibleRangeAndClearData(range, true); //1st way

                            // create a new DepartmentProxy to bind to the Editor.
            createProxy();

            // change button text
            updateButton.setText("Save");

        }
        @Override
        public void onConstraintViolation(Set<ConstraintViolation<?>> violations) {
            for(ConstraintViolation v :violations){
                Window.alert(v.getMessage()+" "+v.getPropertyPath());
            }

        }

        @Override
        public void onFailure(ServerFailure error) {
            Window.alert(error.getMessage());
        }
    });

问题是我从EmployeeProxy获取ConstraintViolations,就像是EmployeeProxy的驱动程序,但是具有空值。 (我用JSR-330验证我的实体)

不知道如何与服务器上的其他代理建立新代理关系。在@OneToOne关系中

任何帮助都会很好!

谢谢

/ *更新* / 这样的东西,但有编辑

            final LayoutExampleRequest r = requestFactory.employeeRequest();
    final DepartmentProxy d  = r.create(DepartmentProxy.class);

    d.setName("Name");
    d.setService(Service.CONTRACT_MANAGMENT);
    // get some random employee
    requestFactory.employeeRequest().findById(1).fire(new Receiver<EmployeeProxy>() {

        @Override
        public void onSuccess(EmployeeProxy response) {
            d.setSupervisor(response);
            r.save(d).fire(new Receiver<DepartmentProxy>() {

                @Override
                public void onSuccess(DepartmentProxy response) {
                    Window.alert("Kidding me! why editor cant get it work =p?");
                }
            });
        }
    });

1 个答案:

答案 0 :(得分:0)

问题是我把它放在了EmployeeProxy的编辑器属性上,所以当用户选择就业时会看到有关它的信息,所以我删除它们然后再做同样的工作。现在可以正常工作。

当GWT从编辑器上的另一个代理检测到属性时,就像GWT一样认为你会填充它。这一行:

proxy.setSupervisor(s.getModel());

不起作用。