-1

I am currently trying to create a p:menubar which has one dynamically created submenu, but all the other submenus should be normally declared in the xhtml. Sadly I couldn't find any information on how to do so, as it seems that you always have to create a MenuModel and use that as the model for a complete p:menubar.

When just using two separate menubars it is possible to have multiple submenus open at the same time, which leads to them overlapping. And also the spacing is wrong then.

EDIT: I can't use JSTL, so the solution with c:forEach is not possible. It has to be dynamic because the items are loaded from the database on each request.

EDIT 2: I could use JSTL, but I still don't really grasp how this could best be accomplished. I wan't to have a menubar with some submenus being normal static ones, but one submenu is built dynamically in the code (for every request, nothing with ajax). This dynamic submenu however has multiple child submenus which have their own children in turn, so in theory I would have to somehow iterate recursively over all children.

I am using Primefaces 8.0 and JSF 2.2

F0X
  • 370
  • 4
  • 13
  • Hi, some comments: 1: PF version missing (adding JSF version and impl is good too). And how 'dynamic' is dynamic? Then does it have to change? – Kukeltje Jun 16 '20 at 11:16
  • Does this answer your question? [Mixing static and dynamic menu entries in PrimeFaces menu components](https://stackoverflow.com/questions/47064923/) – Kukeltje Jun 16 '20 at 11:17
  • @Kukeltje no it doesn't, as i can't use c:forEach. I currently don't have the code here and therefor can't check the PF version, i'm going to update my question when I have it (probably not before Friday) – F0X Jun 17 '20 at 15:53
  • You **can't** use a `c:forEach`? That can only be when you also need to update the menu with ajax. Otherwise there is no reason. And this is such a fundamental thing that it should be added to the question. – Kukeltje Jun 17 '20 at 16:12
  • And then the answer is going to be simple and four fold: 1) Do all in a model 2) Don't update via ajax and use the duplicate 3) Override the PrimeFaces source. 4) Don't use a dynamic menu – Kukeltje Jun 17 '20 at 16:18
  • I actually don't update via ajax, but the project does not use jsp and jstl, and I do not wan't to or am allowed to use it just for this one thing. – F0X Jun 17 '20 at 17:04
  • ok then I'm sorry that I understood that wrong, its just that it's called `JavaServer Pages Standard Tag Library` and is found under (http://java.sun.com/jsp), so I assumed it belonged to jsp somehow. Still, the project does not use jstl in any way (and as far as I know we should not do so), so yeah its a bit annoying – F0X Jun 17 '20 at 17:57
  • _"(and as far as I know we should not do so)"_ Hmmm... So you (and obviously (some of) your colleagues) don't know a certain very common and usefull technology and/or don't use it, and than a rather vague 'as far as...' is the justification? That is rather weird, sorry. So if someone asks you to write something to standard out in this project, you say you can't use `System.out.println` since nobody uses it? But at the same time you ask us how to write something to standard out? Very, very weird. Drop the buts ifs etc and just use jstl what it was meant for:**Precisely these kinds of usecases** – Kukeltje Jun 17 '20 at 18:23
  • And please read [JSTL in JSF2 Facelets… makes sense?](https://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense) – Kukeltje Jun 17 '20 at 18:27
  • 1
    Thank you very much, I'm definitely going to read up on JSTL now. – F0X Jun 18 '20 at 16:22
  • Ok so im sorry if this is another stupid question, but im a bit unsure on how to implement the desired behavior with `c:forEach`, because i'd still have to manually iterate over the submenus and create a `p:submenu` with the values, which I would have to do recursively for all children, right? – F0X Jun 19 '20 at 11:37
  • Yes, if you need recursive things, yes... If it is a limited numberof levels deep it should however not be a problem. If the number of levels deep is undefined (I'd hope there be no more than 4) maybe some other solution would be better but I'd need to see if there are existing Q/A in stackoverflow (which I'm pretty sure there are). And effectively this is a new question... ;-) – Kukeltje Jun 19 '20 at 15:42
  • related: https://stackoverflow.com/questions/3493395/recursion-in-jsf-cforeach-vs-uirepeat – Kukeltje Jun 19 '20 at 15:43

1 Answers1

0

Thank you Kukeltje for answering my questions, I now ended up using c:forEach like in the linked post.

F0X
  • 370
  • 4
  • 13
  • If it is a duplicate, no need to create an answer and just comment (or vote if you can) as a duplicate or upvote the duplicate comment.. Cheers. – Kukeltje Jun 23 '20 at 17:18