【发布时间】:2015-08-14 19:29:48
【问题描述】:
我有一个显示在网格中的职业英雄联盟球员组件(检票口面板)列表,对于每个球员,他们都有自己的模式视图(也是检票口面板)。我的问题在于网站的初始加载,因为正在创建所有检票口面板(播放器和播放器模式面板),模式面板具有播放器信息的列表视图,这需要相当长的时间来加载所有播放器信息和将其写入数据库表。有什么方法可以让我只在点击玩家时才进行查询?我曾考虑将查询放在 AjaxEventBehavior 中,但我的 dao 上出现了 NotSeraliableException。我还考虑仅在单击播放器时添加模式面板(也使用 ajaxeventbehavior),但我不知道如何动态添加 html:
最好的方法是什么,这样我就不必在网站初始加载时查询 api/数据库?
这是播放器面板,您可以看到我在选择播放器面板时添加了模态面板:
public PlayerPanel(String id, final IModel<?> model) {
super(id, model);
Label proName = (new Label("proName", model));
proName.add(new AttributeModifier("data-target", "#modal" + model.getClass().toString()));
add(proName);
//initializing daos for player
ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
ProPlayersDaoJdbc proPlayersDao = (ProPlayersDaoJdbc) context.getBean("proPlayersDaoJdbc");
ProGamesDaoJdbc proGamesDao = (ProGamesDaoJdbc) context.getBean("proGamesDaoJdbc");
ArrayList<Players> allPlayers = (ArrayList<Players>) proPlayersDao.listPlayers();
final ArrayList<Games> games = new ArrayList<Games>();
for(Players p : allPlayers){
if(p.getProName().equals(model.getObject().toString())){
region = p.getRegion();
player = p;
Image proImage = new Image("proImage", p.getThumbnailPath());
proImage.add(new AttributeModifier("src", p.getThumbnailPath()));
proImage.add(new AttributeModifier("data-target", "#modal" + model.getObject().toString()));
try {
ArrayList<Games> gamesList = updateGamesPlayed(player.getSummonerId());
for(Games game : gamesList){
games.add(game);
}
} catch (RiotApiException e) {
e.printStackTrace();
}
add(proImage);
}
}
if(!games.isEmpty()){
for(Games game : games){
proGamesDao.create(game);
}
}
add(new ModalPanel("modalPanel", model));
}
updateGamesPlayed(...) 方法查询 API,proGamesDao.create(game) 将其写入 db 表。
【问题讨论】: