问题描述
我创建了一个Facelet组件来扩展h:commandLink(以添加一些功能和圆角).
I created a Facelet component to extend h:commandLink (to add some functionality and rounded corners).
<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时对其进行评估.
However it gives me an error "ApplyBacking does not have the property submit".I understand the reason for this error because while rendering my:commandLink, it tries to evaluate #{applyBacking.submit} to a property. Instead, I want the info about the method to the invoked (applyBacking.submit) to be passed to the template and evaluated while rendering h:commandLink.
有什么建议吗?
推荐答案
创建复合组件代替(教程),它使您可以将bean动作定义为属性.
Create a composite component instead (tutorial here), it enables you to define bean actions as attribtues.
这是一个开球示例:
/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角插件.只需为您的命令链接指定特定的styleClass
,然后让JS发挥作用即可.
By the way, I would personally prefer using JS/jQuery for the rounded corners part, for example the jQuery corner plugin. Just give your commandlink a specific styleClass
and let JS do the magic.
这篇关于扩展JSF commandLink组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!