No way to remove a parameter from the URL?

606 views
Skip to first unread message

Benjamin Makus

unread,
Dec 2, 2012, 11:56:51 AM12/2/12
to gwt-pl...@googlegroups.com
Hi,

I haven't found a way to remove parameters from the URL using "updateHistory(...)" or have I missed something?
It should be added to GWTP, that if you set ".with("param", null)" the parameter should get deleted.


Thank you.

Maurice

unread,
Dec 2, 2012, 9:46:45 PM12/2/12
to gwt-pl...@googlegroups.com
I have not found a way either.  I just wrote a function.










        /**


         * Removes the parameter from the placeRequest


         * @param placeRequest


         * @param parameter to be removed from placeRequest


         * @return


         */


        public static PlaceRequest removeParameter(final PlaceRequest placeRequest,


                        final String parameter){


               


                //Sanity checks


                assert( placeRequest != null ) : "placeRequest cannot be null";


                assert( parameter != null ) : "parameter cannot be null";


               


               


                // Create return object


                PlaceRequest rtn = new PlaceRequest( placeRequest.getNameToken() );


               


                // Gets all the parameters names


                Set<String> set = placeRequest.getParameterNames();


                if( set != null ){


                        for( String key : set){


                                // Add parameter to rtn as long as its not the parameter to remove


                                if( !key.equals(parameter) ){


                                        // Value


                                        String val = placeRequest.getParameter(key, null);


                                        // Add


                                        rtn = rtn.with(key, val);


                                }


                        }


                }


               


               


                return rtn;


        }


Cheers,
Maurice

Sydney

unread,
Dec 3, 2012, 1:46:25 AM12/3/12
to gwt-pl...@googlegroups.com
Could you describe a test case? Why do you need to remove the parameter, could you just ignore it?

Benjamin Makus

unread,
Dec 3, 2012, 4:30:02 AM12/3/12
to gwt-pl...@googlegroups.com
First: User experience.

Second (but more important): How should I be able to ignore a parameter, if I cannot delete it?



Example 1: You have a TextBox that should display the content of an URL param. And it should be hidden if no URL param is set. This means, that "" is a valid value to display the TextBox.
So I'm not able to 1. show the TextBox and 2. remove the TextBox and 3. to give the URL to a friend. 'cause he will see the TextBox


Example 2: In my application I have an Enum, which tells if I want to use Google Maps, Bing or OpenStreetMap. But if the parameter isn't set, I don't want to display any map. And in my opinion it would be pretty ugly to extend the Enum with a 4th entry called "NO".

Sydney

unread,
Dec 3, 2012, 5:03:29 AM12/3/12
to gwt-pl...@googlegroups.com

To me you process a PlaceRequest in prepareFromRequest. If you have a parameter that you need to remove, it means that the PlaceRequest contains wrong information. Why do you have the parameter you want to delete in your PlaceRequest? I don't understand the need to remove a parameter from a PlaceRequest. Why don't you create a new PlaceRequest containing only the parameter you need. If you don't want to display the TextBox, create a PlaceRequest without the url param.

Message has been deleted

Benjamin Makus

unread,
Dec 3, 2012, 6:33:23 AM12/3/12
to gwt-pl...@googlegroups.com
Ah sorry. I should explain to you how I process parameter handling :D
So here's the (hopefully) full example:


1. prepareFromRequest: As usual: check all the URL parameters and display the stuff according to their values
1.1 Here it gets for example the "map" parameter, that gets converted to an Enum:
enum Map { GOOGLE, BING, OSM }

2. My view has a ListBox to set the displayed map. Values: ["---", "Google Maps", "Bing", "OSM"]

3. User selects "GoogleMaps". => Presenter receives onMapSelection(Map.GOOGLE)
4. Presenter sets the URL parameter .with("map","google") and tells the view to display Google Maps

5. User selects "---". => Presenter receives onMapSelection(null)
6. Here the Presenter should remove the URL parameter. And it tells the view to setInSlot(SLOT_MAP, null);

I have also several other URL parameters that should stay. I just want to remove this one.


Maybe I've misunderstood some of the usual practices using URL params. If that's true, please tell me the right way to handle them.


Thank you

Christian Goudreau

unread,
Dec 9, 2012, 11:47:06 AM12/9/12
to gwt-pl...@googlegroups.com
The placerequest should be build at the moment you select something in your listbox and then use that new placerequest that you just have build and reveal it through the placemanager.

You also have to update existing links through this mechanism


--
 
 



--
Christian Goudreau
Reply all
Reply to author
Forward
0 new messages