【发布时间】:2018-05-08 17:30:04
【问题描述】:
请看下面的表格。特别要注意 ajax 和 graphicsImage 元素。 ajax 元素嵌入在 selectOneMenu 中。当菜单选择改变时,图像相应地更新。更新有时会导致“闪烁”(旧图像消失,表单调整大小(缩小),新图像出现,表单恢复到原始大小)。我猜测不闪烁(闪烁)是由从 url(网络上其他地方的服务器)获取新图像的速度(或缺乏)引起的。没有在本地缓存所有图像,有没有办法解决这个问题?导致旧图像保留在原位,直到新图像准备好?至少防止表单调整大小?
<h:form rendered="#{orderController.addingNew}" styleClass="demo">
<fieldset>
<legend>New Order</legend>
<h:panelGrid columns="2">
<h:outputText value="Patient"></h:outputText>
<h:selectOneMenu validatorMessage="required" value="#{orderController.patientId}" onchange="submit()">
<f:selectItems value="#{orderController.patients}" />
</h:selectOneMenu>
<h:outputText value="Product"></h:outputText>
<h:selectOneMenu value="#{orderController.productId}">
<f:selectItems value="#{orderController.products}" var="product" itemValue="#{product.id}" itemLabel="#{product.name}" />
<f:ajax render="productImage" listener="#{orderController.productSelectionChanged}"/>
</h:selectOneMenu>
<h:graphicImage url="#{orderController.productImageUrl}" id="productImage"/>
</h:panelGrid>
<h:panelGroup>
<h:commandButton value="Save" action="#{orderController.save}" accesskey="s" styleClass="demo"/>
<h:commandButton value="Cancel" action="#{orderController.cancel}" accesskey="c" immediate="true" styleClass="demo"/>
</h:panelGroup>
</fieldset>
<h:outputText value=" " />
</h:form>
【问题讨论】: