0

I want to implement CDI event on a managed bean with @ViewScoped
this is my example code :
CDI managed bean for JSF:

@ViewScoped
@Named
public class SampleBean implements Serializable {

    public void pushEvent(@Observes String str) {
        System.out.println("Bean " + str);
    }
    // And other methods and properties .
}

Stateless Service :

@Stateless
@LocalBean
public class ExampleService {

    @Inject
    private Event<String> event;


    public void execute(String str) {
        event.fire(str);
    }
} 

JaxRs :

@Path("/test")
@RequestScoped
public class ExampleResources {

    @EJB
    private ExampleService service;

    @GET
    @Path("/execute")
    @Produces("application/json")
    public Response executeOperation(@QueryParam("str") String str) {
        service.execute(str);
        return Response.ok("String : " + str).build();
    }
}    

I want to sent event to JSF bean from Rest or soap web services .
I used JavaEE 8 webprofile on Liberty 18.0.0.x .
What is mistake ? How can fix this problem ?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
mah454
  • 1,571
  • 15
  • 38
  • How is the jax-rs related? – Kukeltje Jan 24 '19 at 11:43
  • Amd ypu don't send the event from jax-rs or soap, you send it from your service. Soap or jax-rs endpoint just fires your service. Or can you get it to work if you trigger from another cdi/jsf managed bean – Kukeltje Jan 24 '19 at 11:45
  • Duplicate? https://stackoverflow.com/questions/37117457/asynchronous-cdi-events-and-an-observes-method-in-named-bean just like with asynchronous there is no viewscoped bean in the curremt thread – Kukeltje Jan 24 '19 at 12:02
  • @Kukeltje sorry , I can not understand ! , can you give me a example code ? – mah454 Jan 24 '19 at 13:40

0 Answers0