当用户单击保存按钮 h:commandButton 时,我正在尝试保存在 at:dataTable 对象中编辑的数据。但是,在调用该操作之前,会调用 bean 中的 postConstruct() 方法,该方法尝试加载表的数据,但没有最初传入的 docId。我尝试在 h 中使用 f:param :commandButton 传递 docId,但这不起作用。有没有人有正确的策略来加载带有 docId 的页面,然后在单击保存按钮后保存更改?以下是我当前的 bean 代码和 xhtml。不幸的是,我还没有升级到 JSF 2.0 的选项。
<h:form enctype="multipart/form-data">
<t:outputText value="Document: #{documentWorkflowCommentsBean.document.name}" />
<br/><br/>
<t:dataTable id="commentTable" sortable="false"
value="${documentWorkflowCommentsBean.document.workflowComments}"
var="comment"
styleClass="addmTable">
<t:column styleClass="commentId">
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<t:outputText value="${comment.commentId}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Reviewer" />
</f:facet>
<t:outputText value="${comment.reviewer}"/>
</t:column>
<t:column styleClass="charColumn">
<f:facet name="header">
<h:outputText value="Type" />
</f:facet>
<t:outputText value="${comment.commentType}"
rendered="${!documentWorkflowCommentsBean.editComments}"/>
<t:selectOneListbox id="typeList" title="Choose Comment type"
size="1" rendered="${documentWorkflowCommentsBean.editComments}"
value="${comment.commentType}">
<f:selectItems value="${documentWorkflowCommentsBean.commentTypes}"/>
</t:selectOneListbox>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Page" />
</f:facet>
<t:outputText value="${comment.pageNumber}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Section/Paragraph" />
</f:facet>
<t:outputText value="${comment.sectionParagraph}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="Comment/Rationale" />
</f:facet>
<t:outputText value="${comment.commentRationale}"/>
</t:column>
<t:column styleClass="cr624_wrap cr624_maxwidth200">
<f:facet name="header">
<h:outputText value="PO Resolution" />
</f:facet>
<t:outputText value="${comment.poResolution}"
rendered="${!documentWorkflowCommentsBean.editComments}"/>
<t:inputTextarea id="poResolutionTextArea" value="${comment.poResolution}"
rendered="${documentWorkflowCommentsBean.editComments}"
rows="3" cols="20"/>
</t:column>
<t:column styleClass="charColumn">
<f:facet name="header">
<h:outputText value="Decision" />
</f:facet>
<t:outputText value="${comment.decision}"
rendered="${!documentWorkflowCommentsBean.editComments}"/>
<t:selectOneListbox id="decisionList" title="Choose Decision"
size="1" rendered="${documentWorkflowCommentsBean.editComments}"
value="${comment.decision}">
<f:selectItems value="${documentWorkflowCommentsBean.commentDecisions}"/>
</t:selectOneListbox>
</t:column>
</t:dataTable>
<br/>
<h:commandButton value="Save" action="#{documentWorkflowCommentsBean.saveDocumentComments}">
<f:param name="docId" value="#{documentWorkflowCommentsBean.documentId"/>
<f:param name="editComments" value="#{documentWorkflowCommentsBean.editComments}"/>
</h:commandButton>
<input type="button" value="Cancel" title="Close the dialog" onclick="closeModal();"/>
</h:form>
public class DocumentWorkflowCommentsBean extends PageBean {
private static final long serialVersionUID = -866249792018248429L;
private static final Logger log = LogManager.getLogger(DocumentWorkflowCommentsBean.class);
/**
* Holds a reference to the DocumentBusiness object.
*
* @uml.property name="docBiz"
*/
private DocumentBusiness docBiz;
/**
* This represents the documentId parameter passed
*
* @uml.property name="documentId"
*/
private long documentId;
/**
* This is the corresponding Document object represented by the documentId property
*
* @uml.property name="document"
*/
private Document document;
/**
* Determines if the Type, Resolution, and Decision fields are editable
*
* @uml.property name="editComments"
*/
private boolean editComments = false;
private static final List<SelectItem> COMMENT_TYPES = Arrays.asList(new SelectItem("C", "C"),
new SelectItem("M", "M"),
new SelectItem("S", "S"),
new SelectItem("A", "A"));
private static final List<SelectItem> COMMENT_DECISIONS = Arrays.asList(
new SelectItem("A", "A"),
new SelectItem("R", "R"),
new SelectItem("M", "M"));
/**
* This is called after all resources are injected
*/
@PostConstruct
public void postConstruct() {
docBiz = BusinessUtils.getDocumentBusiness();
// Get the parameters that are passed in
String docIdString = (String) getPassedParam("docId");
String editString = (String) getPassedParam("editComments");
// editComments will be null when closing dialog
if (editString != null) {
editComments = Boolean.parseBoolean(editString);
}
if (docIdString != null) {
try {
// Retrieve the Document object
documentId = Long.parseLong(docIdString);
} catch (NumberFormatException ignore) {
// do nothing
log.error("Invalid parameter - " + docIdString);
}
if (documentId > 0) {
//lazy load of workflow comments to be displayed
document = docBiz.getDocumentFetchWorkflowComments(documentId);
}
// Check to see that the Document exists
if (document == null) {
this.getAddmSessionBean().addPageErrorMessage("Cannot perform action - document has been deleted.");
}
}
}
public String saveDocumentComments() {
docBiz.updateDocument(document); //JPA merge call on document
return null;
}
public long getDocumentId() {
return documentId;
}
public void setDocumentId(long documentId) {
this.documentId = documentId;
}
public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
public List<SelectItem> getCommentTypes() {
return COMMENT_TYPES;
}
public List<SelectItem> getCommentDecisions() {
return COMMENT_DECISIONS;
}
}