HtmlCommandLink generation within custom component
Hey everybody, I had a previous post similar to this, but after solving the one problem I was having another one arose that I'm not sure how to fix either. I've been scouring google and the forums for a definite answer on this to no avail. So, here's my problem again:
I've created a menuBar component that consists of images, tomahawk swap images, and command links. I use the component this way in my pages:
<or:menuBar pageClass="#{menuBarBean.PAGECLASS_HOME}" msg="foo!" />
In my renderer for this component, I have set up HtmlCommandLinks which are supposed to invoke navigation methods in my MenuBarBean. However, when you click on one of the links, it seems as if the MethodBinding is never invoked, because the page just refreshes and never goes into the corresponding backing bean method. Strangely enough, if you provide an erroneous method name for the method binding such as "#{menuBarBean.FakeMethod}", faces doesn't even give a warning.
All the piping seems to be working for the tag and the component.. meaning the "pageClass" and "msg" attributes get set and rendered properly on the menuBar. Also the thing renders correctly, but I have a feeling that I'm not setting the MethodBinding correctly for the "Action" property of the CommandLink, or I'm not setting it in the right place. Here's an abbreviated version of the code behind the component:
In my 'MenuBar.java' class:
publicvoid setHomeBinding(MethodBinding mb)
{ homeBinding = mb;}
public MethodBinding getHomeBinding()
{return homeBinding;}
There is also code in this class for stat management that saves and restores the values of the menuBar. I found that if I didn't do this, the "msg" attribute was cleared on refresh.
In the 'setProperties' method of my 'MenuBarTag.java' class:
MethodBinding mb = getFacesContext().getApplication().createMethodBinding("#{menuBarBean.gotoHome}",null);
menuBar.setHomeBinding(mb);
In the 'encodeEnd' method of 'MenuBarRenderer.java' (Here's where I create the link and set the Action to the MethodBinding)
// If is this class, show a selected tab
if(menuBar.getPageClass().equals(MenuBarBean.PAGECLASS_HOME))
{
HtmlGraphicImage homeButton = (HtmlGraphicImage)application.createComponent(HtmlGraphicImage.COMPONENT_TYPE);
homeButton.setUrl(IMG_HOME_SRC_SELECTED);
menuBar.getChildren().add(homeButton);
}
// else Render the button
else
{
HtmlSwapImage homeSwapImg = (HtmlSwapImage)application.createComponent(HtmlSwapImage.COMPONENT_TYPE);
homeSwapImg.setUrl(IMG_HOME_SRC_IDLE);
homeSwapImg.setSwapImageUrl(IMG_HOME_SRC_OVER);
homeSwapImg.setStyleClass("menuBarButton");
HtmlCommandLink homeButton = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
homeButton.setAction(menuBar.getHomeBinding());
homeButton.setId("homeButton");
homeButton.getChildren().add(homeSwapImg);
menuBar.getChildren().add(homeButton);
}
menuBar.getChildren().add(spacer);
RendererUtils.renderChildren(facesContext, menuBar);
menuBar.getChildren().removeAll(menuBar.getChildren());
And finally, in my MenuBar backing bean 'MenuBarBean.java'
public String gotoHome()
{return("goto-home");}
public String getPAGECLASS_HOME()
{return PAGECLASS_HOME;}
So that's pretty much it. Like I said, the thing appears to be rendered correctly and looks like I want it to look. Unfortunately, the buttons don't do anything because I guess I'm not creating the HtmlCommandLinks properly, or I'm just leaving something out. Does anybody have any idea as to why the links aren't working based the on the above code? There are no exceptions being thrown or any warnings coming up in the console at all, so unfortunately there's no more information I can give you of what's happening within the framework.

