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 com.javaneses.spring.client.rpc.service;
>>
>> import com.google.gwt.user.client.rpc.RemoteService;
>> import com.javaneses.spring.client.User;
>>
>> public interface LoginService extends RemoteService{
>>
>>         String login(User user);
>>
>> }//end interface
>>
>> //end
>>
>> package com.javaneses.spring.client.rpc.service;
>>
>> import com.google.gwt.user.client.rpc.AsyncCallback;
>> import com.javaneses.spring.client.User;
>>
>> public interface LoginServiceAsync {
>>
>>         void login(User user, AsyncCallback<String> asyncCallback);
>>
>> }//end interface
>>
>> //end interfaces login service
>>
>> //class server login
>>
>> package com.javaneses.spring.server.rpc.service;
>>
>> import com.google.gwt.user.server.rpc.RemoteServiceServlet;
>> import com.javaneses.spring.client.User;
>> import com.javaneses.spring.client.rpc.service.LoginService;
>>
>> public class LoginServiceImpl extends RemoteServiceServlet implements
>> LoginService{
>>
>>         private static final long serialVersionUID = 270628040929463623L;
>>
>>         public String login(User user) {
>>                 if(user != null && user.getUser().equalsIgnoreCase("vagner") 
>> &&
>>                                 user.getPasswd().equals("Javagner"))
>>                         return getThreadLocalRequest().getSession().getId();
>>                 return null;
>>         }//end login
>>
>> }//end class
>>
>> //end class server login
>>
>> //User Class
>>
>> package com.javaneses.spring.client;
>>
>> import java.io.Serializable;
>>
>> public class User implements Serializable{
>>         private static final long serialVersionUID = -1744327211076049203L;
>>
>>         private String user;
>>         private String passwd;
>>
>>         public void setUser(String user) {
>>                 this.user = user;
>>         }//end setUser
>>
>>         public String getUser() {
>>                 return user;
>>         }//end getUser
>>
>>         public void setPasswd(String passwd) {
>>                 this.passwd = passwd;
>>         }//end setPasswd
>>
>>         public String getPasswd() {
>>                 return passwd;
>>         }//end getPasswd
>>
>> }//end class
>>
>> //end User class
>>
>> //My Module.gwt.xml
>>
>> <module>
>>
>>       <!-- Inherit the core Web Toolkit stuff.
>> -->
>>       <inherits name='com.google.gwt.user.User'/>
>>
>>       <!-- Inherit the defaultGWTstyle sheet.  You can change
>> -->
>>       <!-- the theme of yourGWTapplication by uncommenting
>> -->
>>       <!-- any one of the following lines.
>> -->
>>       <inherits name='com.google.gwt.user.theme.standard.Standard'/>
>>       <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/>
>> -->
>>       <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>
>> -->
>>
>>       <!-- Other module inherits
>> -->
>>
>>       <!-- Specify the app entry point class.
>> -->
>>       <entry-point class='com.javaneses.spring.client.Main'/>
>>
>>       <!-- Specify the application specific style sheet.
>> -->
>>       <stylesheet src='Main.css' />
>>
>>       <servlet path="/session"
>> class="com.javaneses.spring.server.rpc.service.SessionServiceImpl"/>
>>       <servlet path="/login"
>> class="com.javaneses.spring.server.rpc.service.LoginServiceImpl"/>
>> </module>
>>
>> Vagner Araujo
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to