I have a @ViewScoped
@ManagedBean
with a @RequestParam
to initialize some stuff in my @PostConstruct
method.
@ManagedBean @ViewScoped
public class MyBean implements Serializable
{
@javax.inject.Inject
@org.jboss.solder.servlet.http.RequestParam("id")
private long id;
@PostConstruct
public void init() {...}
...
}
The id is injected correctly with calls like test.jsf?id=1357
, but now I want to add some p:ajax
stuff in my xhtml page. This works fine if I remove the @Inject @RequestParam
(and have the hardcoded id
in init()
), but if I want to use this injection nothing happens and Firebug gives me this response:
<partial-response><error>
<error-name>class java.lang.IllegalStateException</error-name>
<error-message><![CDATA[Can not set long field MyBean.id to null value]]></error-message>
</error></partial-response>
Changing the type to private Long id
results in
<partial-response><error>
<error-name>class java.lang.IllegalStateException</error-name>
<error-message><![CDATA[]]></error-message>
</error></partial-response>
How can I use the @RequestParam
in a @ViewScoped
Bean?
The id
must be encapsulated in a javax.enterprise.inject.Instance;
to be used with Seams RequestParam
.
@javax.inject.Inject
@org.jboss.solder.servlet.http.RequestParam("id")
private Instance<Long> id;
(In the meantime I switched from @ManagedBean @ViewScoped
to @Named @ViewScoped
, but I think this is not relevant to this question)