Rachel
Rachel

Reputation: 103397

JSF: How to initialize bean that am passing using @managedProperty to my managedBean?

In my managedBean, fileUpload : Am calling other beans using @ManagedProperty as shown in code, now later in my class i have something like rtParser.getQuote() but it throws NullPointerException, my question is:

How can I initialize rtParser in this class?

@ManagedProperty(value = "#{rtParser}")
private PositionParserRT rtParser;

public PositionParserRT getRtParser()
{
    return rtParser;
}

public void setrtParser(PositionParserRT rtParser)
{
    this.rtParser = rtParser;
}

Updated

I am having similar kind of issue here and would highly appreciate any suggestions.

Upvotes: 0

Views: 456

Answers (1)

BalusC
BalusC

Reputation: 1108537

The way as you use @ManagedProperty expects the PositionParserRT to be a @ManagedBean too. So put that annotation on the class.

@ManagedBean
@SomeScoped // TODO: Choose the suitable scope.
public class PositionParserRT {
    // ...
}

But if that class is already not a JSF managed bean in the first place (i.e. it has nothing do to with JSF views/models), then you're probably looking for the solution in the wrong direction. If it's a business service, rather make it a @Stateless EJB and inject it by @EJB instead.

@Stateless
public class PositionParserRT {
    // ...
}

with

@EJB
private PositionParserRT rtParser;

Upvotes: 1

Related Questions