The problem I see with your method is mixing server code and jQuery code, as it can become difficult to maintain.
With your menu, I would do it all with jQuery, exporting the currentItem
var to javascript and adding classes from then on.
var currentItem = 'Visualizza elenco dei Brand';
$(document).ready(function(){
var currentAnchor = $("a[title='" + currentItem + "']");
currentAnchor.addClass("open");
currentAnchor.parents("ul").show();
currentAnchor.parents("li.mainmenu").children("a").addClass("open");
});
If you go all server side you eliminate the flickering of the menu in slow machines or old browsers, but it really depends on your actual jsf code generating the menu to know how difficult is to do it all on server side.