Re: Getting username from url only works after refresh

2016-06-01 Thread Olar Andrei
If someone may face this problem again, I solved it like this:

In the ClientFactoryImpl I replaced the following:
private final EventBus eventBus = new SimpleEventBus();
private final PlaceController placeController = new 
PlaceController(eventBus);
private final LoginView loginView = new LoginViewImpl();
private final RegisterView registerView = new RegisterViewImpl();
private final UserView userView = new UserViewImpl();
private final AdminView adminView = new AdminViewImpl();

@Override
public EventBus getEventBus() {
return eventBus;
}

@Override
public PlaceController getPlaceController() {
return placeController;
}

@Override
public LoginView getLoginView() {
return loginView;
}

@Override
public RegisterView getRegisterView() {
return registerView;
}

@Override
public UserView getUserView() {
return userView;
}

@Override
public AdminView getAdminView() {
return adminView;
}

with the followring:

private final EventBus eventBus = new SimpleEventBus();
private final PlaceController placeController = new 
PlaceController(eventBus);

@Override
public EventBus getEventBus() {
return eventBus;
}

@Override
public PlaceController getPlaceController() {
return placeController;
}

@Override
public LoginView getLoginView() {
return new LoginViewImpl();
}

@Override
public RegisterView getRegisterView() {
return new RegisterViewImpl();
}

@Override
public UserView getUserView() {
return new UserViewImpl();
}

@Override
public AdminView getAdminView() {
return new AdminViewImpl();
}


Lots of thanks to everybody for their support and have a great day. :)

marți, 31 mai 2016, 01:25:10 UTC+3, Olar Andrei a scris:
>
> My login based application, requires to always know the username of the 
> logged in user. (MVP) . So I'm getting the username from the url, but when 
> the page opens after the login succeeded, I can't get the username from the 
> url, because it does not appear to exists, but it is there. It only works 
> after a refresh. Then I'm able to get the username.
>
>
> The URL is in the form 
> *http://127.0.0.1:/AdministrareBloc.html#AdminPlace:admin 
> *, where 
> I'm splitting the String to only get the admin part. 
>
>
> I thought this is because it downloads the code before verifying the user. 
> So I placed a split point in my code like this: (I don't know if I placed 
> it correctly)
>
>
> loginButton.addClickHandler(new ClickHandler() {
>
> @Override
> public void onClick(ClickEvent event) {
> final String username = usernameBox.getText();
> final String password = passwordBox.getText();
> GWT.runAsync(new RunAsyncCallback() {
>
> @Override
> public void onSuccess() {
> performUserConnection(username, password);
> }
>
> @Override
> public void onFailure(Throwable reason) {
> // TODO Auto-generated method stub
> }
> });
> }
> });
>
> private static void performUserConnection(String username, String password) {
> DBConnectionAsync rpcService = (DBConnectionAsync) 
> GWT.create(DBConnection.class);
> ServiceDefTarget target = (ServiceDefTarget) rpcService;
> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
> target.setServiceEntryPoint(moduleRelativeURL);
>
> rpcService.authenticateUser(username, password, new AsyncCallback() 
> {
>
> @Override
> public void onSuccess(User user) {
>
> if (user.getType().equals("User")) {
> String username = user.getUsername();
> presenter.goTo(new UserPlace(username));
> } else if (user.getType().equals("Admin")) {
> String username = user.getUsername();
> presenter.goTo(new AdminPlace(username));
> }
> }
>
> }}
>
>
> This is happening when the user clicks the login button. Is the split 
> point placed correclty, or not ? How can I get the username without needing 
> to refresh the page after a successful login ? 
>
> Thanks in advance
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-06-01 Thread Olar Andrei
This is the ActivityMapper

public class AppActivityMapper implements ActivityMapper {

private ClientFactory clientFactory;

public AppActivityMapper(ClientFactory clientFactory) {
super();
this.clientFactory = clientFactory;
}

@Override
public Activity getActivity(Place place) {
if (place instanceof LoginPlace) {
return new LoginActivity((LoginPlace) place, clientFactory);
} else if (place instanceof RegisterPlace) {
return new RegisterActivity((RegisterPlace) place, clientFactory);
} else if (place instanceof UserPlace) {
return new UserActivity((UserPlace) place, clientFactory);
} else if (place instanceof AdminPlace) {
return new AdminActivity((AdminPlace) place, clientFactory);
}

return null;
}

}

And this is the onModuleLoad() method
public class AdministrareBloc implements EntryPoint {

private Place defaultPlace = new LoginPlace("Login Place!");
private SimplePanel appWidget = new SimplePanel();

@Override
public void onModuleLoad() {
ClientFactory clientFactory = GWT.create(ClientFactory.class);
EventBus eventBus = clientFactory.getEventBus();
PlaceController placeController = clientFactory.getPlaceController();

// Start Activity for the main widget with our ActivityMapper
ActivityMapper activityMapper = new AppActivityMapper(clientFactory);
ActivityManager activityManager = new ActivityManager(activityMapper, 
eventBus);
activityManager.setDisplay(appWidget);

// 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);
historyHandler.handleCurrentHistory();
}

}

What do you mean by "Where does the UserPlace come from ? " ? 

Thanks

marți, 31 mai 2016, 01:25:10 UTC+3, Olar Andrei a scris:
>
> My login based application, requires to always know the username of the 
> logged in user. (MVP) . So I'm getting the username from the url, but when 
> the page opens after the login succeeded, I can't get the username from the 
> url, because it does not appear to exists, but it is there. It only works 
> after a refresh. Then I'm able to get the username.
>
>
> The URL is in the form 
> *http://127.0.0.1:/AdministrareBloc.html#AdminPlace:admin 
> *, where 
> I'm splitting the String to only get the admin part. 
>
>
> I thought this is because it downloads the code before verifying the user. 
> So I placed a split point in my code like this: (I don't know if I placed 
> it correctly)
>
>
> loginButton.addClickHandler(new ClickHandler() {
>
> @Override
> public void onClick(ClickEvent event) {
> final String username = usernameBox.getText();
> final String password = passwordBox.getText();
> GWT.runAsync(new RunAsyncCallback() {
>
> @Override
> public void onSuccess() {
> performUserConnection(username, password);
> }
>
> @Override
> public void onFailure(Throwable reason) {
> // TODO Auto-generated method stub
> }
> });
> }
> });
>
> private static void performUserConnection(String username, String password) {
> DBConnectionAsync rpcService = (DBConnectionAsync) 
> GWT.create(DBConnection.class);
> ServiceDefTarget target = (ServiceDefTarget) rpcService;
> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
> target.setServiceEntryPoint(moduleRelativeURL);
>
> rpcService.authenticateUser(username, password, new AsyncCallback() 
> {
>
> @Override
> public void onSuccess(User user) {
>
> if (user.getType().equals("User")) {
> String username = user.getUsername();
> presenter.goTo(new UserPlace(username));
> } else if (user.getType().equals("Admin")) {
> String username = user.getUsername();
> presenter.goTo(new AdminPlace(username));
> }
> }
>
> }}
>
>
> This is happening when the user clicks the login button. Is the split 
> point placed correclty, or not ? How can I get the username without needing 
> to refresh the page after a successful login ? 
>
> Thanks in advance
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-06-01 Thread Thomas Broyer
Where and when and how is UserActivity constructed? Where does the 
UserPlace come from?

On Tuesday, May 31, 2016 at 5:22:21 PM UTC+2, Olar Andrei wrote:
>
> I've tried that before, and I didn't managed to get the username to be 
> visible in my *ViewImpl...*
>
> For example. This is the structure I have:
>
> *UserActivity*
> public class UserActivity extends AbstractActivity implements UserView.
> Presenter {
>
>
>  private ClientFactory clientFactory;
>  private String name;
>
>
>  public UserActivity(UserPlace place, ClientFactory clientFactory) {
>  this.name = place.getPlaceName();
>  this.clientFactory = clientFactory;
>  }
>
>
>  @Override
>  public void start(final AcceptsOneWidget containerWidget, EventBus 
> eventBus) {
>  UserView userView = clientFactory.getUserView();
>  userView.setName(name);
>  userView.setPresenter(this);
>  containerWidget.setWidget(userView.asWidget());
>
>
>  }
>
>
>  @Override
>  public void goTo(Place place) {
>  clientFactory.getPlaceController().goTo(place);
>  }
>
>
> }
>
>
>
> *UserPlace*
>
>
>
>
>
>
>
>
>
>
> *public class UserPlace extends Place { private String username; public 
> UserPlace(String username) { this.username = username; } public String 
> getPlaceName() { return username; } public static class Tokenizer 
> implements PlaceTokenizer { @Override public UserPlace 
> getPlace(String token) { return new UserPlace(token); } @Override public 
> String getToken(UserPlace place) { return place.getPlaceName(); } }}*
> *UserView*
>
>
>
>
> *public interface UserView extends IsWidget { void setName(String name); 
> void setPresenter(Presenter presenter); public interface Presenter { void 
> goTo(Place place); }}UserViewImpl*
> public class UserViewImpl extends Composite implements UserView {
>
> ...
>
> public UserViewImpl() {
> Widget mainMenu = createMenu();
> initWidget(mainMenu);
> }
>
> ...
> }
>
> How can I access the username I send from my *LoginViewImpl *like shown 
> above in my* UserViewImpl ? *
>
> Thanks in advance
>
>
> marți, 31 mai 2016, 01:25:10 UTC+3, Olar Andrei a scris:
>>
>> My login based application, requires to always know the username of the 
>> logged in user. (MVP) . So I'm getting the username from the url, but when 
>> the page opens after the login succeeded, I can't get the username from the 
>> url, because it does not appear to exists, but it is there. It only works 
>> after a refresh. Then I'm able to get the username.
>>
>>
>> The URL is in the form 
>> *http://127.0.0.1:/AdministrareBloc.html#AdminPlace:admin 
>> *, where 
>> I'm splitting the String to only get the admin part. 
>>
>>
>> I thought this is because it downloads the code before verifying the 
>> user. So I placed a split point in my code like this: (I don't know if I 
>> placed it correctly)
>>
>>
>> loginButton.addClickHandler(new ClickHandler() {
>>
>> @Override
>> public void onClick(ClickEvent event) {
>> final String username = usernameBox.getText();
>> final String password = passwordBox.getText();
>> GWT.runAsync(new RunAsyncCallback() {
>>
>> @Override
>> public void onSuccess() {
>> performUserConnection(username, password);
>> }
>>
>> @Override
>> public void onFailure(Throwable reason) {
>> // TODO Auto-generated method stub
>> }
>> });
>> }
>> });
>>
>> private static void performUserConnection(String username, String password) {
>> DBConnectionAsync rpcService = (DBConnectionAsync) 
>> GWT.create(DBConnection.class);
>> ServiceDefTarget target = (ServiceDefTarget) rpcService;
>> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
>> target.setServiceEntryPoint(moduleRelativeURL);
>>
>> rpcService.authenticateUser(username, password, new 
>> AsyncCallback() {
>>
>> @Override
>> public void onSuccess(User user) {
>>
>> if (user.getType().equals("User")) {
>> String username = user.getUsername();
>> presenter.goTo(new UserPlace(username));
>> } else if (user.getType().equals("Admin")) {
>> String username = user.getUsername();
>> presenter.goTo(new AdminPlace(username));
>> }
>> }
>>
>> }}
>>
>>
>> This is happening when the user clicks the login button. Is the split 
>> point placed correclty, or not ? How can I get the username without needing 
>> to refresh the page after a successful login ? 
>>
>> Thanks in advance
>>
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to googl

Re: Getting username from url only works after refresh

2016-06-01 Thread Jens


>  About the code splitting stuff. Because the browser downloads code before 
> he needs it.
>

The split point itself will be loaded once you click your login button. 
Once the split point has been loaded the performUserConnection() method 
will be called. But depending on your code structure it is not guaranteed 
that the UserViewImpl and UserActivity are actually part of that split 
point.

Anyways, its not that easy to tell you how to solve the issue you have in 
your code, because everything you have posted so far is generally ok. You 
can do the code splitting the way you have done it.

If you can, upload the full code to Github or similar, so people can take a 
closer look instead of just seeing code snippets. Otherwise use the Browser 
debugger and step through your code to see when and why things go wrong in 
your app.

-- J.

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-06-01 Thread Olar Andrei
I'll take your option into consideration. But for now I'm running out of 
time and I want to know how to fix the problem specified in my previous 
post. About the code splitting stuff. Because the browser downloads code 
before he needs it.

marți, 31 mai 2016, 01:25:10 UTC+3, Olar Andrei a scris:
>
> My login based application, requires to always know the username of the 
> logged in user. (MVP) . So I'm getting the username from the url, but when 
> the page opens after the login succeeded, I can't get the username from the 
> url, because it does not appear to exists, but it is there. It only works 
> after a refresh. Then I'm able to get the username.
>
>
> The URL is in the form 
> *http://127.0.0.1:/AdministrareBloc.html#AdminPlace:admin 
> *, where 
> I'm splitting the String to only get the admin part. 
>
>
> I thought this is because it downloads the code before verifying the user. 
> So I placed a split point in my code like this: (I don't know if I placed 
> it correctly)
>
>
> loginButton.addClickHandler(new ClickHandler() {
>
> @Override
> public void onClick(ClickEvent event) {
> final String username = usernameBox.getText();
> final String password = passwordBox.getText();
> GWT.runAsync(new RunAsyncCallback() {
>
> @Override
> public void onSuccess() {
> performUserConnection(username, password);
> }
>
> @Override
> public void onFailure(Throwable reason) {
> // TODO Auto-generated method stub
> }
> });
> }
> });
>
> private static void performUserConnection(String username, String password) {
> DBConnectionAsync rpcService = (DBConnectionAsync) 
> GWT.create(DBConnection.class);
> ServiceDefTarget target = (ServiceDefTarget) rpcService;
> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
> target.setServiceEntryPoint(moduleRelativeURL);
>
> rpcService.authenticateUser(username, password, new AsyncCallback() 
> {
>
> @Override
> public void onSuccess(User user) {
>
> if (user.getType().equals("User")) {
> String username = user.getUsername();
> presenter.goTo(new UserPlace(username));
> } else if (user.getType().equals("Admin")) {
> String username = user.getUsername();
> presenter.goTo(new AdminPlace(username));
> }
> }
>
> }}
>
>
> This is happening when the user clicks the login button. Is the split 
> point placed correclty, or not ? How can I get the username without needing 
> to refresh the page after a successful login ? 
>
> Thanks in advance
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-06-01 Thread Chad Vincent
For some reason, passing the username around via the URL seems like a code 
smell to me.

I'm not sure if it's actually better or not, but I store the User object 
from the server (less password hash) in a singleton (and the session, in 
case of a full refresh).  I also have all my Place content setup so I just 
change it within a Panel (TabLayoutPanel, though Dock or Stack would work, 
too) while leaving navigation and header alone.

This removes putting user information in the URL, so people can share 
deep-links to content without sharing usernames by default.

On Wednesday, June 1, 2016 at 7:09:20 AM UTC-5, Olar Andrei wrote:
>
> Hello,
>
> I've tried a little trick today, because I still belive the browser 
> downloads code he does not need before he actually needs it.
>
> I placed this:
> Window.Location.reload();
> inside my *UserViewImpl, *so it would reload after the login.
>
> The problem is that when the application starts with the *LoginViewImpl *the 
> page refreshes every second. So I'm not even in the UserViewImpl, so I 
> didn't log in, and the page gets the code from the UserViewImpl and starts 
> refreshing.
> The thing is I've used code splitting in my application like this:
>
> *Login Button*
>
> loginButton.setHTML(LoginFormConstants.LOGIN_BUTTON);
> loginButton.addClickHandler(new ClickHandler() {
>
> @Override
> public void onClick(ClickEvent event) {
> final String username = usernameBox.getText();
> final String password = passwordBox.getText();
>
> // Is this good code splitting ?
> GWT.runAsync(new RunAsyncCallback() {
>
> @Override
> public void onSuccess() {
> performUserConnection(username, password);
> }
>
> @Override
> public void onFailure(Throwable reason) {
> // TODO Auto-generated method stub
> }
> });
> }
> });
>
>  and *performUserConnection()*
>
> private static void performUserConnection(String username, String 
> password) {
> DBConnectionAsync rpcService = (DBConnectionAsync) 
> GWT.create(DBConnection.class);
> ServiceDefTarget target = (ServiceDefTarget) rpcService;
> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
> target.setServiceEntryPoint(moduleRelativeURL);
>
> rpcService.authenticateUser(username, password, new AsyncCallback() {
>
> @Override
> public void onSuccess(User user) {
>
> if (user.getType().equals("User")) {
> String username = user.getUsername();
> presenter.goTo(new UserPlace(username));
> } else if (user.getType().equals("Admin")) {
> String username = user.getUsername();
> presenter.goTo(new AdminPlace(username));
> }
> }
>
> @Override
> public void onFailure(Throwable caught) {
> DialogBox dialogBox = createDialogBox();
> dialogBox.setGlassEnabled(true);
> dialogBox.setAnimationEnabled(true);
> dialogBox.center();
> dialogBox.show();
> }
>   });
>   }
>
> So the page should wait to see if connection was successful, and then 
> download the code, right ? Why isn't this happening ?
>
> Thanks in advance
>
>
> marți, 31 mai 2016, 01:25:10 UTC+3, Olar Andrei a scris:
>>
>> My login based application, requires to always know the username of the 
>> logged in user. (MVP) . So I'm getting the username from the url, but when 
>> the page opens after the login succeeded, I can't get the username from the 
>> url, because it does not appear to exists, but it is there. It only works 
>> after a refresh. Then I'm able to get the username.
>>
>>
>> The URL is in the form 
>> *http://127.0.0.1:/AdministrareBloc.html#AdminPlace:admin 
>> *, where 
>> I'm splitting the String to only get the admin part. 
>>
>>
>> I thought this is because it downloads the code before verifying the 
>> user. So I placed a split point in my code like this: (I don't know if I 
>> placed it correctly)
>>
>>
>> loginButton.addClickHandler(new ClickHandler() {
>>
>> @Override
>> public void onClick(ClickEvent event) {
>> final String username = usernameBox.getText();
>> final String password = passwordBox.getText();
>> GWT.runAsync(new RunAsyncCallback() {
>>
>> @Override
>> public void onSuccess() {
>> performUserConnection(username, password);
>> }
>>
>> @Override
>>  
>> *Introduceți aici codul...*   public void onFailure(Throwable 
>> reason) {
>>
>> // TODO Auto-generated method stub
>> }
>> });
>> }
>> });
>>
>> private static void performUserConnection(String username, String password) {
>> DBConnectionAsync rpcService = (DBConnectionAsync) 
>> GWT.create(DBConnection.class);
>> ServiceDefTarget target = (ServiceDefTarget) rpcService;
>> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
>> target.setServiceEntryPoint(moduleRelativeURL);
>>
>> rpcService.authenticateUser(username, password, 

Re: Getting username from url only works after refresh

2016-06-01 Thread Olar Andrei
Hello,

I've tried a little trick today, because I still belive the browser 
downloads code he does not need before he actually needs it.

I placed this:
Window.Location.reload();
inside my *UserViewImpl, *so it would reload after the login.

The problem is that when the application starts with the *LoginViewImpl *the 
page refreshes every second. So I'm not even in the UserViewImpl, so I 
didn't log in, and the page gets the code from the UserViewImpl and starts 
refreshing.
The thing is I've used code splitting in my application like this:

*Login Button*

loginButton.setHTML(LoginFormConstants.LOGIN_BUTTON);
loginButton.addClickHandler(new ClickHandler() {

@Override
public void onClick(ClickEvent event) {
final String username = usernameBox.getText();
final String password = passwordBox.getText();

// Is this good code splitting ?
GWT.runAsync(new RunAsyncCallback() {

@Override
public void onSuccess() {
performUserConnection(username, password);
}

@Override
public void onFailure(Throwable reason) {
// TODO Auto-generated method stub
}
});
}
});

 and *performUserConnection()*

private static void performUserConnection(String username, String password) 
{
DBConnectionAsync rpcService = (DBConnectionAsync) 
GWT.create(DBConnection.class);
ServiceDefTarget target = (ServiceDefTarget) rpcService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
target.setServiceEntryPoint(moduleRelativeURL);

rpcService.authenticateUser(username, password, new AsyncCallback() {

@Override
public void onSuccess(User user) {

if (user.getType().equals("User")) {
String username = user.getUsername();
presenter.goTo(new UserPlace(username));
} else if (user.getType().equals("Admin")) {
String username = user.getUsername();
presenter.goTo(new AdminPlace(username));
}
}

@Override
public void onFailure(Throwable caught) {
DialogBox dialogBox = createDialogBox();
dialogBox.setGlassEnabled(true);
dialogBox.setAnimationEnabled(true);
dialogBox.center();
dialogBox.show();
}
  });
  }

So the page should wait to see if connection was successful, and then 
download the code, right ? Why isn't this happening ?

Thanks in advance


marți, 31 mai 2016, 01:25:10 UTC+3, Olar Andrei a scris:
>
> My login based application, requires to always know the username of the 
> logged in user. (MVP) . So I'm getting the username from the url, but when 
> the page opens after the login succeeded, I can't get the username from the 
> url, because it does not appear to exists, but it is there. It only works 
> after a refresh. Then I'm able to get the username.
>
>
> The URL is in the form 
> *http://127.0.0.1:/AdministrareBloc.html#AdminPlace:admin 
> *, where 
> I'm splitting the String to only get the admin part. 
>
>
> I thought this is because it downloads the code before verifying the user. 
> So I placed a split point in my code like this: (I don't know if I placed 
> it correctly)
>
>
> loginButton.addClickHandler(new ClickHandler() {
>
> @Override
> public void onClick(ClickEvent event) {
> final String username = usernameBox.getText();
> final String password = passwordBox.getText();
> GWT.runAsync(new RunAsyncCallback() {
>
> @Override
> public void onSuccess() {
> performUserConnection(username, password);
> }
>
> @Override
>  
> *Introduceți aici codul...*   public void onFailure(Throwable reason) 
> {
>
> // TODO Auto-generated method stub
> }
> });
> }
> });
>
> private static void performUserConnection(String username, String password) {
> DBConnectionAsync rpcService = (DBConnectionAsync) 
> GWT.create(DBConnection.class);
> ServiceDefTarget target = (ServiceDefTarget) rpcService;
> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
> target.setServiceEntryPoint(moduleRelativeURL);
>
> rpcService.authenticateUser(username, password, new AsyncCallback() 
> {
>
> @Override
> public void onSuccess(User user) {
>
> if (user.getType().equals("User")) {
> String username = user.getUsername();
> presenter.goTo(new UserPlace(username));
> } else if (user.getType().equals("Admin")) {
> String username = user.getUsername();
> presenter.goTo(new AdminPlace(username));
> }
> }
>
> }}
>
>
> This is happening when the user clicks the login button. Is the split 
> point placed correclty, or not ? How can I get the username without needing 
> to refresh the page after a successful login ? 
>
> Thanks in advance
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and 

Re: Getting username from url only works after refresh

2016-05-31 Thread Jens
As said what you have done is generally fine in terms of passing data to a 
new place. I am saying that you have a bug somewhere in your code that 
results in a blank "logged in as: " widget because when you do 
placeController.goTo(new UserPlace(username)) then your UserActivity should 
be created with the same UserPlace instance as constructor parameter and 
thus you have the username available in your UserActivity. If that does not 
happen something is generally wrong in your code.

Personally I would not store the username in the browser URL as it is data 
for the current user session. An URL can be shared with other people so it 
should not contain "personal" information, only navigational information. 
At work we have a class called UserSession which stores user related data 
like username, permissions and is used as a singleton.

-- J.

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-05-31 Thread Olar Andrei
Ok. Then let me be a little more precise. How do you normally pass a variable 
between 2 places. How should i access my username from the UserViewImpl knowing 
the facts above ? 

I've tried using History.getToken(), and when the page gets loaded the username 
does not appear (i have a widget which says "logged in as: " and it's blank. 
Nothing appears. When i click the browser refresh button, then the username 
appears., like "logged in as: UserPlace:andrei.olar" , same as when i splitted 
my url to obtain the username 

PS: no uibinder

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-05-31 Thread Jens
The only issue I can see with the above code is that you have not 
implemented hashcode/equals for your places. However GWT expects you do 
implement both methods correctly for your places. I am still under the 
impression that it should just work, especially because you use 
placeController.goTo(new UserPlace(name)). In that case GWT does not parse 
the URL at all but only updates the URL in the browser based on the place 
you have created yourself in code.

Do you use UiBinder in your UserViewImpl? If yes then check if the widget 
that shows the user name has not been recreated accidentally, e.g. 
something like

UserViewImpl extends Composite {

  @UiField
  Label userNameLabel;

  public UserViewImpl() {
initWidget(...);
*userNameLabel = new Label();*
  }

  void setName(...) {
 userNameLabel.setText(...);
  }

}

will not work because the userNameLabel has been recreated manually in the 
constructor and is not attached in the browser UI at all.


-- J.

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-05-31 Thread Olar Andrei
I've tried that before, and I didn't managed to get the username to be 
visible in my *ViewImpl...*

For example. This is the structure I have:

*UserActivity*
public class UserActivity extends AbstractActivity implements UserView.
Presenter {


 private ClientFactory clientFactory;
 private String name;


 public UserActivity(UserPlace place, ClientFactory clientFactory) {
 this.name = place.getPlaceName();
 this.clientFactory = clientFactory;
 }


 @Override
 public void start(final AcceptsOneWidget containerWidget, EventBus eventBus
) {
 UserView userView = clientFactory.getUserView();
 userView.setName(name);
 userView.setPresenter(this);
 containerWidget.setWidget(userView.asWidget());


 }


 @Override
 public void goTo(Place place) {
 clientFactory.getPlaceController().goTo(place);
 }


}



*UserPlace*










*public class UserPlace extends Place { private String username; public 
UserPlace(String username) { this.username = username; } public String 
getPlaceName() { return username; } public static class Tokenizer 
implements PlaceTokenizer { @Override public UserPlace 
getPlace(String token) { return new UserPlace(token); } @Override public 
String getToken(UserPlace place) { return place.getPlaceName(); } }}*
*UserView*




*public interface UserView extends IsWidget { void setName(String name); 
void setPresenter(Presenter presenter); public interface Presenter { void 
goTo(Place place); }}UserViewImpl*
public class UserViewImpl extends Composite implements UserView {

...

public UserViewImpl() {
Widget mainMenu = createMenu();
initWidget(mainMenu);
}

...
}

How can I access the username I send from my *LoginViewImpl *like shown 
above in my* UserViewImpl ? *

Thanks in advance


marți, 31 mai 2016, 01:25:10 UTC+3, Olar Andrei a scris:
>
> My login based application, requires to always know the username of the 
> logged in user. (MVP) . So I'm getting the username from the url, but when 
> the page opens after the login succeeded, I can't get the username from the 
> url, because it does not appear to exists, but it is there. It only works 
> after a refresh. Then I'm able to get the username.
>
>
> The URL is in the form 
> *http://127.0.0.1:/AdministrareBloc.html#AdminPlace:admin 
> *, where 
> I'm splitting the String to only get the admin part. 
>
>
> I thought this is because it downloads the code before verifying the user. 
> So I placed a split point in my code like this: (I don't know if I placed 
> it correctly)
>
>
> loginButton.addClickHandler(new ClickHandler() {
>
> @Override
> public void onClick(ClickEvent event) {
> final String username = usernameBox.getText();
> final String password = passwordBox.getText();
> GWT.runAsync(new RunAsyncCallback() {
>
> @Override
> public void onSuccess() {
> performUserConnection(username, password);
> }
>
> @Override
> public void onFailure(Throwable reason) {
> // TODO Auto-generated method stub
> }
> });
> }
> });
>
> private static void performUserConnection(String username, String password) {
> DBConnectionAsync rpcService = (DBConnectionAsync) 
> GWT.create(DBConnection.class);
> ServiceDefTarget target = (ServiceDefTarget) rpcService;
> String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionImpl";
> target.setServiceEntryPoint(moduleRelativeURL);
>
> rpcService.authenticateUser(username, password, new AsyncCallback() 
> {
>
> @Override
> public void onSuccess(User user) {
>
> if (user.getType().equals("User")) {
> String username = user.getUsername();
> presenter.goTo(new UserPlace(username));
> } else if (user.getType().equals("Admin")) {
> String username = user.getUsername();
> presenter.goTo(new AdminPlace(username));
> }
> }
>
> }}
>
>
> This is happening when the user clicks the login button. Is the split 
> point placed correclty, or not ? How can I get the username without needing 
> to refresh the page after a successful login ? 
>
> Thanks in advance
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: Getting username from url only works after refresh

2016-05-30 Thread Jens
Well there is nothing wrong with the code you posted. I guess your issue is 
in some other code. You said you are splitting the URL String, which sounds 
like you do this manually? Actually GWT already does this using the 
AdminPlace and its Tokenizer. Whenever you visit the above URL you should 
get a PlaceChangeEvent for the AdminPlace which should already hold the 
username. So your ActivityMapper.getActivity(Place) method should be 
triggered and then you can pass on the user name to your activity/presenter.

-- J.

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.