I'm fairly new to GWT (in fact this is my first project to use it). I
was trying to build a simple app:
1. I have a page with some links (each with different request
parameter).
2. Clicking on a link will invoke a servlet on the backend (passing the
request parameter), which construct the result & return it.
3. The page renders the result inside a table (under relevant link).
So far I've completed a tutorial which allow me to render a page &
retrieve the result from the backend (no link, just a simple page to
retrieve the data from the servlet & display it).
I'm having trouble with what I wanted above. In particular:
1. Because of the parameters to the individual links are constructed
from data inside HttpServletRequest / Session .... how can I obtain it?
I have the following code
-----------------------------------------------------------------------------------------------------------
public class PerformanceExtractorEntryPoint implements EntryPoint {
private Table table;
/**
* This is the entry point method.
*/
public void onModuleLoad() {
// here i will create a Hyperlink to invoke the getData()
method. Unfortunately I dont know to retrieve "messageName","branch",
etc which are in HttpServletRequest
}
private void getData(String messageName,String branch, TimeType
timetype, int start, int end){
AsyncPerfExtractorServiceAsync dataService =
(AsyncPerfExtractorServiceAsync) GWT.create(
AsyncPerfExtractorService.class );
ServiceDefTarget endpoint = (ServiceDefTarget) dataService;
endpoint.setServiceEntryPoint("/asyncPerfExtractor");
dataService.getSegmentation(messageName, branch, timetype,
start, end, new AsyncCallback(){
public void onSuccess(Object result) {
table.setSource(
new SimpleDataSource(
(PerformanceMeasurement[]) result ) );
}
public void onFailure(Throwable caught) {
Window.alert("Unable to get data from server: "
+caught.toString());
}
});
}
}
------------------------------------------------------------------------------------------------
Maybe I misunderstood it, but as I understand it.. GWT compiler will
try to convert an EntryPoint to the HTML +javascript.
Can anybody share a light?
Thanks!
Alex.
- As I understand it, the class that will subclass "EntryPoint" above
will be compiled by GWT compiler to produce HTML +javascript needed to
perform AJAX.
- Having said so, I was planning to write the class (as above), and
then use GWT compiler to produce the HTML + javascript. The results
will then be combined with my existing JSP (manually). --> not sure if
this is the standard procedure. I'm sure there is a better way..
(again, this is my first time to use GWT)
- My current JSP page has a link that resemble this:
<a
href="/bla/bla.do?parameter=<%=request.getParameter("paramValue")%>">
(might not be syntaticall correct, but you get the idea. The
hyperlink has a parameter which should be obtained from request. I'm
doing this using Struts at the moment)
- As I mentioned in my previous post, I am having trouble in making
GWT's Hyperlink object and giving it a parameter with value that exist
in HttpServletRequest - I dont know how to obtain the request in the
first place.
All the examples that I have looked at either:
1. Have a simple link that invoke servlet in the backend without the
need of passing parameter
2. Have a slightly more complicated link (with parameter), but the
parameter value is taken from a textbox thats rendered using GWT. i.e.
value is not from HttpServletRequest.
Any help will be very appreciated. (even telling me if what I'm after
is impossible :) )
Oh... of course I'm open to suggestion... sounds like I'm approaching
the problem in a wrong way.
I've thought of calling a 2nd servlet in the backend that will return
all the links & parameterrs (since RemoteServiceServlet has access to
HttpServletRequest).. but I'm sure there's better way out there.
Thanks again!
Alex.
I have not done this myself, but it I were, I might do something like
this. Create JavaScript variables in the head of the page to hold the
values from the server.
(disclaimer: untested code, probably buggy. just trying to get the
idea across)
[somepage.jsp]
<html>
<head>
<meta name='gwt:module' content='org.name.MyApplication' />
<script type="text/javascript">
link_name_one = "<%=request.getParameter("name1")%>";
link_url_one = "<%=request.getParameter("url1")%>";
</script>
</head>
<body>
<script language="javascript" src="gwt.js"></script>
</body>
</html>
...Then in the GWT code, referece the JavaScript variables you created.
public native String getLinkName (String name) /*-{
return $wnd["link_name_" + name];
}-*/;
public native String getUrlName (String name) /*-{
return $wnd["link_url_" + name];
}-*/;
...And create the Hyperlink object like this:
Hyperlink h = new Hyperlink();
h.setText(getLinkName("one"));
DOM.setAttribute(h.getElement(), getUrlName("one"));
Even if you don't go with this sort of solution I would be interested
to hear what solution you do use.
Rob
Thanks for the reply. I will give your suggestion a shot, but I've
decided to hold the horse for now.
Lets see if others come up with other ideas... coz I'm pretty sure this
is a common thing...
Regards,
Alex.