• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF Dynamic ContextMenu from Backing Bean  RSS feed

 
Roberto Bottino
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i need help about creation of a contextmenu programmatically in JSF 1.2
I have an xhtml page with this ContextMenu:



I have a datatable and when i right-click on the row, i want the contextmenu appear:



I have a backing bean with this methods:






The problem is: it renders corretly what i want, but when i click on the MenuItem "Attributi" the js auto-rendered from JSF gives this error (multiple error from console of Browser)

Uncaught SyntaxError: Unexpected identifier

and the row when it gives problem is:




If someone notice some big error in the creation of the ContextMenu from backing bean, please tell me, because i can't see the error.

Thanks in advance, have a nice day.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Roberto!

JSF 1.2 is very old now. You really need to consider moving to JSF2 AND to RichFaces 4, since RichFaces 3 doesn't support Internet Explorer past IE8 and Microsoft will be withdrawing all IE8 support in less than a year.

Also, please note that you cannot use EL for the JSF "id" attribute. It won't function properly. While most JSF attributes do support EL expressions, the id attribute is one that does not (see the JavaDocs).

A much cleaner approach to constructing a ContextMenu dynamically would be to make it a 1xn dataTable, where each row holds one menu option. You would then use AJAX to re-render the table when the menu options (represented by the table's DataModel) change. That would avoid all that arcane code involved with binding. The actual presentation of the menu is done in Javascript by changing the CSS visible/invisible and screen co-ordinate information for the table.

However, better yet would be to go back and review the RichFaces documentation, since I think they already have an option to do what you want without having to do either binding code or roll-your-own javascript.
 
Roberto Bottino
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info Tim! The big problem is: I can't move to JSF2 and RichFaces 4 and I must fight against JBoss 5.1 GA bugs - JSF 1.2 bugs and Richfaces 3.3.3 bugs....
I'll try to correct the EL id approach and see if they have effects on the final result.

P.S. How can i make a datatable 1xn with each row has is own contextmenu?
As I understand.... you mean a datatable for every row? The contextmenu is defined on the datatable (as far as i know).
If you can tell me how make a context menu for every row, I'm very happy to try your solution.

Now I'm downloading the RichFaces documentation and seach for something useful.

Thanks in advance, have a nice day.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly urge that you keep your CV handy and up-to-date. If you really have no choice then you are standing on a small island and it's getting smaller all the time.

I will confess that I don't keep all of my systems running on the leading edge, but JBoss 5 went end-of-life in 2012 and Red Hat dropped all support for it over six months ago back in 2014. Any problems you have with JBoss 5 you would find hard to get any external support on even if you paid for it. As a matter of fact, even JBoss 6 will be in end-of-life in less than 2 weeks time.

Some people think that software is forever. That is not true. Software rots from the outside in. OS's become incompatible, hardware becomes incompatible, clients (browsers) become incompatible - and note especially what I said about Microsoft and IE 8 and RichFaces. You cannot pay for software as a one-time thing. It's an ongoing expense and the longer you put off keeping it maintained, the more it's going to cost when it finally collapses entirely, just like the roof on your house. Someone needs to decide whether it's worth spending time and money now or whether they want to do work on something that's likely to utterly collapse before the work has paid for itself. Unless they simply plan to ride that horse until it dies and then walk away from it. In which case I'd definitely keep the CV handy.

And, having made that admonition, let me proceed on.

A 1xn table is very simple it's merely a table with a single column defined. The "n" is the variable number of rows in the backing model, where each row is a single string value of the menu text. Or, if you prefer, the text plus useful (but undisplayed) data for when the menu is selected. You could just as easily do it with a 1-column panelgrid, but the dataTable allows you a more dynamic means of adding/removing rows without complex logic.

The table is simply a rectangular section of display. What else is a rectangular section of display? How about a ContextMenu?

So you can use this table as a ContextMenu by A) hiding it when the menu is invisible and B) using CSS positioning values to move it to wherever on the screen you want the menu to appear.

Actually, it's not uncommon to use an DIV and/or TABLE in exactly this manner in non-JSF webapps. RichFaces also uses this mechanism for its pop-up menus and dialog (ModalPanel) tags.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!