嗨,我需要将 h:commandLink 操作动态设置为 bean 端的字符串值。这里解释了我的代码 MenuObject.java 的问题
public class MenuObject {
private String menuName;
private String menuAction;
public String getMenuName() {
return menuName;
}
public void setMenuName(String menuName) {
this.menuName = menuName;
}
public String getMenuAction() {
return menuAction;
}
public void setMenuAction(String menuAction) {
this.menuAction = menuAction;
}
}
MenuCreator.java
public class MenuCreator {
public List getMenu(){
List menuList = new ArrayList();
MenuObject menu1 = new MenuObject();
menu1.setMenuAction("accountController.beginSearch()");
menu1.setMenuName("Account");
menuList.add(menu1);
MenuObject menu2 = new MenuObject();
menu2.setMenuAction("companyController.beginSearch()");
menu2.setMenuName("Company");
menuList.add(menu1);
return menuList;
}
main.xhtml
<ui:repeat value="#{menuCreator.menu}" var="subMenu">
<li class="glyphicons cogwheels"><h:commandLink action="#{subMenu.menuAction}"><i></i><span><h:outputText value="#{subMenu.menuName}"/></span></h:commandLink></li>
</ui:repeat>
这里我需要的是我需要根据 bean 字符串值动态更改 commandlink 操作值(这里是 menuAction)。但在这种情况下,我得到了以下异常
javax.el.MethodNotFoundException: /WEB-INF/layouts/main.xhtml @137,85 action="#{menuCreator.menu}": Method not found: com.util.MenuObject@30c96021.menuAction()
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101)
at net.bull.javamelody.JsfActionListener.processAction(JsfActionListener.java:65)