Places & Activities any suggestion?

45 views
Skip to first unread message

Rohan Aggarwal

unread,
Oct 17, 2011, 12:34:59 PM10/17/11
to google-we...@googlegroups.com
Hi,


I am newbie to this group and new to GWT as well.  I am working on a project in that i am using GWT Places/Activities.   

I am not able to solve few issues which i think this group members can hhelp me out....

1. I am able to navigate between different pages

      http://VITS/welcome.html?Mechanical
      http://VITS/welcome.html?Chemical

I am able to navigate between these pages by annotating with PlaceTokenizer.

But my problem is if i want to navigate to student id in Mechanical branch how to register this parameter  in URL and also how to retrieve this parameter to retrieve details of the student in database.

      http://VITS/welcome.html?Mechanical:studentId=10&studentName=50


How to achieve this, please help i am struck here badly.

Here is the code below which i have wrritten...............


Rgds
Rohan

Jens

unread,
Oct 17, 2011, 1:37:44 PM10/17/11
to google-we...@googlegroups.com
Your MechanicalPlace should have a constructor like public Mechanical(Long studentId, Long studentName) along with the corresponding getters. In your PlaceTokenizer.getToken() for MechanicalPlace you build the string like "studentId=" + place.getStudentId() + "&studentName=" + place.getStudentName(); and in PlaceTokenizer.getPlace() you have to parse the provided token into its components and reconstruct the MechanicalPlace using the constructor above.

Then in your ActivityMapper you pass in the place to your activity so it can use the getters to get the stored information and fetch the data from database in its start() method.

-- J.

Rohan Aggarwal

unread,
Oct 17, 2011, 2:07:04 PM10/17/11
to google-we...@googlegroups.com
Thanks Jen and one more question.  I have a hyperlink eg:

Now the problem is i am trying to navigate when a user click on Hyperlink available in Mechnical (tab) to Chemical (tab)

Below is the snippet code, please let me know any issue with the code below

MechanicalActivity.java

....
public void start()  {

LayoutContainer c = new LayoutContainer();

        Hyperlink hyper =  new Hyperlink();
        hyper.setHTML("Navigate to Chemical");
        hyper.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
               PlaceController control = new PlaceController(eventBus);
               String token = "&id=2105&tabName=Chemical&Page=1";
               ChemicalPlace dh = new ChemicalPlace(token);
               control.goTo(dh);
               History.newItem(token);
//               event.preventDefault();

            }

        });

        c.add(new Text("Mechnical"));
        c.add(hyper);
        panel.setWidget(c);
}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/x4EsU-FOU7IJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Andrea Boscolo

unread,
Oct 17, 2011, 2:11:07 PM10/17/11
to google-we...@googlegroups.com

Rohan Aggarwal

unread,
Oct 17, 2011, 2:18:38 PM10/17/11
to google-we...@googlegroups.com
Andrew,

But this doesnt solve the problem, can anyone provide some insight into this.

Rgds
Rohan.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Aidan O'Kelly

unread,
Oct 17, 2011, 2:54:25 PM10/17/11
to google-we...@googlegroups.com

Your question is not exactly clear, but I'm pretty sure you shouldn't need to add click handlers to a Hyperlink object, or create entries in the History object yourself.  Just construct it with the Token you want to go to:

Hyperlink h = new Hyperlink("Navigate to Chemical", thePlaceToken);

And you shouldn't be building the token yourself. Thats whats Places are for. Once you've got your parsing/splitting of parameters working correctly (as I'm sure you have by this time. )  you should be constructing Places like this:

ChemicalPlace newPlace = new ChemicalPlace(2105, "Chemical", 1 );

Now, newPlace.getToken() should return something like: "&id=2105&tabName=Chemical&Page=1"

Thats not quite the *full* place URL that you need to pass to Hyperlink however, to get that you should use your PlaceHistoryMapper, this will prepend the PlaceName and the seperator to the token the place object returns.

String thePlaceToken = MyPlaceHistoryMapper.getToken(newPlace); // Will return 'ChemicalPlace:&id=2105&tabName=Chemical&Page=1'
...
Hyperlink link = new Hyperlink("Navigate to Chemical", thePlaceToken);

Rohan Aggarwal

unread,
Oct 17, 2011, 10:35:20 PM10/17/11
to google-we...@googlegroups.com
But when you click on the HyperLink it should fire 'ValueChangeEvent', if so how do we navigate

And the basic parsing of token and findout the place based by token, since entire parsing of the token will be done in Base Place class.

Please let me know with an example .




--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Aidan O'Kelly

unread,
Oct 18, 2011, 12:12:49 AM10/18/11
to google-we...@googlegroups.com
The Hyperlink object does not fire ValueChangeEvents, the History object does, but you probably don't need to listen for them, as your PlaceHistoryHandler is already listening for them. 


Rohan Aggarwal

unread,
Oct 18, 2011, 12:42:18 AM10/18/11
to google-we...@googlegroups.com
Thanks Kelly that sounds good.

Thanks
Rohan
Message has been deleted

-sowdri-

unread,
Oct 18, 2011, 1:09:39 AM10/18/11
to google-we...@googlegroups.com
Activities and Places are in first place to make navigation simple. 

To Navigate to other url on clicking a hyperlink. 

>> Hyperlink link = new Hyperlink("Navigate to Chemical", thePlaceToken);

Instead, 

Create a gwtanchor, and in the click handler, call

placeController.goTo(new ChemicalPlace(2105, "Chemical", 1 )); // this must change the url, stop the current activity, and start new activity(s) corresponding to ChemicalPlace.

#
How you construct the ChemicalPlace depends upon your design. 

If you refer to the post mentioned by Andrea, a AbstractBasePlace class is provided, assuming your ChemicalPlace extends AbstractBasePlace, you can construct your place using: 

placeController.goTo(new ChemicalPlace("id",2105,"tabName", "Chemical", "page","1" ));

Thanks, 

Rohan Aggarwal

unread,
Oct 18, 2011, 1:18:38 AM10/18/11
to google-we...@googlegroups.com
Sowdri,

thanks for info. Below is the way i have tried but nothing help to solve this issue.  Anything else i need to change i tired different ways. ChemicalPlace extends Abstract Place and also the required parsing of URL present in AbstractPlace.
Now the problem when i clik on the link it does navigate but the parameters are not visisble.....  Can we create this hyperlink from PHP based appln and point to this place, how to achieve it


       LayoutContainer c = new LayoutContainer();
       Hyperlink hyper =  new Hyperlink();
       String token = "&id=2105&tabName=Chemical&Page=1";
       hyper.setHTML("Navigate to Chemical", token);

       PlaceController control = new PlaceController(eventBus);              
        ChemicalPlace dh = new ChemicalPlace(token);
        control.goTo(dh);
      }
   });
        c.add(new Text("Mechnical"));
        c.add(hyper);
        panel.setWidget(c);


On Tue, Oct 18, 2011 at 10:39 AM, -sowdri- <sow...@gmail.com> wrote:
Activities and Places are in first place to make navigation simple. I'll present 2 simple use cases:

1. Navigate to other url on clicking a hyperlink. 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

-sowdri-

unread,
Oct 18, 2011, 3:35:35 AM10/18/11
to google-we...@googlegroups.com
Hi Rohan,

I guess you are trying to user PlaceController in isolation.

>> PlaceController control = new PlaceController(eventBus); 

This is not supposed to work. Have you referred the documentation on Activities and Places? Have you run the sample application given in the below link?

// taken from the official docs
        // Start PlaceHistoryHandler with our PlaceHistoryMapper
       
AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
       
PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler
.register(placeController, eventBus, defaultPlace);

       
RootPanel.get().add(appWidget);
       
// Goes to the place represented on URL else default place
        historyHandler
.handleCurrentHistory();

Hope this helps!

sridevi macherla

unread,
Oct 18, 2011, 4:28:08 AM10/18/11
to google-we...@googlegroups.com
Ya i have ran the application see my problem when i click on the hyperlink in one of the page i need to navigate to another page with those parameters in URL , please guide me how to achieve this...............



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
Reply all
Reply to author
Forward
0 new messages