JSFにマネージドビーンを追加する その2
前回、作成してうまく動かなった部分ですが、 単純にアノテーションのimportがまちがっており、修正したら正しく動作しました。
では今回は、「投稿」ボタンを押下したら、 レスが上に表示されるような仕組みを作成します。
細かい体裁やクラス構造はいったん無視します。 リクエスト送って、再度表示ができるとこまでです。
XHTMLはいかのように修正
<h:body> <h:outputText value="#{responseBean.responseList}"></h:outputText> <h:form> <h:outputLabel>名前</h:outputLabel> <h:inputText value="#{responseBean.name}" p:placeholder="#{responseBean.defaultName}"></h:inputText> <h:outputLabel>e-mail</h:outputLabel> <h:inputText value="#{responseBean.EMail}" p:placeholder="#{responseBean.defaultEMail}"></h:inputText> <div> <h:inputTextarea cols="50" rows="10" value="#{responseBean.res}"></h:inputTextarea> </div> <h:commandButton action="#{responseBean.tweetResponse()}" value="投稿"></h:commandButton> </h:form> </h:body>
管理beanはボタン押下時のメソッドを作成します。
public void tweetResponse(){ this.responseList += this.name + this.EMail + this.Res; return; }
とりあえずこんな感じになりました。 体裁やクラス構造は気にしない!