Extension de composant JSF commandLink
Question
I créé un composant Facelet pour étendre h: commandLink (pour ajouter des fonctionnalités et des coins arrondis)
.<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"> </span>
<span type="submit" class="submit">
<h:commandLink id="#{id}" value="#{label}" action="#{action}" />
</span>
<span class="btn-right btn-corners"> </span> </ui:composition>
Mon nouveau composant est accessible via
<my:commandLink id="continue" label="continue" action="#{applyBacking.submit}"/>
et le code Java est
public String submit(){
...
}
Cependant, il me donne une erreur « ApplyBacking ne pas soumettre la propriété ». Je comprends la raison de cette erreur, car tout en rendant mon: commandLink, il essaie d'évaluer # {} applyBacking.submit à une propriété. , Je veux plutôt que les informations sur la méthode à invoquer (applyBacking.submit) à transmettre au modèle et évalué tout en rendant h:. CommandLink
Toutes les suggestions?
La solution
au lieu ( tutoriel ), il vous permet de définir des actions de haricots comme attribtues.
Voici un exemple de coup d'envoi:
/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"> </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"> </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>
Par ailleurs, personnellement, je préfère utiliser JS / jQuery pour la partie des coins arrondis, par exemple coin jQuery plug-in . Il suffit de donner votre commandLink un styleClass
spécifique et laissez JS faire la magie.