You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Olga <ba...@list.ru> on 2011/10/11 11:41:50 UTC

ApplicationStateManager - No service implements the interface long.

Hello, i have this problem.

When i try to login in my project with incorect name i have this error:
Error invoking constructor com.htc.identity.entities.User(long, String,
String) (at User.java:36) (for service 'ApplicationStateManager'): No
service implements the interface long.

On line 36 in User class i have:
 
    public User(final long id, final String username, final String password)
{
        this.setId(id);
        this.setUsername(username);
        this.setPassword(password);
    }

My Login.java

public class Login {

    @Inject
    private UserService userService;

    @SessionState
    private User user;

    @Property
    private String username;

    @Property
    private String password;

    @Log
    public Object onSubmitFromLoginForm() throws SQLException {
        user = userService.getUser(username, password);
        if (user != null) {
            return Home.class;
        } else
            return null;
    }
}


UserService:

public class UserServiceImpl implements UserService {
    
    private Map&lt;String, User&gt; users;

    public UserServiceImpl(String userList, String passwordList) {
        users = new HashMap&lt;String, User&gt;();
        try {
            String[] us = userList.split(",");
            String[] pws = passwordList.split(",");
            for(int i = 0; i < Math.max(us.length, pws.length); i++) {
                users.put(us[i], new User(i, us[i], pws[i]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public User getUser(String username, String password) {
        User user = users.get(username);
        if (user != null && StringUtils.equals(user.getPassword(),
password)) return user;
        return null;
    }

}


Thanks for your help.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/ApplicationStateManager-No-service-implements-the-interface-long-tp4891217p4891217.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ApplicationStateManager - No service implements the interface long.

Posted by Olga <ba...@list.ru>.
Thanks

--
View this message in context: http://tapestry.1045711.n5.nabble.com/ApplicationStateManager-No-service-implements-the-interface-long-tp4891217p4891444.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ApplicationStateManager - No service implements the interface long.

Posted by Muhammad Gelbana <m....@gmail.com>.
False credentials will return a null and then when you reference the 'user'
variable, just referencing it when it's null, tapestry attempts to create
the object using the constructor with the most parameters.

To overcome this and be able to check if 'user' is null there are 2 methods.

1. Is to add (create = false) to the @SeesionState annotation, so it ends up
like this @SessionState(create = false)
*Or*
2. Add a boolean following the naming convention *varname*Exists; So in your
case you'll have a private boolean userExists;
The new boolean variable will help you know if the object 'use' is
initialized.

If you would like tapestry to use a specific constructor, like the java's
default constructor, add the default constructor and annotate it with a
@Inject annotation. So you'll have a:

@Inject
public User(){}

I hope I was clear.

On Tue, Oct 11, 2011 at 11:41 AM, Olga <ba...@list.ru> wrote:

> Hello, i have this problem.
>
> When i try to login in my project with incorect name i have this error:
> Error invoking constructor com.htc.identity.entities.User(long, String,
> String) (at User.java:36) (for service 'ApplicationStateManager'): No
> service implements the interface long.
>
> On line 36 in User class i have:
>
>    public User(final long id, final String username, final String password)
> {
>        this.setId(id);
>        this.setUsername(username);
>        this.setPassword(password);
>    }
>
> My Login.java
>
> public class Login {
>
>    @Inject
>    private UserService userService;
>
>    @SessionState
>    private User user;
>
>    @Property
>    private String username;
>
>    @Property
>    private String password;
>
>    @Log
>    public Object onSubmitFromLoginForm() throws SQLException {
>        user = userService.getUser(username, password);
>        if (user != null) {
>            return Home.class;
>        } else
>            return null;
>    }
> }
>
>
> UserService:
>
> public class UserServiceImpl implements UserService {
>
>    private Map&lt;String, User&gt; users;
>
>    public UserServiceImpl(String userList, String passwordList) {
>        users = new HashMap&lt;String, User&gt;();
>        try {
>            String[] us = userList.split(",");
>            String[] pws = passwordList.split(",");
>            for(int i = 0; i < Math.max(us.length, pws.length); i++) {
>                users.put(us[i], new User(i, us[i], pws[i]));
>            }
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>    }
>
>    public User getUser(String username, String password) {
>        User user = users.get(username);
>        if (user != null && StringUtils.equals(user.getPassword(),
> password)) return user;
>        return null;
>    }
>
> }
>
>
> Thanks for your help.
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/ApplicationStateManager-No-service-implements-the-interface-long-tp4891217p4891217.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
*Regards,*
*Muhammad Gelbana
Java Developer*