我一直致力于创建一个动态表,捕获已更新的所有单元格(以便更快地保存),然后在保存后刷新/重新呈现这些单元格。
到目前为止,我已经创建了表,所有更新的项目都是通过ajax监听器非常好地捕获的,但是我现在仍然无法在保存后刷新/重新呈现这些更新的组件。
页面中的代码段:
<h:form id="formMain" prependId="false">
<div id="contentWrapper">
<p:messages id="messages" severity="warn, error" autoUpdate="true" closable="true" />
<div style="float:right; position:relative; top: -3px;">
<h:commandButton id="btnSaveUpdates" styleClass="save_updates_button">
<f:ajax execute="@this" listener="#{remediationDetail.processUpdates}"/>
</h:commandButton>
</div>
<h:panelGroup id="detailEdit" styleClass="clear_left" layout="block">
<h:dataTable id="tblDetails" styleClass="slate_table remediation" value="#{remediationDetail.details}" var="dataItem">
<c:forEach items="#{remediationDetail.detailHeaders}" var="key" varStatus="looper">
<h:column>
<f:facet name="header">#{key.fieldDefinition.fieldConfiguration.customLabel}</f:facet>
<c:if test="#{key.fieldDefinition.dataType.name eq 'Number'}">
<h:panelGroup id="detailNumberPanel#{looper.index}">
<h:inputText id="txtDetailNumber#{looper.index}" rendered="#{remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}" styleClass="remediation_textbox error_marker" title="#{remediationDetail.errorMessages(dataItem.id, key.fieldDefinition.id)}">
<f:convertNumber maxFractionDigits="0" maxIntegerDigits="19"/>
<f:ajax event="change" execute="@this" render="@none" listener="#{remediationDetail.markChangedEntity}"/>
<f:attribute name="entity" value="#{dataItem.entityList[looper.index]}"/>
</h:inputText>
<h:outputText id="txtDetailNumberOut#{looper.index}" rendered="#{not remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}"></h:outputText>
</h:panelGroup>
</c:if>
<c:if test="#{key.fieldDefinition.dataType.name eq 'Decimal'}">
<h:panelGroup id="detailDecimalPanel#{looper.index}">
<h:inputText id="txtDetailDecimal#{looper.index}" rendered="#{remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" converterMessage="Value provided is not a valid Decimal" styleClass="remediation_textbox error_marker" title="#{remediationDetail.errorMessages(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}">
<f:convertNumber maxFractionDigits="2" maxIntegerDigits="19"/>
<f:ajax event="change" execute="@this" render="@none" listener="#{remediationDetail.markChangedEntity}"/>
<f:attribute name="entity" value="#{dataItem.entityList[looper.index]}"/>
</h:inputText>
<h:outputText id="txtDetailDecimalOut#{looper.index}" rendered="#{not remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}">
<f:convertNumber maxFractionDigits="2" maxIntegerDigits="19"/>
</h:outputText>
</h:panelGroup>
</c:if>
<c:if test="#{key.fieldDefinition.dataType.name eq 'Date'}">
<h:panelGroup id="detailDatePanel#{looper.index}">
<h:inputText id="txtDetailDate#{looper.index}" rendered="#{remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" styleClass="remediation_textbox error_marker dates" title="#{remediationDetail.errorMessages(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}">
<f:convertDateTime locale="en_US" pattern="MM/dd/yyyy" />
<f:ajax event="change" execute="@this" render="@none" listener="#{remediationDetail.markChangedEntity}"/>
<f:attribute name="entity" value="#{dataItem.entityList[looper.index]}"/>
</h:inputText>
<h:outputText id="txtDetailDateOut#{looper.index}" rendered="#{not remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}">
<f:convertDateTime locale="en_US" pattern="MM/dd/yyyy" />
</h:outputText>
</h:panelGroup>
</c:if>
<c:if test="#{key.fieldDefinition.dataType.name eq 'Boolean'}">
<h:panelGroup id="detailBooleanPanel#{looper.index}">
<h:selectBooleanCheckbox id="cbDetailBooleanInput#{looper.index}" rendered="#{remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" title="#{remediationDetail.errorMessages(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}">
<f:ajax event="change" execute="@this" render="@none" listener="#{remediationDetail.markChangedEntity}"/>
<f:attribute name="entity" value="#{dataItem.entityList[looper.index]}"/>
</h:selectBooleanCheckbox>
<h:outputText id="txtDetailBooleanOutput#{looper.index}" rendered="#{not remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}"></h:outputText>
</h:panelGroup>
</c:if>
<c:if test="#{key.fieldDefinition.dataType.name eq 'String'}">
<h:panelGroup id="detailStringPanel#{looper.index}">
<h:inputText id="txtDetailString#{looper.index}" rendered="#{key.fieldDefinition.inputType eq 'TEXTBOX' and remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}" styleClass="remediation_textbox error_marker" title="#{remediationDetail.errorMessages(dataItem.id, key.fieldDefinition.id)}">
<f:ajax event="change" execute="@this" render="@none" listener="#{remediationDetail.markChangedEntity}"/>
<f:attribute name="entity" value="#{dataItem.entityList[looper.index]}"/>
</h:inputText>
<h:selectOneMenu id="ddDetailString#{looper.index}" styleClass="remediation_select error_marker" rendered="#{key.fieldDefinition.inputType eq 'DROPDOWN' and remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}" title="#{remediationDetail.errorMessages(dataItem.id, key.fieldDefinition.id)}">
<f:selectItems value="#{dataItem.entityList[looper.index].fieldDefinition.listItemSet.selectItemsList}"></f:selectItems>
<f:ajax event="change" execute="@this" render="@none" listener="#{remediationDetail.markChangedEntity}"/>
<f:attribute name="entity" value="#{dataItem.entityList[looper.index]}"/>
</h:selectOneMenu>
<h:outputText id="txtDetailStringOut#{looper.index}" rendered="#{not remediationDetail.containsErrors(dataItem.id, key.fieldDefinition.id)}" value="#{dataItem.entityList[looper.index].val}"></h:outputText>
</h:panelGroup>
</c:if>
</h:column>
</c:forEach>
</h:dataTable>
</h:panelGroup>
</div>
</h:form>
来自支持bean的代码
@ManagedBean
@SessionScoped
public class RemediationDetail implements Serializable {
public void markChangedEntity(AjaxBehaviorEvent ajaxEvent){
Entity entity = (Entity) Utility.getAjaxActionAttribute(ajaxEvent, "entity");
//Capture the Client Ids that were updated
getComponentsIdsToRefresh().add(ajaxEvent.getComponent().getParent().getClientId());
//Capture what Entities were changed
getChangedEntities().add(entity);
}
//This is where the save happens and hoping for updating of components !!
public void processUpdates(AjaxBehaviorEvent event){
entityDomain.processEntities(changedEntities);
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().addAll(getComponentsIdsToRefresh());
}
}
保存发生后,我将要更新的客户端ID添加到PartialViewContext()。getRenderIds()我没有看到任何更新。我也尝试过OmniFaces Ajax.Update(clientId)也没有成功。
我已经更新了代码片段,因为它目前正在构建正在构建的完整表格。
我的问题是:
我的环境: Mojarra 2.1.7 Tomcat 7.022
此致
麦克
答案 0 :(得分:0)
我注意到了markChangedEntity
方法中的某些内容。您有以下代码:
getComponentsIdsToRefresh().add("formMain:" +
ajaxEvent.getComponent().getParent().getClientId());
调用getClientId()
已经返回包含表单ID的完整ID。添加formMain:
会导致类似formMain:formMain:XXX
的内容,这在您的视图中不会是合法ID。
答案 1 :(得分:0)
此代码适用于Mojarra 2.1.21。 Mojarra 2.1.7从2012年3月开始,目前已经超过1岁。我强烈建议升级它。
我无法准确确定2.1.7和2.1.21之间的哪个版本和/或哪个Mojarra issue修复了2.1.7的具体问题,因为我不认识这个问题,但我可以告诉你最近,在国家管理视野中,很多事情都得到了改善。更重要的是,从2.1.18开始,eternal chicken-egg problem with taglibs+viewscope已被修复,它可能也会得到解决。