Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF UiComponent help required

 
Kumar Gaurav
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I notice a bizarre scenarion which is :

In my page xhtml page following is the component

<rich:menuItem id="menu_home" value="Home" actionListener="#{menuBean.onclickMenu}" disabled="#{menuBean.homeActive}">
<f:attribute value="pages/home.jsf" name="menuUrl"></f:attribute>
</rich:menuItem>


in backing bean in onclickmenu method i am settting the styleClass of this component but it is not getting reflected in the page.

public void onclickMenu(ActionEvent event) {

Object obj = event.getSource();
if ((obj instanceof HtmlMenuItem)) {
HtmlMenuItem item = (HtmlMenuItem)obj;
item.setStyleClass("activeLinkMenu")
}
// rest of code related to navigation
}
this styleClass is not getting applied to menuItem, even if i am using following <a4j:support event="onclick" reRender="menu_home"/> wrapped between menu item.

But when i am writing menuitem like this

<rich:menuItem id="menu_home" value="Home" actionListener="#{menuBean.onclickMenu}" styleClass="activeLinkMenu"
disabled="#{menuBean.homeActive}">
<f:attribute value="pages/home.jsf" name="menuUrl"></f:attribute>
</rich:menuItem>

Then it is getting reflected.

can any one please provide any pointer why it is like so.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17625
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably because the UIComponent property "styleClass" isn't the actual style class name, it's an EL expression. Which means that to work properly, you'd have to add logic to properly handle EL.

It's not worth the trouble. Just create a new backing bean property. Let's call it "menuStyle". Now in your menu action method, set it.


And modify the VDL code to match:


You may need to add reRender and/or ajaxSingle attributes to get the re-rendering to be done at the desired time.
 
Kumar Gaurav
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

But problem is there are numerous menuItem in my page and the way you are proposing , it involves to have menustyle attribute in managedbean for each item which may run into say 50.

Also at one time this style needs to be applied to only one menuitem. so i went with this approach.

Can we have any other pointer.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17625
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, for this particular case, I'd probably use JavaScript to change the style, not JSF. But there are ways to make the getMenuStyle method sensitive to which menuitem it's rendering for.
 
Kumar Gaurav
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Tim,

Can you please share a code snippet for the way you are suggesting.

it would be great.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic