Domanda

Ho creato un componente facelet per estendere h:. CommandLink (per aggiungere alcune funzionalità e angoli arrotondati)

<ui:composition 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">
    <span class="btn-left btn-corners">&#160;</span>
    <span type="submit" class="submit">
        <h:commandLink id="#{id}" value="#{label}" action="#{action}" />
    </span>
    <span class="btn-right btn-corners">&#160;</span> </ui:composition>

Il mio nuovo componente si può accedere utilizzando

<my:commandLink id="continue" label="continue" action="#{applyBacking.submit}"/>

e il codice Java è

public String submit(){
    ...
}

Tuttavia mi dà un errore "ApplyBacking non ha la proprietà submit". Capisco il motivo per questo errore perché oltre che a rendere la mia: commandLink, si cerca di valutare # {} applyBacking.submit a una proprietà. Invece, voglio che l'informazioni sul metodo per l'invocato (applyBacking.submit) da passare al modello e valutati durante il rendering h:. CommandLink

Qualche suggerimento?

È stato utile?

Soluzione

Crea un componente composito invece ( tutorial qui ), consente per definire le azioni di fagioli come attribtues.

Ecco un esempio kickoff:

/resources/components/commandLink.xhtml

<ui:component
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:cc="http://java.sun.com/jsf/composite">
    <cc:interface>
        <cc:attribute name="id" required="true" />
        <cc:attribute name="label" required="true" />
        <cc:attribute name="action" method-signature="java.lang.String action()" required="true" />
    </cc:interface>
    <cc:implementation>
        <span class="btn-left btn-corners">&#160;</span>
        <span type="submit" class="submit">
            <h:commandLink id="#{cc.attrs.id}" value="#{cc.attrs.label}" action="#{cc.attrs.action}" />
        </span>
        <span class="btn-right btn-corners">&#160;</span>
    </cc:implementation>
</ui:component>

/somepage.xhtml

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:my="http://java.sun.com/jsf/composite/components">
    <h:head>
        <title>SO question 4608030</title>
    </h:head>
    <h:body>
        <h:form>
            <my:commandLink id="continue" label="continue" action="#{applyBacking.submit}"/>
        </h:form>
    </h:body>
</html>

A proposito, io preferirei personalmente usando JS / jQuery per l'angoli arrotondati parte, ad esempio l'angolo jQuery plug . Basta dare il vostro commandLink una specifica styleClass e lasciare JS fare la magia.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top