我创建了一个Facelet组件来扩展h:commandLink (添加一些功能和圆角)。
<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>可以使用以下命令访问我的新组件
<my:commandLink id="continue" label="continue" action="#{applyBacking.submit}"/>Java代码是
public String submit(){
...
}然而,它给我一个错误"ApplyBacking没有提交属性“。我理解这个错误的原因,因为在呈现my:commandLink时,它会尝试将#{applyBacking.submit}赋值为一个属性。相反,我希望将有关被调用方法(applyBacking.submit)的信息传递给模板,并在呈现h:commandLink时进行计算。
有什么建议吗?
发布于 2011-01-06 03:25:41
而不是创建一个composite component (tutorial here),它使您能够将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>/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>顺便说一下,我个人更喜欢在圆角部分使用JS/jQuery,例如jQuery corner plugin。只需给你的命令链接一个特定的styleClass,让JS来施展魔法。
https://stackoverflow.com/questions/4608030
复制相似问题