Следующее p:dialog
создает новый comment
, используя:
<p:dialog id="buyDlg" widgetVar="buyDialog" modal="true" resizable="false" appendTo="@(body)"
header="#{myBundle.CreateCommentsTitle}" closeOnEscape="true" width="auto" height="auto">
<h:form id="buyCommentCreateForm">
<h:panelGroup id="buyDisplay">
<p:outputPanel id="buyCommentsPanel">
<p:row>
<p:column>
<p:editor id="commentText" value="#{commentsController.selected.commentText}" style="margin-bottom:10px"/>
</p:column>
</p:row>
</p:outputPanel>
<p:commandButton actionListener="#{commentsController.setBuyComment(pmMainController.selected.idPmMain, commentsController.selected.commentText)}" value="#{myBundle.Save}" update=":PmMainEditForm:display" oncomplete="handleSubmit(xhr,status,args,PF('buyDialog'));">
<p:confirm header="#{myBundle.ConfirmationHeader}" message="#{myBundle.ConfirmEditMessage}" icon="ui-icon-alert"/>
</p:commandButton>
<p:commandButton value="#{myBundle.Cancel}" oncomplete="PF('buyDialog').hide()" update="buyDisplay" process="@this" immediate="true" resetValues="true"/>
</h:panelGroup>
</h:form>
</p:dialog>
Где метод сохранения:
public void setBuyComment(long idPmMain, String commentText){
PmMain pmMain = pmMainFacadeEJB.find(idPmMain);
Comments comments = new Comments();
pmMain.setBuyComment(comments);
comments.setBuyComment(pmMain);
comments.setCommentText(commentText);
commentsFacadeEJB.edit(comments);
}
Все работает нормально, но мне нужно перезагрузить страницу, чтобы визуализировать идентификатор комментария в PmMain
(он вставляется выше, где написано PmMain.setBuyComments(comments)
). Есть идеи?
EDIT
Добавление информации о setBuyComment
:
Для PmMain.setBuyComment
У меня есть:
public void setBuyComment(Comments buyComment) {
this.buyComment = buyComment;
}
А для comments.setBuyComment
:
public void setBuyComment(PmMain pmMain){
pmMain.setBuyComment(this);
pmMainCollection24.add(pmMain);
}
РЕДАКТИРОВАТЬ 2
Поддерживающий Боб из PmMain
выглядит так:
@Entity
@Table(name = "pm_main")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "PmMain.findAll", query = "SELECT p FROM PmMain p")
, @NamedQuery(name = "PmMain.findByPropId", query = "SELECT p FROM PmMain p WHERE p.propId = :propId")
, @NamedQuery(name = "PmMain.findByPropName", query = "SELECT p FROM PmMain p WHERE p.propName = :propName")
, @NamedQuery(name = "PmMain.findByIdPmMain", query = "SELECT p FROM PmMain p WHERE p.idPmMain = :idPmMain")})
public class PmMain implements Serializable {
private static final long serialVersionUID = 1L;
@Size(max = 25)
@Column(name = "prop_id")
private String propId;
@Size(max = 125)
@Column(name = "prop_name")
private String propName;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_pm_main")
private Long idPmMain;
@JoinColumn(name = "buy_comment", referencedColumnName = "id_comments")
@ManyToOne
private Comments buyComment;
[... Getters and Setters ...]
И Comments
боб выглядит так:
@Entity
@Table(name = "comments")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Comments.findAll", query = "SELECT c FROM Comments c")
, @NamedQuery(name = "Comments.findByCommentText", query = "SELECT c FROM Comments c WHERE c.commentText = :commentText")
, @NamedQuery(name = "Comments.findByIdComments", query = "SELECT c FROM Comments c WHERE c.idComments = :idComments")})
public class Comments implements Serializable {
private static final long serialVersionUID = 1L;
@Size(max = 2147483647)
@Column(name = "comment_text")
private String commentText;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_comments")
private Long idComments;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "buyComment")
private List<PmMain> pmMainCollection24 = new ArrayList<>();
[... Getters and Setters ...]
public void setBuyComment(PmMain pmMain){
pmMain.setBuyComment(this);
pmMainCollection24.add(pmMain);
}