2012-08-16 47 views
3

我想写一个或多或少的gemeric组件,其中我交入一个控制器bean,并且组件应该显示一些CRUD按钮。我可以在复合组件中的bean上调用方法吗?

下面的复合物成分:

<composite:interface> 
    <composite:attribute name="controller" /> 
    <composite:attribute name="object" /> 
</composite:interface> 

<composite:implementation> 

    <h:panelGrid columns="3" columnClasses="celltop"> 
    <h:commandButton id="save" value="#{msg.saveButtonLabel}" 
     action="#{cc.attrs.controller.save}" /> 
    <h:commandButton id="delete" value="#{msg.deleteButtonLabel}" 
     action="#{cc.attrs.controller.delete(cc.attrs.object)}" /> 
    <h:commandButton id="cancel" value="#{msg.backButtonLabel}" 
     action="#{cc.attrs.controller.cancel}" immediate="true" /> 
    </h:panelGrid> 

</composite:implementation> 

<viewController:buttons controller="customerController" object="#{customerController.customer}"/> 
@Named 
@ConversationScoped 
public class CustomerController implements Serializable { 

    public String cancel() { 
    customer = null; 
    if (!conversation.isTransient()) { 
     conversation.end(); 
    } 
    return "cancelled"; 
} 

导致以下情况例外,当我点击取消按钮:

javax.faces.el.MethodNotFoundException: javax.el.MethodNotFoundException: /resources/components/viewController/buttons.xhtml @25,65 action="#{cc.attrs.controller.cancel}": Method not found: customerController.cancel() 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:92) 

它是不可能的呼吁给予CC豆方法?

回答

3

是的,你可以。你的错误就是,你只传递一个普通的String代表托管bean的名称作为属性值

controller="customerController" 

,而你实际上应该已经从EL范围通过具体的管理bean实例

controller="#{customerController}" 

的异常消息肯定有些误导,但它基本上只显示属性值的Object#toString()。没有发现如果它是一个具体的管理bean实例,你宁愿看到过类似

方法:[email protected]()

或无论是被退回其toString()实施,如果重写。

+0

eieiei :)再次感谢。 – Joysn 2012-08-16 20:33:49

+0

不客气。 – BalusC 2012-08-16 20:38:09

相关问题