Hinzufügen von action-Methoden, um eine zusammengesetzte Komponente

Lerne ich über composite-Komponenten mit JSF 2.0 und ich möchte, dass meine Komponente auslösen zu können Methoden von backing beans, so habe ich ein einfaches Beispiel, aber etwas ist falsch.

Dies ist die Komponente, die ich erstellt:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
        <composite:attribute name="attribute1"/>
        <composite:attribute name="attribute2"/>
        <composite:attribute name="actionBtnText"/>
        <composite:attribute name="actionMethod" method-signature="java.lang.String action()"/>
</composite:interface>

<composite:implementation>
    <h:form>
            <h:inputText value="#{cc.attrs.attribute1}"/>
            <br/>
            <h:inputText value="#{cc.attrs.attribute2}"/>
            <br/>
            <h:commandButton action="#{cc.attrs.actionMethod}" value="#{cc.attrs.actionBtnText}"/>          
    </h:form>

</composite:implementation> 

</html>

Dies ist, wie ich es in einer JSF-Seite

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:custom="http://java.sun.com/jsf/composite/custom">

...

    <h:body>
    <custom:demoCustomComponent attribute1="#{demoBB.value1 }" attribute2="#{demoBB.value2 }" actionBtnText="Button text!" actionBtn="#{demoBB.act}"/>
    </h:body>

Und dies ist der backing-bean, gibt Unterstützung zu der Seite, wo die Komponente

@Named("demoBB")
@RequestScoped
public class DemoBB {

    private String value1;
    private String value2;
    public String getValue1() {
        return value1;
    }

    public String act() {
        System.out.println("Input 1: " + value1 + "\nInput 2: " + value2);
        return null;
    }

    //Getters and setters
    public void setValue1(String value1) {
        this.value1 = value1;
    }
    public String getValue2() {
        return value2;
    }
    public void setValue2(String value2) {
        this.value2 = value2;
    }   
}

Die Komponente scheint render gut, aber wenn ich auf den Knopf drücke, bekomme ich eine Ausnahme, die sagt:

javax.Gesichter.FacesException: Nicht lösen können-composite-Komponente aus
mit Seite mit EL-Ausdruck " #{cc.attrs.actionMethod}'

Habe ich einen Fehler in der Schnittstelle oder Implementierung der Komponente? Warum nicht arbeiten?

InformationsquelleAutor sfrj | 2011-10-18
Schreibe einen Kommentar