Search code examples
gwtrpcsmartgwt

GWT how to pass form parameters to server


which are the steps to pass form parameters with rpc to service implemantation ? Bassicaly for now I have these steps , but I have always null for p1(for username) and p2(for password) values passed when calling

userService.createUser(p1,p2,callback):

My code:

 /**
 * Overlay form
 * 
 * @return
 */
public Canvas getViewPanel() {

    IButton buttonShowWindow = new IButton("Show Window");

    final DynamicForm form = new DynamicForm();
    final TextItem emailItem = new TextItem();
    final PasswordItem passwordItem = new PasswordItem();
    final PasswordItem password2Item = new PasswordItem();

    buttonShowWindow.setShowRollOver(true);
    buttonShowWindow.setShowDown(true);
    buttonShowWindow.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            final Window winModal = new Window();
            winModal.setWidth(360);
            winModal.setHeight(200);
            winModal.setTitle("Modal Window");
            winModal.setShowMinimizeButton(false);
            winModal.setIsModal(true);
            winModal.setShowModalMask(true);
            winModal.centerInPage();
            winModal.addCloseClickHandler(new CloseClickHandler() {
                public void onCloseClick(CloseClickEvent event) {
                    winModal.destroy();
                }
            });
            HLayout layout = new HLayout(20);


            form.setWidth(250);

            final TextItem usernameItem = new TextItem();
            usernameItem.setTitle("Username");
            usernameItem.setRequired(true);

            emailItem.setTitle("Email");
            emailItem.setRequired(true);

            passwordItem.setTitle("Password");
            passwordItem.setRequired(true);

            password2Item.setTitle("Password again");
            password2Item.setRequired(true);
            password2Item.setType("password");

            IButton submit = new IButton();
            submit.setTitle("subscribe");

            final AsyncCallback callback = new AsyncCallback<String>() {

                public void onSuccess(String result) {
                    // TODO Auto-generated method stub

                }

                public void onFailure(Throwable caught) {
                    // TODO Auto-generated method stub

                }
            };

            submit.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    // vm.validate();
                    if (form.hasErrors()) {
                        // TODO some message to the user
                    } else {
                        userService.createUser(usernameItem.getValueField(), passwordItem.getValueField(),callback);

                    }
                }
            });
            form.setFields(new FormItem[] { usernameItem, emailItem, passwordItem, password2Item });
            winModal.addItem(form);
            winModal.addItem(submit);
            winModal.show();
        }
    });

    HStack layoutTopRow = new HStack(10);
    layoutTopRow.setHeight(50);

    VLayout layoutMain = new VLayout();
    layoutMain.addMember(layoutTopRow);
    layoutMain.addMember(buttonShowWindow);

    return layoutMain;
}

Thanks


Solution

  • Use

    userService.createUser(usernameItem.getValue(), passwordItem.getValue(),callback);
    

    instead of

    userService.createUser(usernameItem.getValueField(), passwordItem.getValueField(),callback);
    

    For more info read about FormItem.getValueField().