【发布时间】:2010-10-15 20:18:00
【问题描述】:
错误是我在下面的inputTextarea。只有最后一行可以记录来自inputTextarea 的任何输入,也就是说,只有最后一行,将value 挂钩到#{PostComment.comment.comment}。这是为什么呢?
<h:form id="userCommentList" >
<p:dataTable value="#{CentralFeed.profileComments}" var="item">
<p:column>
<!-- Original Comment -->
<h:outputText value="#{item.comment}"/>
<!-- ****BUG IS THIS INPUTTEXTAREA BELOW*** -->
<h:inputTextarea id="keyword" value="#{PostComment.comment.comment}"/>
<p:commandButton actionListener="#{PostComment.postProfileComment(item.id)}"
value="Post" update="userCommentList" />
</p:column>
</p:dataTable>
</h:form>
编辑
我改变了inputTextarea 和commandButton 就像你建议的BalusC。在Comment 实体中,我添加了另一个字段调用newComment,所以Comment 看起来像这样
Comment
+ id
+ comment
+ newComment --> I have @Transient to this field so it wont map to the database. I also set its default value to the empty string in the constructor
+ ...
...
<p:column>
...
<h:inputTextarea id="keyword" value="#{item.newComment}" rows="2" />
<p:commandButton actionListener="#{PostComment.postReply(item)}" value="Post" />
</p:column>
我希望item.newComment 能保存我刚刚输入的值,所以当我将对象item 传递给postReply 时,我可以将newComment 的内容提取出来,但是它是一个空字符串。所以无论我输入什么都不会绑定到newComment。知道为什么吗?
【问题讨论】: