0

Currently, I try to make a game based on JSF 2.x with XHTML, JavaScript and Java as back-end. This game is round based with up to 6 players. Creating player (objects) and make some settings on it (like the name) works well with the getter and setters. But at the end of the round I have some troubles. I have the following plan:

When a player has finished his inputs, he clicks on "end round". With this button he sets his player status in his player object to "ready". Now a modal dialog appears (made with Bootstrap) where he can see whether the other players are ready or not(feature nearly finished with hidden commandbutton and AJAX command). This view updates every 5 seconds. I plan to use the setinterval feature of JavaScript for this. And now the problem: JSF resolves all "#{xxx}" tags when loading the page. So I can not call a method with "#{}" multiple times, because its already gets resolved on loading. I also can not use AJAX to call the methods multiple times, because the method for example"#{player.setready}" would fire at startup and set the player to ready state. I also can not use a commandbutton. This button works only with the result of reloading the complete page.

Maybe I misunderstand the way JSF works.

Is it possible to have a functon, which gets not resolved at loading and can be called multiple times?

I am really desperate at this moment, because I am not able to solve this problem alone.

JAL
  • 41,701
  • 23
  • 172
  • 300
tiga05
  • 3
  • 1
  • 7
  • 2
    You indeed misunderstand JSF, not only how it works but also what its intent is. Likely JSF actually has very little to do in your stack; the game is javascript and that is where your "multiple calls" happen - javascript functions. The communication to the backend is better served through some other means. Websockets and RESTful webservice are two good considerations. – Gimby Oct 29 '15 at 20:57
  • Just stop doing business logic in getter methods. There they are not for. They are there to let the view access the model, not invoke the business logic. JSF has several different hooks to invoke business logic. They are all summarized in the abovelinked duplicate. – BalusC Oct 30 '15 at 09:33
  • You are right guys! I reworked my game and now the setters are only setters and the getters are only getters. I also included Primefaces. With it is very easy to update informations on the view of another players. With the Primeface ajax Buttons i can fire events when i want them to fire without reloading the page. Primefaces has also some cool Features to reduce the amount of Javascript. Much work is now done at the backend in the Java code. – tiga05 Oct 30 '15 at 17:16

0 Answers0