简体   繁体   中英

SEAM Solder @RequestParam in @ViewScoped Bean with AJAX

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM