0

我有可以工作的按钮:

    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)

为什么这不起作用?

4

2 回答 2

0

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

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

于 2012-08-30T16:11:03.527 回答
0

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

new StringResourceModel("sheets", this,null)
于 2012-08-30T12:37:38.493 回答