开发者

JSF: Actions calls are delayed

开发者 https://www.devze.com 2023-03-08 04:31 出处:网络
What could possible reasons be that my action calls are delayed? It happens for all action calls on one form I have. After I click on a anything that will call an action (or when the value of a dataTa

What could possible reasons be that my action calls are delayed? It happens for all action calls on one form I have. After I click on a anything that will call an action (or when the value of a dataTable should be evaluated on form load), it takes roughly 10 seconds for the action to be called. (I checked it by setting a breakpoint and then click on the button.)

Any ideas why?

This is the part that seems to cause the trouble:

<h:panelGroup id="someGroup">
<h:dataTable value="#{someHandler.keys}" binding="#{someHandler.dataTable}" var="key">
    <h:column>
        <f:facet name="header">
            <h:outputText value="Key" />
        </f:facet>
        <h:outputText value="#{key}" />
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText value="Value" />
        </f:facet>
        <h:commandLink value="[No value]" re开发者_运维百科ndered="#{empty someHandler.getValue(key)}">
            <f:ajax listener="#{someHandler.loadProperty}" render="someForm:key someForm:value" />
        </h:commandLink>
        <h:commandLink value="#{someHandler.getValue(key)}" rendered="#{not empty someHandler.getValue(key)}">
            <f:ajax listener="#{someHandler.loadProperty}" render="someForm:key someForm:value" />
        </h:commandLink>
    </h:column>
</h:dataTable>
</h:panelGroup>

During debugging I noticed that it always calls someHandler.keys first when I click a commandLink. Is there any explaination for that? I don't want the dataTable rerendered if I click on one of these commandLinks. None of the methods called is particularly "slow".


The only feasible explanation I can think of is that you're doing expensive business logic inside a getter method instead of in the bean's constructor or any other event method which is called only once when necessary.

Getter methods are intented to only return some prepopulated bean property or at highest do lazy loading, not to do expensive business logic like connecting a DB, copying 1000 rows into Java's memory, etcetera. Getter methods can be called more than once during a JSF request, which grows exponentially when the call is made inside an iterating component like <h:dataTable> or is been used in rendered attribute. JSF/EL won't cache results of getter methods on a per-request basis or something since a normal getter call is prarticularly cheap.

See also:

  • Why JSF calls getters multiple times


I'd say your browser is having a hard time with the "lousy" javascript generated by JSF. Did you measure performances with different browsers ? I suggest seeing if chrome for example goes faster.

0

精彩评论

暂无评论...
验证码 换一张
取 消