我创建了一个部件的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">&#160;</span>
    <span type="submit" class="submit">
        <h:commandLink id="#{id}" value="#{label}" action="#{action}" />
    </span>
    <span class="btn-right btn-corners">&#160;</span> </ui:composition>

我的新的组件可以使用访问

<my:commandLink id="continue" label="continue" action="#{applyBacking.submit}"/>

和Java代码是

public String submit(){
    ...
}

然而,它给了我一个错误“ApplyBacking没有物业提交”。 我理解这个错误的原因是因为在渲染我:commandLink,它试图评估#{} applyBacking.submit一个属性。相反,我想了解该方法的调用(applyBacking.submit)的信息被传递给模板和在渲染ħ评价:commandLink

任何建议?

有帮助吗?

解决方案

创建复合部件代替(教程这里),它可以让你定义豆动作作为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">&#160;</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">&#160;</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的角插件。只要给你的commandlink特定styleClass,让JS做的魔力。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top