2017-06-17 4 views
2

私の複合コンポーネントは次の形式が含まれています。私は私のバッキングコンポーネントで<input jsf:id="sc#{cc.attrs.ItemSource.answerId}" />の値にアクセスするにはどうすればよい複合コンポーネントからバッキングコンポーネントでフォームデータを取得

<cc:interface componentType="answerCompositeComponent"> 
    <cc:attribute name="AnswerType" type="code.elephant.domainmodel.AnswerType" required="true" /> 
    <cc:attribute name="ItemSource" type="code.elephant.domainmodel.Answer" required="true" /> 
    <cc:attribute name="QuestionId" type="java.lang.Long" required="true" /> 
</cc:interface> 
<cc:implementation> 
    <input jsf:id="sc#{cc.attrs.ItemSource.answerId}" /> 
</cc:implementation> 

?私はオーバーライドprocessUpdatesメソッドで私のバッキングビーンで次のことを試しました。

Answer ItemSource = (Answer) getValueExpression("ItemSource").getValue(context.getELContext()); 
String formid = String.format("sc%d", ItemSource.getAnswerId()); 
String get = context.getExternalContext().getRequestParameterMap().get(formid); 

String getは常にnullです。入力値を取得する方法はありますか?

PS:私は、jsfでプレーンhtmlを使用するのがその目的ではないことを知っています。私は、私の計画がどのように達成可能であるかを丁寧に考えています。

答えて

3

jsf属性でプレーンhtmlを使用したことはありませんので、該当するかどうかわかりません。

一般に、この複合体にネストされたコンポーネントにアクセスする一般的な方法である:複合バッキング構成要素はNamingContainerので、静的(またはnoneを好むこと

<cc:interface componentType="answerCompositeComponent"> 
    <cc:attribute name="AnswerType" type="code.elephant.domainmodel.AnswerType" required="true" /> 
    <cc:attribute name="ItemSource" type="code.elephant.domainmodel.Answer" required="true" /> 
    <cc:attribute name="QuestionId" type="java.lang.Long" required="true" /> 
</cc:interface> 
<cc:implementation> 
    <h:inputText id="questionInput" binding="#{cc.input}" /> 

    <!-- maybe something like this might work 
     <input jsf:id="questionInput" jsf:binding="#{cc.input}" /> 
    --> 
</cc:implementation> 

@FacesComponent("answerCompositeComponent") 
public class AnswerCompositeComponent extends UINamingContainer 
{ 
    private UIInput input; 

    @Override 
    public void processUpdates(FacesContext context) 
    { 
     super.processUpdates(context); 

     Object value = input.getValue(); 
     Object localValue = input.getLocalValue(); 
     Object submittedValue = input.getSubmittedValue(); 

     // do your things with values 
    } 

    public UIInput getInput() 
    { 
     return input; 
    } 

    public void setInput(UIInput input) 
    { 
     this.input = input; 
    } 
} 

注まったく)ネストされたコンポーネントID。あなたが本当に必要としていない限り、あなたが何をしているのか正確に知っていない限り、動的IDを避けてください。

+0

多くの感謝!それは私のために働く。立ってはいけない。その問題に関連する場合、いいえ - jsfにname属性の代わりにid属性を使用するように指示する方法はありますか?私はここで属性名とグループ化する必要があるラジオ入力のリストを得ました。 – Briefkasten

+0

JSFは** ** id *と* name *の両方を、UIInputコンポーネントの生成HTMLと同じ値に設定します。 html input * name *属性はhtmlコンテナ*

*自身で必要です。そうでなければ、サブミット要求内でどのようにキーと値のペアを渡すかがわかりません。たぶん私はあなたが尋ねているものを誤解したでしょうか? –

+0

Ahokay。また、processUpdatesメソッドで生成されたコンポジションコンポーネントのHTMLコードを取得し、 ' Briefkasten

関連する問題