簡體   English   中英

如何顯示f:viewAction的等待指示?

[英]How to display a wait indicator for f:viewAction?

我有一個JSF頁面,它加載一個對象的屬性(id在URL中傳遞)。 加載可以持續更長時間,因此我想顯示等待/忙碌指示符或“正在加載...”消息。

這是使用“viewAction”完成的

<f:metadata>
    <f:viewAction action="#{myBean.loadParams}" />
</f:metadata>

有沒有一種簡單的方法來實現這一目標? 我正在使用Primefaces。

PrimeFaces已經准備好了一個組件: <p:outputPanel deferred="true"> 您只需要確保#{heavyBean} <p:outputPanel>中的組件中引用(因此絕對不會在<c:xxx>類的標記文件中引用,因為這里解釋的原因)而不是其他地方。

...
#{notHeavyBean.property}
...

<p:outputPanel deferred="true">
    ...
    #{heavyBean.property}
    ...
</p:outputPanel>

...
#{anotherNotHeavyBean.property}
...

然后你可以在@PostConstruct方法中完成繁重的工作。 完成你最初在@PostConstruct中的<f:viewAction>@PostConstruct

@Named
@ViewScoped
public class HeavyBean implements Serializable {

    @PostConstruct
    public void init() {
        // Heavy job here.
    }

    // ...
}

如果您需要訪問其他bean的屬性,只需在HeavyBean @Inject那些bean。 例如,如果您需要ID視圖參數:

<f:viewParam name="id" value="#{notHeavyBean.id}" />

@Inject
private NotHeavyBean notHeavyBean; // Also @ViewScoped.

@PostConstruct
public void init() {
    Long id = notHeavyBean.getId();
    // Heavy job here.
}

<p:outputPanel>已經附帶了動畫gif。 您可以通過CSS輕松自定義它。

.ui-outputpanel-loading {
    background-image: url("another.gif");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM