0

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?

Thor
  • 6,607
  • 13
  • 62
  • 96
  • I have no idea what Seam Solder is and what it's supposed to do, but you can achieve the same underlying functional requirement with the standard JSF2 `` tag. – BalusC Feb 06 '12 at 16:06
  • Thank you for this workaround, currently I have removed the `@Inject @RequestParam` and use ``. – Thor Feb 08 '12 at 07:30

1 Answers1

0

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)

Thor
  • 6,607
  • 13
  • 62
  • 96