jstl请求性能

jstl request performance

我在列表中有一些对象 是组件,我实现了这个来展示它们:

first.xhtml:

<h:form id="sceneForm">
   <c:forEach items="#{templateController.model.selectedTemplate.templatesSet.toArray()}" var="templateControls" varStatus="ind">

        <ui:include src="second.xhtml"/>

    </c:forEach>
</h:form>

second.xhtml:

<c:forEach items="#{templateControls.controlAttributes.toArray()}" var="controlAttributes" >
    <c:choose>
        <c:when test="#{controlAttributes.controlAttributeType.name == 'top'}">
            <ui:param name="top" value="#{controlAttributes.value}px"  />
        </c:when>
        <c:when test="#{controlAttributes.controlAttributeType.name == 'left'}">
            <ui:param name="left" value="#{controlAttributes.value}px"  />
        </c:when>
        <c:when test="#{controlAttributes.controlAttributeType.name == 'width'}">
            <ui:param name="width" value="#{controlAttributes.value}px"  />
        </c:when>
        <c:when test="#{controlAttributes.controlAttributeType.name == 'height'}">
            <ui:param name="height" value="#{controlAttributes.value}"  />
        </c:when>
    </c:choose>
</c:forEach>

<c:if test="#{templateControls.controlType.type == 'Button'}">
    <div style="top:#{top}; left:#{left}; width:#{width}; height:#{height}px;>
        <div class="gui-component-inner">
            <span>#{value}</span>
            <em class="helper"></em>
        </div>
    </div>
</c:if>

我遍历我的属性列表并设置一些变量,然后我用变量设置我的组件。这工作正常,但不是最佳的。我做了一个按钮:

<p:commandButton value="Test" actionListener="#{templateController.testAction}" onstart="Utils.PrintTime()" oncomplete="Utils.PrintTime()"/>

打印请求开始和请求结束的时间,如果我删除整个 <c:forEach> 则需要 2 秒,则需要 0.05 秒。我怎样才能通过迭代做出更好的请求时间?有什么想法吗?

为什么我得到那个减号我不知道...

这也是我的解决方案:

我创建了一个具有顶部、左侧、宽度、高度的对象,并在 TemplateControl 对象中声明了它。在页面加载时,我迭代 templateControls.controlAttributes 并为每个组件设置顶部、左侧、宽度、高度。在 xhtml 中我简单地写:

<c:if test="#{templateControls.controlType.type == 'Button'}">
    <div style="top:#{templateControls.atr.top}; left:#{templateControls.atr.left}; width:#{templateControls.atr.width}; height:#{templateControls.atr.height}px;>
        <div class="gui-component-inner">
            <span>#{value}</span>
            <em class="helper"></em>
        </div>
    </div>
</c:if>

像这样,我在开始时在 java 中进行了迭代,而不是在 xhtml 中,并且我摆脱了 <c:forEach><c:if> 标记,现在我的请求非常快。