{"action":"created","issue":{"url":"https://api.github.com/repos/primefaces/primefaces/issues/2503","repository_url":"https://api.github.com/repos/primefaces/primefaces","labels_url":"https://api.github.com/repos/primefaces/primefaces/issues/2503/labels{/name}","comments_url":"https://api.github.com/repos/primefaces/primefaces/issues/2503/comments","events_url":"https://api.github.com/repos/primefaces/primefaces/issues/2503/events","html_url":"https://github.com/primefaces/primefaces/issues/2503","id":240940655,"number":2503,"title":"[PrimeFaces showcase] chat example is not working","user":{"login":"hitochan777","id":6002787,"avatar_url":"https://avatars1.githubusercontent.com/u/6002787?v=3","gravatar_id":"","url":"https://api.github.com/users/hitochan777","html_url":"https://github.com/hitochan777","followers_url":"https://api.github.com/users/hitochan777/followers","following_url":"https://api.github.com/users/hitochan777/following{/other_user}","gists_url":"https://api.github.com/users/hitochan777/gists{/gist_id}","starred_url":"https://api.github.com/users/hitochan777/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hitochan777/subscriptions","organizations_url":"https://api.github.com/users/hitochan777/orgs","repos_url":"https://api.github.com/users/hitochan777/repos","events_url":"https://api.github.com/users/hitochan777/events{/privacy}","received_events_url":"https://api.github.com/users/hitochan777/received_events","type":"User","site_admin":false},"labels":[{"id":198352641,"url":"https://api.github.com/repos/primefaces/primefaces/labels/defect","name":"defect","color":"fc2929","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-07-06T12:30:11Z","updated_at":"2017-07-10T11:14:09Z","closed_at":null,"body":"## 1) Environment\r\n- PrimeFaces version: 6.1\r\n- Atmosphere version: 2.4.12\r\n- Does it work on the newest released PrimeFaces version? Version?\r\nNo\r\n- Application server + version: GlassFish 4.1.2\r\n- Affected browsers:\r\nTested with Chrome only \r\n\r\n## 2) Expected behavior\r\nI am running [Chat example in showcase](https://www.primefaces.org/showcase/push/chat.xhtml).\r\n1. Users can login\r\n2. Users are notified when new users log in\r\n\r\n## 3) Actual behavior\r\n1. Nothing happens when I click \"Login\" button. This is because `init` annotated with `@PostConstruct` is not called and `ChatView.users` is `null`. ( I fixed the above problem by assigning the instance as the instance variable is declared. I am not sure if this is the right way to fix it. )\r\n2. Users are not notified when new users log in. \r\nIn ChatResource.java\r\n\r\n```\r\n    @OnClose\r\n    public void onClose(RemoteEndpoint r, EventBus eventBus) {\r\n        ChatUsers users= (ChatUsers) ctx.getAttribute(\"chatUsers\");\r\n        users.remove(username);\r\n         \r\n        eventBus.publish(room + \"/*\", new Message(String.format(\"%s has left the room\", username), true));\r\n    }\r\n``` \r\nThis is because `eventBus` is `null`.\r\n\r\n## 4) Steps to reproduce\r\nI used exactly the same code as [the chat example in PrimeFaces showcase](https://www.primefaces.org/showcase/push/chat.xhtml), except that I enabled the input textbox and button in the `chat.xhtml`.\r\n\r\n## 5) Sample XHTML\r\nSee [chat.xhtml](https://www.primefaces.org/showcase/push/chat.xhtml), and enable the textbox and button.\r\n\r\n## 6) Sample bean\r\nSee [Chat example](https://www.primefaces.org/showcase/push/chat.xhtml)\r\n\r\n## 7) Question\r\n1. What are the right way to fix the above problems?\r\n2. Is it possible to inject CDI bean (For example, a class annotated with `@javax.enterprise.context.ApplicationScoped`) to the class annotated with `@PushEndPoint`? It seems that we cannot inject either JSF beans and CDI beans. And `ServletContext.getAttribute` can only access JSF beans. An example is as follows.\r\n\r\nChatResource.java\r\n```\r\n@PushEndpoint(\"/{room}/{user}\")\r\n@Singleton\r\npublic class ChatResource {\r\n \r\n    @PathParam(\"room\")\r\n    private String room;\r\n \r\n    @PathParam(\"user\")\r\n    private String username;\r\n \r\n    @Inject\r\n    private ChatUsers users;\r\n \r\n   ...\r\n}\r\n```\r\n\r\nChatUsers.java\r\n```\r\n...\r\nimport javax.enterprise.context.ApplicationScoped;\r\n\r\n@ApplicationScoped\r\npublic class ChatUsers implements Serializable {\r\n     \r\n    private List<String> users;\r\n     \r\n    @PostConstruct\r\n    public void init() {\r\n        users = new ArrayList<String>();\r\n    }\r\n    ...\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/primefaces/primefaces/issues/comments/314076482","html_url":"https://github.com/primefaces/primefaces/issues/2503#issuecomment-314076482","issue_url":"https://api.github.com/repos/primefaces/primefaces/issues/2503","id":314076482,"user":{"login":"hitochan777","id":6002787,"avatar_url":"https://avatars1.githubusercontent.com/u/6002787?v=3","gravatar_id":"","url":"https://api.github.com/users/hitochan777","html_url":"https://github.com/hitochan777","followers_url":"https://api.github.com/users/hitochan777/followers","following_url":"https://api.github.com/users/hitochan777/following{/other_user}","gists_url":"https://api.github.com/users/hitochan777/gists{/gist_id}","starred_url":"https://api.github.com/users/hitochan777/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hitochan777/subscriptions","organizations_url":"https://api.github.com/users/hitochan777/orgs","repos_url":"https://api.github.com/users/hitochan777/repos","events_url":"https://api.github.com/users/hitochan777/events{/privacy}","received_events_url":"https://api.github.com/users/hitochan777/received_events","type":"User","site_admin":false},"created_at":"2017-07-10T11:14:09Z","updated_at":"2017-07-10T11:14:09Z","body":"@tandraschko OK, I will try."}}
{"actor":{"display_login":"hitochan777"}}