Reputation: 243
I hava a class below;
package org.domain.emlakprojesi.session;
import java.util.List;
import javax.persistence.EntityManager;
import org.domain.emlakprojesi.entity.ziyaretci;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;
@Name("authenticator")
public class Authenticator
{
@Logger private Log log;
@In Identity identity;
@In Credentials credentials;
@In EntityManager entityManager;
@Out(scope =ScopeType.SESSION,required=false) ziyaretci girisYapanZiyaretci;
public boolean authenticate()
{
log.info("authenticating {0}", credentials.getUsername());
List<ziyaretci> ziyaretciler =entityManager.createQuery("from Ziyaretci where email = #{credentials.username} and sifre = #{credentials.password}").getResultList();
if(ziyaretciler.size() == 1){
this.setGirisyapanziyaretci(ziyaretciler.get(0));
return true;
}else
return false;
}
public void setGirisyapanziyaretci(ziyaretci girisyapanziyaretci) {
this.girisYapanZiyaretci= girisyapanziyaretci;
}
public ziyaretci getGirisyapanziyaretci() {
return girisYapanZiyaretci;
}
}
I am setting the girisYapanZiyaretci in authenticate method
when I run the application I am getting null pointer exception
I actually ask when @In and @Out annotations work?
Upvotes: 0
Views: 4122
Reputation: 3867
@In
annotation gets tree parameters: value, create
and required
In Seam documantation there is brief explanation en examples.
Specifies that a component attribute is to be injected by evaluating a JSF EL expression at the beginning of each component invocation.
value — specifies the name of the context variable. Default to the name of the component attribute. Alternatively, specifies a JSF EL expression, surrounded by #{...}.
create — specifies that Seam should instantiate the component with the same name as the context variable if the context variable is undefined (null) in all contexts. Default to false.
required — specifies Seam should throw an exception if the context variable is undefined in all contexts.
Maybe create
parameter, which creates Context Variable
if it is null, helps you about your problem.
@In(create = true)
Upvotes: 0
Reputation: 1927
Injection with @In
and the so-called outjection with @Out
work before and after the method call.
All @In
properties are injected before the method is invoked, and all @Out
properties are set in the defined context after the invocation, unless the method raised an exception.
Session scope is broader than the event scope, so if a session scoped beans is injected in an event scoped bean, the event scope (and the event scoped bean) is destroyed before the session scoped bean.
On the contrary, if an event scoped bean is injected in a session scoped bean (or in any other broader scope context), the value is injected before the method call and set to null
after the method call.
Regarding injection and JSF phases, injection happens after the update model values phase and inside the invoke application phase. @Filter
and @Converter
break this rule, though.
Upvotes: 2