1
我有primefaces dataTable我想要編輯的行。我確實提交了該行的ID,並將其顯示在要編輯的面板中。使用相同的對象,如果我使用h:outputText輸出值,我可以看到這些值。 p:inputText不顯示值。如果我使用瀏覽器重新加載按鈕刷新頁面,表格值顯示得很好。以下是我的代碼的精簡版。Primefaces表單值不顯示
型號
@Entity
@Table(name = "TICKET")
public class Ticket extends AuditTrail implements Serializable
{
private static final long serialVersionUID = 1L;
private static Logger log = Logger.getLogger(Ticket.class);
@Id
@SequenceGenerator(name = "TICKET_TICKETID_GENERATOR", sequenceName = "TICKET_SEQ")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "TICKET_TICKETID_GENERATOR")
@Column(name = "TICKET_ID", unique = true, nullable = false, precision = 0)
private Long ticketId;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "ticket")
@OrderBy(clause = "createdBy")
private Set<Comment> comments = new LinkedHashSet<Comment>(0);
}
@Entity
@Table(name = "COMMENT_LOG")
public class Comment extends AuditTrail implements java.io.Serializable {
// Fields
private static final long serialVersionUID = 1L;
@Id
@Column(name = "COMMENT_LOG_ID", unique = true, nullable = false, precision = 0)
@SequenceGenerator(name = "COMMENT_COMMENTID_GENERATOR", sequenceName = "COMMENT_SEQ")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "COMMENT_COMMENTID_GENERATOR")
private Long commentId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TICKET_ID")
private Ticket ticket;
@Column(name = "COMMENT1", nullable = false, length = 300)
private String comment1;
}
控制器
@Named("ticketBean")
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class TicketBean implements Serializable
{
private Ticket ticket = new Ticket();
private Comment comment = new Comment();
/**
* getters & setters
*/
public void editComment(long commentId)
{
for (Comment editComment: ticket.getComment())
{
if (editComment.getCommentId().longValue() == commentId)
{
this.comment = editComment;
changeButtonValue("tabView:commentForm1:submitAddComment", "Save");
break;
}
}
}
}
XHTML
<h:form prependId="false" id="commentForm1">
<p:panel id="panelComment">
<h:outputText value="#{ticketBean.comment.comment1}"/>
<p:inputTextarea styleClass="textarea" value="#{ticketBean.comment.comment1}"
rows="4"
cols="60"
maxlength="255"
counter="counter2"
counterTemplate="{0} characters remaining."
id="comment1"
required="true"
requiredMessage="Comment is required"/>
<br />
<h:outputText id="counter2" style="font-size:8pt;" />
<p:commandButton id="submitAddComment" value="Add"
actionListener="#{ticketBean.addComment()}"
ajax="true"
style="font-size:11pt;" process="panelComment"
update=":tabView:commentForm1" />
<p:dataTable id="ticketCommentsList" var="com"
value="#{ticketBean.ticket.comments.toArray()}"
paginator="true" dynamic="true" rows="10"
paginatorPosition="bottom" lazy="true"
paginatorAlwaysVisible="false" widgetVar="projTable"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="10,15,20" styleClass="prime-datatable">
<p:column id="comment1" headerText="Comment">
<h:outputText value="#{com.comment1}" />
</p:column>
<p:column>
<f:facet name="header">Edit</f:facet>
<p:commandLink action="#{ticketBean.editComment(com.commentId)}"
ajax="true" value="Edit"
update=":tabView:commentForm1"
immediate="true"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
爲什麼會<h:outputText value="#{ticketBean.comment.comment1}"/>
打印出來的值不過 <p:inputTextarea value="#{ticketBean.comment.comment1}"/>
不顯示值?
感謝您的幫助。
爲什麼AJAX = false,並立即=真的嗎? – Leo
其實我把它當作ajax = true。我試圖看看如果ajax = false會產生任何影響 – user3520171
我會回答我自己的問題。看到我像意外刪除了commandLink中的過程=「@ this」。 '
' – user3520171