1

I have a general JSF problem, I found no nice solution for yet. See the picture for a general idea. I have a workaround solution (sorry for the typo in the image) in place that solves the problem by a listbox. However the desired solution is to display all existing versions next to each other (probably always around 1-3).

solution overview

I have a view with a tree and picklist. There is a complex flow regarding the interaction between list and tree, e.g. you can only move models to subgroups, not top-level-groups and much more. I created a handler class that manages this behavior and translates it to service calls. Now, a new requirement came up. There are several versions of this tree that should be displayed all together on one page. My gut feeling is that managing n versions in one handler is a big mess as I need to store several things in the handler already for one version. In React, I would create a component that wraps the tree and all of the interaction. However, in JSF I'm not so sure what is the best practice here? I would be happy about suggestions and ideas, I'm not expecting Code :)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Uwe Bretschneider
  • 1,211
  • 8
  • 12
  • 1
    Just like react is an 'extension' to html/javascript, JSF has these too in the form of component suites. PrimeFaces e.g. has a [tree](https://www.primefaces.org/showcase/ui/data/tree/basic.xhtml) and other components which in combination with other components (which can be wrapped in composite components) seems to be what you need – Kukeltje Dec 03 '19 at 12:05
  • Nevermind, like Kukeltje I misunderstood your question, I deleted my previous comment. Your question is after all a duplicate of https://stackoverflow.com/questions/6822000/when-to-use-uiinclude-tag-files-composite-components-and-or-custom-componen Probably a composite component with a backing component is what you're after. – BalusC Dec 03 '19 at 12:26
  • Thanks guys, but I think composite components don't cover all my requirements as I would still need separate handlers for that, right? The handler also forwards actions on the view to a service component. I cannot see a way, how I would do that with a composite component. – Uwe Bretschneider Dec 03 '19 at 12:55
  • No not specifically. As long as you pass a reference to the specific dataset, you can have generic handlers. – Kukeltje Dec 03 '19 at 13:47

1 Answers1

0

I found a solution that fits my needs and I post it here hoping that it might help other people as well :)

So on my view I have several tree views with complex interactions. For example, if an item within the tree is moved, the operation is immediately reflected in the database. As I use JPA, I need to translate this to an entitymanager call. The views are either displayed in a list or just one-at-a-time via a dropdown select.

Anyway, the idea is that every complex view component has its own controller with a reference to an entitymanager and a transaction, while having just one JSF handler class. If JSF would allow to create multiple handlers (like #{handler_1}, {handler_2}), the problem could be solved in a different way. But as JSF works name based and the name {#handler} always refers to the same container managed thing, this is no option.

enter image description here

The handler class is ViewScoped (or SessionScoped, if you prefer). For each tree component it has a ComponentController class that receives the EntityManager and the UserTransaction as well as the related data form the handler via constructor injection. This way, the handler can delegate all commands to the Controller while being DRY.

With this solution, the controller logic can be re-used regardless how many tree components exist. Each view elements binds a specific controller via handler.controllers.get(id).

All other solutions did not work for me as they are not able to perform database operations on view interactions.

Uwe Bretschneider
  • 1,211
  • 8
  • 12