2011-01-05 9 views
4

FaceLinkコンポーネントを作成して、h:commandLinkを拡張しました(いくつかの機能と丸みのあるコーナーを追加しました)。それは私にエラー "ApplyBackingプロパティが提出していない" を与えるしかしJSF 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(){ 
    ... 
} 

です。 my:commandLinkをレンダリングするときに#{applyBacking.submit}をプロパティに評価しようとしているので、このエラーの原因を理解しています。代わりに、呼び出されるメソッドに関する情報(applyBacking.submit)をテンプレートに渡して、h:commandLinkをレンダリングしながら評価します。

提案がありますか?

答えて

5

代わりに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">&#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 corner plugin。あなたのコマンドリンクに特定のstyleClassを与えて、JSに魔法をさせてください。

関連する問題