WicketでAjaxLazyLoadPanelを使用する方法
AjaxLazyLoadPanel定義:
A panel where you can lazy load another panel. This can be used if you
have a panel/component that is pretty heavy in creation and you first
want to show the user the page and the replace the panel when it is
ready.
この機能は本当に印象的です。ここでは、通常のパネルをこの強力な `AjaxLazyLoadPanel`に変換する方法を示します。
オリジナルパネル
通常のWicketパネル。
add(new PricePanel("price"));
レイジーロードパネル
Wicket `AjaxLazyLoadPanel`に変換してください。
add(new AjaxLazyLoadPanel("price")
{
@Override
public Component getLazyLoadComponent(String id)
{
return PricePanel(id);
}
});
今度は、PricePanelに遅延読み込み効果があります。ニース
注意してください!
この
AjaxLazyLoadPanel
の欠点の1つは、フォールバックバージョンを含んでいないということです。ブラウザのJavaScriptが無効になっている場合、遅延イメージは永久にロードされ続けます。
ここでそれを使って遊ぶことができます。
{空} 1。 Wicketのアプリケーションクラスに次のコードを追加します
protected void init() {
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
}
{空} 2。それをチェックする
WebClientInfo clientInfo = (WebClientInfo)WebRequestCycle.get().getClientInfo();
if(clientInfo.getProperties().isJavaEnabled()){
add(new AjaxLazyLoadPanel("price")
{
@Override
public Component getLazyLoadComponent(String id)
{
return PricePanel("price");
}
});
}else{
add(new PricePanel("price"));
}
上記の関数は、ブラウザがJavaScriptをサポートしている場合はAjaxLazyLoadPanel関数を実行し、それ以外の場合は通常の要求に委譲します。