我使用JSF 2.2和Primefaces 6.1。我在第一次提交表单时有textarea值的问题。我对一种表单使用多个子视图。问题是当在文本区域中键入某些内容时,在第一个表单提交后,该值将消失并且不更新数据模型。但是,当再次键入并触发提交时,就会显示该值。 textarea在dataTable的subTable内部。
我尝试将valueChangeListener与ajax一起使用。这可行,但是当单击快速提交时,值没有更新。我只尝试了ajax,但是结果是一样的。我尝试使用onchange =“ submit()”的valueChangeLister,但这不起作用。尝试过的解决方案Primefaces valueChangeListener or <p:ajax listener not firing for p:selectOneMenu,但这不起作用
文本区域代码
<h:form id="reuestForm">
<div class="form-group">
<p:dataTable id="edScopeTable" styleClass="form-group dataTable-space"
value="#{requestBean.employeeDealerTabController.getEdScopeCategories()}"
var="category">
<p:columnGroup type="header">
<p:row>
<p:column headerText="#{i18nMsg.ed_env_scopes_tbl_colScope_header}"/>
<p:column headerText="#{i18nMsg.ed_env_scopes_tbl_col_openIdConnect_header}"/>
<p:column headerText="#{i18nMsg.ed_env_scopes_tbl_col_reasonNeeded}"/>
</p:row>
</p:columnGroup>
<p:subTable
value="#{requestBean.employeeDealerTabController.getScopeReasonsByCategory(category)}"
var="edScope" rendered="#{requestBean.employeeDealerTabController.isCategoryInTable(category)}">
<p:column styleClass="#{requestBean.employeeDealerTabController.calculateDiff(edScope,'cell-right')} textAlign-center">
<p:inputTextarea id="reason"
value="#{edScope.reason}" rows="2"
autoResize="false"
data-disable-type="custom"
styleClass="form-control #{edScope.getDiffValue('reason')}"
rendered="#{edScope.edScopeConst.reasonNeeded}"
label="#{i18nMsg.edScope_request_selectionTable_scope_reasonNeeded} #{edScope.edScopeConst.name}"
disabled="#{requestBean.employeeDealerTabController.disableReasonField()}">
<f:attribute name="scope" value="#{edScope}"/>
<f:validateBean
binding="#{requestBean.validatorContainer.requiredBeanValidator}"/>
<p:message for="reason" display="tooltip"/>
</p:inputTextarea>
<h:outputText
rendered="#{not edScope.edScopeConst.reasonNeeded}"
value="#{i18nMsg.edScope_request_selectionTable_scope_noReasonNeeded}"/>
</p:column>
</p:subTable>
</p:dataTable>
</div>
<div class="text-right">
<p:commandButton value="#{(requestBean.request.version eq 1 and requestBean.request.stateDraft) or requestBean.isEdRequestToBePrinted() ? i18nMsg.general_mainButton_send_and_print : i18nMsg.general_mainButton_send}"
id="send"
update="requestForm"
actionListener="#{requestBean.prepareDialog()}"
oncomplete="args.validationFailed ? PF('validationFailedMessageDialog').show() : PF('readyToSendDialog').show(); jQuery(document).scrollTop(0)"
title="#{requestBean.sendButtonDisabled ? i18nMsg.request_sendButtonTooltip : ''}"
styleClass="ui-priority-primary" icon="ui-icon-mail-closed"
disabled="#{requestBean.sendButtonDisabled}" data-disable-type="custom" />
</div>
</h:form>
RequestBean
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class RequestBean extends PageBeanBase implements Serializable {
private EmployeeDealerTabController employeeDealerTabController;
@PostConstruct
public void initialize() {
employeeDealerTabController = new EmployeeDealerTabController();
}
public EmployeeDealerTabController getEmployeeDealerTabController() {
return employeeDealerTabController;
}
public void prepareDialog() {
// preparation before send and show dialog with confirmation send form
}
// rest of method
}
EmployerDealerTabController
public List<EdScopeREason> getScopeReasonsByCategory(int category) {
if(category == 1) {
return scopesOidcList;
} else {
return scopesIdentityList;
}
}
EdScopeReason
@Entity
@Table(name = "ED_SCOPE_REASON")
public class EdScopeReason extends InlineDiffBase<EdScopeReason> implements EdScopeConstBearer, Serializable, Comparable<EdScopeReason> {
private String reason;
@Basic
@Column(name = "REASON")
@NotBlank(groups = RequiredValidationGroup.class, message = "{iamat.validation.general.edScopeReason.notempty}")
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
}
我有setter和getter方法。当我调试时,此值传递给验证器,但未设置为component。我有点困惑为什么不第一次设置此值
编辑
我将jsf ajax添加到textarea输入中,并在commandButton上设置5s延迟。这是一种解决方法,但仍在寻找更好的解决方案。当我使用primefaces ajax时,我不需要延迟,但是对于每个primefaces ajax,我都会显示loader.gif。
<p:inputTextarea id="reason"
...{requestBean.employeeDealerTabController.disableReasonField()}">
<f:attribute name="scope" value="#{edScope}"/>
<f:validateBean
binding="#{requestBean.validatorContainer.requiredBeanValidator}"/>
<p:message for="reason" display="tooltip"/>
<f:ajax />
</p:inputTextarea>
....
<p:commandButton value="#{(requestBean.request.version eq 1 and requestBean.request.stateDraft) or requestBean.isEdRequestToBePrinted() ? i18nMsg.general_mainButton_send_and_print : i18nMsg.general_mainButton_send}"
id="send"
update="requestForm"
actionListener="#{requestBean.prepareDialog()}"
oncomplete="args.validationFailed ? PF('validationFailedMessageDialog').show() : PF('readyToSendDialog').show(); jQuery(document).scrollTop(0)"
title="#{requestBean.sendButtonDisabled ? i18nMsg.request_sendButtonTooltip : ''}"
styleClass="ui-priority-primary" icon="ui-icon-mail-closed"
disabled="#{requestBean.sendButtonDisabled}" data-disable-type="custom" delay="5000" />