java - Wicket: Lazy loading DropDownChoice -


one dropdownchoice list on webapp takes long time create, because of getting options operations ldap connection , sql connection. , because of whole page loading more couple of seconds - i'd much.

so want achieve, use (best me) built-in ajax functionality of wicket lazy load dropdown, have problems.

i know how make regular dropdownchoice list, simple example working great me - link

i know how make lazy-loaded paragraph, wicket-examples - link (source code -> lazyloadingpage.html/lazyloadingpage.java)

but putting throwing me exceptions , resulting wicket's internal error.

here how try it:

in html:

<select wicket:id="lazy"></select> 

in java:

private string selected = "abc"; (...) add(new ajaxlazyloadpanel("lazy") {              @override             public component getlazyloadcomponent(string id) {                 //simulating long time simple list                 try {                     thread.sleep(5000);                 }                 catch (interruptedexception e) {                     throw new runtimeexception(e);                 }                 return new dropdownchoice<string>(                         id, new propertymodel<string>(this,"selected"),                         arrays.aslist("abc","def"));              }         });     } 

and i'm getting internal error wicket, in logs:

error unexpected error occurred component [content] (path = [0:lazy:content]) must applied tag of type [select], not:  '<div wicket:id="content">' (line 0, column 0)  markupstream: [markup = jar:file:/c:/program%20files/apache%20software%20foundation/tomcat%207.0/webapps/devservices/web-inf/lib/wicket-extensions-1.5.7.jar!/org/apache/wicket/extensions/ajax/markup/html/ajaxlazyloadpanel.html 

, index = 0, current = ''

and stacktrace.

i appreciate help, i'm doing wrong, or maybe better code examples.

thanks bert, i'm putting here full solution, in case use in future.

we need create our own panel, because ajaxlazyloadpanel can change 1 panel another.

example of mypanel.html:

<?xml version="1.0" encoding="utf-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org"> <body> <wicket:panel>     <select wicket:id="project"></select> </wicket:panel> </body> </html> 

and mypanel.java :

public class mypanel extends panel {     private string selected = <what want>;     private list<string> projectlist <what want>;     public mypanel(string id) {         super(id);         add(new dropdownchoice<string>(            "project", new propertymodel<string>(this, "selected"), projectslist));     } } 

on main page html add this:

<span wicket:id="lazy2"></span> 

and in main page java file:

add(new ajaxlazyloadpanel("lazy") {     @override     public component getlazyloadcomponent(string id) {         return new mypanel(id);     } }); 

hope else :-)


Comments