扩展JSF commandLink组件
我创建了一个Facelet组件来扩展h:commandLink(添加一些功能和圆角) 但是,它给了我一个错误“ApplyBacking没有submit属性”。 我理解此错误的原因,因为在呈现my:commandLink时,它试图对属性#{applyBacking.submit}求值。相反,我希望有关被调用的(applyBacking.submit)方法的信息传递到模板,并在呈现h:commandLink时进行计算 有什么建议吗?创建一个instead(),它允许您将bean操作定义为属性 以下是一个启动示例:扩展JSF commandLink组件,jsf,jsf-2,Jsf,Jsf 2,我创建了一个Facelet组件来扩展h:commandLink(添加一些功能和圆角) 但是,它给了我一个错误“ApplyBacking没有submit属性”。 我理解此错误的原因,因为在呈现my:commandLink时,它试图对属性#{applyBacking.submit}求值。相反,我希望有关被调用的(applyBacking.submit)方法的信息传递到模板,并在呈现h:commandLink时进行计算 有什么建议吗?创建一个instead(),它允许您将bean操作定义为属性 以下是
/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>
<!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>
顺便说一句,我个人更喜欢对圆角部分使用JS/jQuery,例如。只需给您的commandlink一个特定的样式类
,让JS发挥神奇的作用
public String submit(){
...
}
<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>
<!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>