【问题标题】:Wicket query API and write data to database on click AjaxEventBehaviorWicket 查询 API 并在单击 AjaxEventBehavior 时将数据写入数据库
【发布时间】: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 表。

【问题讨论】:

    标签: onclick wicket panel


    【解决方案1】:

    您可以通过单击方法进行数据库查询的播放器图像/链接,将结果设置为子面板的默认模型对象,并通过 target.add 刷新页面或网格。在子面板上,您可以控制大小。

    【讨论】:

    • 尝试这个,但我仍然收到“NotSerializableException”,我想知道为什么!?
    猜你喜欢
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    相关资源
    最近更新 更多