Wicket模态窗口显示在上下文菜单选项单击上

时间:2017-06-28 05:28:19

标签: wicket wicket-1.5

我是wicket的新手,开发了一个上下文菜单,其中包含几个选项,可以在HTML和Excel中运行报表。根据菜单项单击,我需要显示一个模态窗口,以选择该相应报告所需的参数。

我正在处理在contextMenuBehavior java class

的下面方法中选择的菜单选项
public void onRequest()
{
    final Component component = getComponent();
    final IRequestCycle cycle = component.getRequestCycle();
    final IRequestParameters parameters = cycle.getRequest().getRequestParameters();
    final String action = parameters.getParameterValue("action").toString(null);
    if (null == action)
    {
        cycle.scheduleRequestHandlerAfterCurrent(new TextRequestHandler("application/json", "UTF-8",
                buildResponse()));
    } else
    {
        final String target = parameters.getParameterValue("targetId").toString(null);
        if (null == target)
        {
            throw new RuntimeException(
                    String.format("Did not receive a target object identifier for action [%s].", action));
        }
        menu.getAdapter().performActionOnTarget(component, action, target);
    }
}

和DomainActionHandler类 -

public void perform(final Component component, final String name, final Object target) throws ApplicationException
{
    if (target instanceof CannedReport)
    {
        final CannedReport report = (CannedReport) target;

        if ("runHtml".equals(name))
        {
            component.getPage().setResponsePage(new RunReport(report.getReportId()));
        } else if ("runExcel".equals(name))
        {
            //AjaxRequestTarget ajaxTarget = AjaxRequestTarget.get();
            component.getPage().setResponsePage(new ModalReport(ajaxTarget, report.getReportId(), ReportFormat.EXCEL));
        }
    }
}

和ModalReport类

public ModalReport(AjaxRequestTarget target, String reportId, ReportFormat format)
{
    super();
    setDefaultModel(modelFactory.createReportsModel());
    reportFiltersWindow = addReportFiltersWindow(this, "reportFiltersWindow");

    final IModel<Boolean> acceptedModel = new Model<Boolean>(Boolean.FALSE);
    final IModel<ReportModel> filtersModel = modelFactory.createEditReportModel(reportId);
    reportFiltersWindow.setContent(new ReportFiltersPanel(reportFiltersWindow, filtersModel, acceptedModel));

    modals.showWindow(target, reportFiltersWindow, new WindowClosedHandler() {
        private static final long serialVersionUID = 1L;

        /** {@inheritDoc} */
        @Override
        public void onWindowClosed(final AjaxRequestTarget target)
        {
            // some action
        }
    });
}

为了显示模态窗口,我需要在ModalReport java类的modals.showWindow中使用AjaxRequestTarget。我无法弄清楚如何获得AjaxRequestTarget,因为它带有一个行为。请让我知道如何获得它。感谢。

0 个答案:

没有答案