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<UserPlace> { @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:8888/AdministrareBloc.html#AdminPlace:admin
> <http://127.0.0.1:8888/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<User>()
> {
>
> @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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.