我创建了一个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>
Run Code Online (Sandbox Code Playgroud)
我的新组件可以使用
<my:commandLink id="continue" label="continue" action="#{applyBacking.submit}"/>
Run Code Online (Sandbox Code Playgroud)
而Java代码是
public String submit(){
...
}
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误"ApplyBacking没有提交属性".我理解这个错误的原因是因为在渲染my:commandLink时,它试图将#{applyBacking.submit}评估为属性.相反,我希望将有关调用方法的信息(applyBacking.submit)传递给模板,并在渲染h:commandLink时进行评估.
有什么建议?
相反,创建一个复合组件(此处为教程),它使您能够将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>
Run Code Online (Sandbox Code Playgroud)
/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>
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我个人更喜欢使用JS/jQuery作为圆角部分,例如jQuery角落插件.只需给你的命令链接一个特定的styleClass
让JS做的魔术.
归档时间: |
|
查看次数: |
3448 次 |
最近记录: |