如何在downloadLink中使用wicket StringResourceModel

时间:2012-08-30 12:09:01

标签: java wicket

我有按钮有效:

    Button options = new Button("sheets", new StringResourceModel("sheets", null)) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            setResponsePage(new TournamentOptionsPage(tournament, table) {

                private static final long serialVersionUID = 1L;
            });
        }
    };

现在我想用downloadLink替换这个按钮:

        add(new DownloadLink("sheets", new AbstractReadOnlyModel<File>() {
            private static final long serialVersionUID = 1L;

            @Override
            public File getObject() {
                File tempFile;
                try {
                    tempFile = PdfFactory.createSheets(WicketApplication.getSheetsPath(),
                            tournamentService.getSchedule(table, tournament), table);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
                return tempFile;
            }
        }, new StringResourceModel("sheets", null)).setCacheDuration(Duration.NONE).setDeleteAfterDownload(true));

但是这里我遇到了StringResourceModel的问题,当我推送链接时我得到了异常:

Caused by: java.util.MissingResourceException: Unable to find property: 'sheets'
    at org.apache.wicket.Localizer.getString(Localizer.java:239)
    at org.apache.wicket.Localizer.getString(Localizer.java:170)
    at org.apache.wicket.model.StringResourceModel.getString(StringResourceModel.java:425)
    at org.apache.wicket.model.StringResourceModel.getString(StringResourceModel.java:400)
    at org.apache.wicket.model.StringResourceModel.load(StringResourceModel.java:583)
    at org.apache.wicket.model.StringResourceModel.load(StringResourceModel.java:182)
    at org.apache.wicket.model.LoadableDetachableModel.getObject(LoadableDetachableModel.java:119)
    at org.apache.wicket.markup.html.link.DownloadLink.onClick(DownloadLink.java:151)
    at org.apache.wicket.markup.html.link.Link.onLinkClicked(Link.java:188)

为什么这不起作用?

2 个答案:

答案 0 :(得分:0)

我不知道为什么Button有效,但DownloadLink没有。无论如何,您可以解决将容器组件传递给StringResourceModel的问题。这样的事情应该没问题:

new StringResourceModel("sheets", this,null)

答案 1 :(得分:0)

我已经开了一个问题来讨论这个问题

https://issues.apache.org/jira/browse/WICKET-4738