Hi Vitali, can yolu please explain in detail what u have mentioned over here.
What should i need to do in order to run the above example? How i will get the SessionId class? thanks, Arun. On Apr 18, 11:46 am, Vitali Lovich <[email protected]> wrote: > That's also outdated as the RPC is using the old syntax instead of the > much shorter one that uses annotations. > > On Sat, Apr 18, 2009 at 2:24 AM, Arun <[email protected]> wrote: > > > hello Vagner, > > > This is very good example.. > > > When I started implementing the same, it is asking me for SessionId. > > > could you tell me from where you are refering this one. It would be > > helpful to me if you put it over here. > > > Also, is it possible to reference/create a user define data/object on > > client side? > > > Thanks in advance. > > > Arun. > > > On Feb 27, 12:02 pm, Vagner Araujo <[email protected]> wrote: > >> Hello Friends, > > >> I was making a simple code ofSessionfor my students. > >> Well, I decided post that code here, > >> because maybe it can serve as a basis for someone. > > >> //Main Class > > >> package com.javaneses.spring.client; > > >> import com.google.gwt.core.client.EntryPoint; > >> import com.google.gwt.core.client.GWT; > >> import com.google.gwt.user.client.Cookies; > >> import com.google.gwt.user.client.Window; > >> import com.google.gwt.user.client.rpc.AsyncCallback; > >> import com.google.gwt.user.client.rpc.ServiceDefTarget; > >> import com.google.gwt.user.client.ui.Button; > >> import com.google.gwt.user.client.ui.ClickListener; > >> import com.google.gwt.user.client.ui.DialogBox; > >> import com.google.gwt.user.client.ui.FlexTable; > >> import com.google.gwt.user.client.ui.FlowPanel; > >> import com.google.gwt.user.client.ui.Label; > >> import com.google.gwt.user.client.ui.PasswordTextBox; > >> import com.google.gwt.user.client.ui.RootPanel; > >> import com.google.gwt.user.client.ui.TextBox; > >> import com.google.gwt.user.client.ui.Widget; > >> import com.javaneses.spring.client.rpc.service.LoginService; > >> import com.javaneses.spring.client.rpc.service.LoginServiceAsync; > >> import com.javaneses.spring.client.rpc.service.SessionService; > >> import com.javaneses.spring.client.rpc.service.SessionServiceAsync; > > >> /** > >> * Entry point classes define <code>onModuleLoad()</code>. > >> */ > >> public class Main implements EntryPoint, ClickListener{ > > >> /** > >> * This is the entry point method. > >> */ > > >> private final SessionId sessionId = new SessionId(); > > >> private final DialogBox dialogBox = new DialogBox(); > >> private final Label userLabel = new Label("User"); > >> private final Label passwdLabel = new Label("Password"); > >> private final TextBox userField = new TextBox(); > >> private final PasswordTextBox passwdField = new PasswordTextBox(); > >> private final Button login = new Button("Login"); > > >> private final Label welcome = new Label("Welcome"); > > >> private final User user = new User(); > > >> { > >> FlexTable flexTable = new FlexTable(); > > >> flexTable.setWidget(0, 0, userLabel); > >> flexTable.setWidget(0, 1, userField); > >> flexTable.setWidget(1, 0, passwdLabel); > >> flexTable.setWidget(1, 1, passwdField); > > >> FlowPanel panel = new FlowPanel(); > >> panel.setWidth("100"); > >> panel.add(login); > > >> flexTable.setWidget(2, 1, panel); > > >> dialogBox.setSize("350", "150"); > >> dialogBox.add(flexTable); > > >> login.addClickListener(this); > > >> sessionId.setSessionId(Cookies.getCookie("session")); > >> }//end init block > > >> public void onModuleLoad() { > > >> validateSession(); > > >> }//end onModuleLoad > > >> private void validateSession(){ > > >> SessionServiceAsync myServiceAsync = > >> (SessionServiceAsync)GWT.create > >> (SessionService.class); > >> ServiceDefTarget serviceDefTarget = (ServiceDefTarget) > >> myServiceAsync; > >> serviceDefTarget.setServiceEntryPoint("session"); > > >> AsyncCallback<SessionId> asyncCallback = new > >> AsyncCallback<SessionId> > >> (){ > >> public void onFailure(Throwable caught) { > >> System.out.println(caught); > >> }//end onFailure > >> public void onSuccess(SessionId result) { > >> if(result == null){ > >> RootPanel.get().clear(); > >> RootPanel.get().add(dialogBox); > >> System.out.println("Teste1"); > >> }else > >> if(!sessionId.getSessionId().equals(result.getSessionId())){ > >> RootPanel.get().clear(); > >> RootPanel.get().add(dialogBox); > >> System.out.println("Teste2"); > >> }else > >> if(sessionId.getSessionId().equals(result.getSessionId())){ > >> RootPanel.get().add(welcome); > >> } > >> }//end onSucess > >> };//end AsyncCallback<String> asyncCallback = new > >> AsyncCallback<String>() > >> myServiceAsync.session(sessionId, asyncCallback); > >> }//end validateSession > > >> public void onClick(Widget sender) { > >> if(sender == login){ > >> user.setUser(userField.getText()); > >> user.setPasswd(passwdField.getText()); > >> LoginServiceAsync loginServiceAsync = > >> (LoginServiceAsync)GWT.create > >> (LoginService.class); > >> ServiceDefTarget serviceDefTarget = > >> (ServiceDefTarget) > >> loginServiceAsync; > >> serviceDefTarget.setServiceEntryPoint("login"); > > >> AsyncCallback<String> asyncCallback = new > >> AsyncCallback<String>() { > >> public void onSuccess(String result) { > >> if(result != null){ > >> RootPanel.get().clear(); > >> > >> RootPanel.get().add(welcome); > >> > >> Cookies.setCookie("session", result); > >> > >> sessionId.setSessionId(result); > > >> > >> System.out.println("loginsession=> "+result); > > >> }else{ > >> Window.alert("Login > >> Invalid !"); > >> } > >> } > >> public void onFailure(Throwable caught) { > >> System.out.println(caught); > >> } > >> };//end asyncCallback > > >> loginServiceAsync.login(user, asyncCallback); > >> }//end if(sender == login) > >> }//end onClick > > >> }//end class > > >> //end Main Class > > >> //Interfaces of Services > > >> package com.javaneses.spring.client.rpc.service; > > >> import com.google.gwt.user.client.rpc.RemoteService; > >> import com.javaneses.spring.client.SessionId; > > >> public interface SessionService extends RemoteService{ > >> SessionIdsession(SessionId sessionId); > > >> }//end class > > >> package com.javaneses.spring.client.rpc.service; > > >> import com.google.gwt.user.client.rpc.AsyncCallback; > >> import com.javaneses.spring.client.SessionId; > > >> public interface SessionServiceAsync { > >> voidsession(SessionId sessionId, AsyncCallback<SessionId> > >> asyncCallback); > > >> }//end MyServiceAsync > > >> //end interfaces SessionServices > > >> package com.javaneses.spring.server.rpc.service; > > >> import javax.servlet.http.HttpSession; > > >> import com.google.gwt.user.server.rpc.RemoteServiceServlet; > >> import com.javaneses.spring.client.SessionId; > >> import com.javaneses.spring.client.rpc.service.SessionService; > > >> public class SessionServiceImpl extends RemoteServiceServlet > >> implements SessionService{ > > >> private static final long serialVersionUID = -6274876845484737659L; > > >> public SessionIdsession(SessionId sessionId) { > >> HttpSession httpSession = > >> getThreadLocalRequest().getSession(false); > >> if(httpSession != null){ > >> sessionId.setSessionId(httpSession.getId()); > >> return sessionId; > >> }//end if(result == null) > >> return null; > >> }//endsession > > >> }//end class > > >> //interfaces login service > > >> package > > ... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
