开发者

Passing beans between viewImpl and place in GWT

开发者 https://www.devze.com 2023-04-12 05:51 出处:网络
I am using MVP architecture and am trying to track the click event on a GWT cellTAble. 1.I have one ConfigureViewImpl class which has ConfigurePlace as a Place.

I am using MVP architecture and am trying to track the click event on a GWT cellTAble.

1.I have one ConfigureViewImpl class which has ConfigurePlace as a Place.

2.ValidationViewImpl class which has ValidationPlace as a Place.

I have One table in ConfigueViewImpl.On the click of one of its columns , another place(ValidationPlace) should arrive in order to navigate to other page.But I have to track the click event of the particular row. For this I am trying to pass the Bean but without any sucess.

    final CellTable<UserBean> configGrid= new CellTable<UserBean>(5,(Resources) GWT.create(TableResources.class));
    final SingleSelectionModel<UserBean> selectionModel = new SingleSelectionModel<UserBean>();
    claimsGrid.setSelectionModel(selectionModel,
            DefaultSelectionEventManager.<UserBean> createDefaultManager());


    Column<UserBean, String> action = new Column<UserBean, String>(new ButtonCell()) {
        @Override
        public String getValue(UserBean object) {
            // Get the value from the selection model.
            return"images/edit.png";
        }

    };  
    configGrid.addColumn(action,"Action");
    action.setFieldUpdater(new FieldUpdater<UserBean, String>() {

        public void update(int index, UserBean object, String value) {
        //need to pass the bean 'object'
                     listener.goTo(new ValidationPlace());
        }
    }); 

I need to pass 'UserBean object' as an argument to ValidationPlace() but GWT is not allowing to pass the bean parame开发者_Go百科ters as it allows only String as tokens.Is there a way through which I can track the click event and pass the info to next page.Any suggestions appreciated.Thanks in advance.


You're almost there - you simply need to pass your beans into your place and then generate a token from those.

Something like this

public class ValidationPlace extends Place {

    private final UserBean userBean;

    public ValidationPlace(UserBean userBean) {

        this.userBean = userBean;
    }

    public UserBean getUserBean() {

        return userBean;
    }

    public static class Tokenizer implements PlaceTokenizer<ValidationPlace> {

        @Override
        public String getToken(ValidationPlace place) {

            return "name=" + userBean.getName();
        }

        @Override
        public ValidationPlace getPlace(String token) {

            // parse token into user bean and return new place
            return new ValidationPlace(createFromToken(token));
        }
    }
}

public static final UserBean createFromToken(String token) {
    Map<String, String> params = simpleParse(token);
    return new UserBean(params.get("name"), params.get("xyz"), ...);
}


public static final Map<String, String> simpleParse(String token) {

    Map<String, String> map = new HashMap<String, String>();
    if (token != null) {
        String[] params = token.split("&");
        for (String param : params) {
            String[] keyValues = param.split("=");
            if (keyValues.length > 1) {
                map.put(keyValues[0], keyValues[1]);
            }
        }
    }
    return map;
}

The parameter parsing is very naive and doesn't handle escaping, &., = etc but generally suffices.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号