用indicationAjaxButton替换submitlink

时间:2015-02-03 12:06:41

标签: ajax wicket

我有一个带有提交按钮的表单,它将从数据库中获取结果并根据这些结果更新列表视图。如果没有结果,则显示反馈消息。一切正常。

现在我想用IndicatingAjaxButton替换submitlink,这样用户可以在获得结果需要很长时间时看到发生的事情。

基本理念是:

IndicatingAjaxButton submitLink = new IndicatingAjaxButton("submit", form) {

        private static final long serialVersionUID = -4306011625084297054L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Integer hourFrom = 0;
            Integer hourTo = 0;
            Integer minuteFrom = 0;
            Integer minuteTo = 0;
            hourFrom = Integer.parseInt(hour_from.getModelObject());
            hourTo = Integer.parseInt(hour_to.getModelObject());

            minuteFrom = Integer.parseInt(minute_from.getModelObject());
            minuteTo = Integer.parseInt(minute_to.getModelObject());

            Calendar from = Calendar.getInstance();
            Calendar to = Calendar.getInstance();

            Date dateFrom = date_from.getModelObject();
            Date dateTo = date_to.getModelObject();

            from.setTime(dateFrom);
            to.setTime(dateTo);

            from.set(Calendar.HOUR, hourFrom);
            from.set(Calendar.MINUTE, minuteFrom);

            to.set(Calendar.HOUR, hourTo);
            to.set(Calendar.MINUTE, minuteTo);

            if (topicQueueSelect.getModelObject() == null) {
                error("Please select a message name.");
                getSession().setAttribute("error", "");
            }

            if (to.before(from)) {
                error("Date to must be after date from.");
                getSession().setAttribute("error", "");
            }

            cal.setTimeInMillis(System.currentTimeMillis());

            if (from.after(cal)) {
                error("Date from must be in the past.");
                getSession().setAttribute("error", "");
            }

            if (getSession().getAttribute("error") != null) {
                getSession().removeAttribute("error");
                return;
            }

            page.setModelObject(1);
            List<Search> searchFields = (List<Search>) searchFieldsField
                    .getModelObject();
            messageKeyDataList = messageController.search(
                    topicQueueSelect.getModelObject(), searchFields,
                    from.getTime(), to.getTime(),
                    maxResults.getModelObject(), page.getModelObject(),
                    sortorder);
            if (messageKeyDataList.size() == 0) {
                info("Search criteria didn't produce any results.");
                result.setList(messageKeyDataList);
                resultContainer.setVisible(false);
                return;
            }
            resultContainer.setVisible(true);
            resultSize = messageController.getResultSize();
            int pages = (int) Math.ceil((float) resultSize
                    / maxResults.getModelObject());
            ArrayList<Integer> pageNumbers = new ArrayList<Integer>();
            for (int n = 1; n <= pages; n++) {
                pageNumbers.add(n);
            }
            page.setChoices(pageNumbers);
            pageunder.setChoices(pageNumbers);
            showing.setDefaultModelObject("Showing 1 to "
                    + messageKeyDataList.size() + " out of " + resultSize
                    + " messages");

            lastSearch.put("topicQueue", topicQueueSelect.getModelObject());
            lastSearch.put("searchFields", searchFields);
            lastSearch.put("from", from.getTime());
            lastSearch.put("to", to.getTime());
            lastSearch.put("maxResults", maxResults.getModelObject());
            result.setList(messageKeyDataList);
            target.add(feedback);
        }
    };

SubmitLink确实向我显示带有新列表的ResultView,或者显示信息消息,IndicatingAjaxButton没有。我知道表单提交被调用,因为正在打印system.out。

对此有何建议?

2 个答案:

答案 0 :(得分:0)

SubmitLink是非Ajax组件。使用它将重绘整个页面! IndicatingAjaxButton是一个Ajax组件。您需要使用传递的AjaxRequestTarget来添加应该使用Ajax响应重新绘制的组件。例如,应将FeedbackPanel添加到AjaxRequestTarget。

答案 1 :(得分:0)

我发现我必须对resultContainer和反馈都做setOutputMarkupPlaceholderTag(true)。之后,将它们添加到requesttarget按预期工作。