jQuery in Action, 2nd edition*
The moose likes JSF and the fly likes JSF UiComponent help required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF UiComponent help required" Watch "JSF UiComponent help required" New topic
Author

JSF UiComponent help required

Kumar Gaurav
Ranch Hand

Joined: Apr 08, 2008
Posts: 108
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.

Regards,
Gaurav
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kumar Gaurav
Ranch Hand

Joined: Apr 08, 2008
Posts: 108
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

Joined: Jun 25, 2001
Posts: 16160
    
  21

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

Joined: Apr 08, 2008
Posts: 108
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
 
subject: JSF UiComponent help required