How to display download link with file name in wicket

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to display download link with file name in wicket

kspat
Hi,

I have 2 issues for which I need guidance from you.

Issue 1:::

In my application I am trying to write a page where I am having one html file with one wicket panel with id mapped to a table.
And in the java file I am creating columns with AbstractColumns. Then I am populating the DataTable with id (which is specified in the html page), columns (created using AbstractColumns), dataprovider (this feeds the row data to the table), and rows per page.

Coming to the columns, except one column all other are Label. And do not see any problem.

But when I want to have a DownloadLink for a file present on the server I am facing issue. I want to have the fileName as the DownloadLink which is not happening. (Just to remind I am not using separate wicket ids for each field). I am passing id, File (file object present on the server) and fileName (this is the name displayed on the popup when the link is clicked). This results in the Id being displayed in the place of link field and when this is clicked I am able to download the file.

I need help on how do I get the fileName as download link instead of id.

new AbstractColumn(new MessageModel(COLUMN_NAME)) {
    @Override
    public void populateItem(Item cellItem, String id, IModel rowModel) {
        final MyClass myClass = (MyClass) rowModel.getObject();
        final File fileDirectory = new File(filePath);
        cellItem.add(new DownloadLink(id, new File(fileDirectory, csvFile), myClass.getFile()));
        }
}

Issue 2 :::
I tried on more approach. For the download link I declared a Label with id and href for the link. We are able to get the link but when clicked it is appending the ip of the server which I do not want. I could not find any way to remove that IP. Following is the code snippet used in side the column:

cellItem.add(new Label(componentId, "<a onclick=\"window.open('" + filePath + "', '_blank'); target=\"_blank\" href=\"" + filePath + "\" > " + fileName + "").setEscapeModelStrings(false));

Thanks
Karthik S Patawardhan
Reply | Threaded
Open this post in threaded view
|

Re: How to display download link with file name in wicket

Martin Grigorov-4
Hi,

On Mon, Apr 13, 2015 at 3:34 PM, kspat <[hidden email]> wrote:

> Hi,
>
> I have 2 issues for which I need guidance from you.
>
> Issue 1:::
>
> In my application I am trying to write a page where I am having one html
> file with one wicket panel with id mapped to a table.
> And in the java file I am creating columns with AbstractColumns. Then I am
> populating the DataTable with id (which is specified in the html page),
> columns (created using AbstractColumns), dataprovider (this feeds the row
> data to the table), and rows per page.
>
> Coming to the columns, except one column all other are Label. And do not
> see
> any problem.
>
> But when I want to have a DownloadLink for a file present on the server I
> am
> facing issue. I want to have the fileName as the DownloadLink which is not
> happening. (Just to remind I am not using separate wicket ids for each
> field). I am passing id, File (file object present on the server) and
> fileName (this is the name displayed on the popup when the link is
> clicked).
> This results in the Id being displayed in the place of link field and when
> this is clicked I am able to download the file.
>
> I need help on how do I get the fileName as download link instead of id.
>

This is not very clear to me.
Do you want to show the file name as a label for the link ?
If YES then do:

String fileName = myClass.getFile();
cellItem.add(new DownloadLink(id, new File(fileDirectory, csvFile),
fileName).setBody(Model.of(fileName)));


> new AbstractColumn(new MessageModel(COLUMN_NAME)) {
>     @Override
>     public void populateItem(Item cellItem, String id, IModel rowModel) {
>         final MyClass myClass = (MyClass) rowModel.getObject();
>         final File fileDirectory = new File(filePath);
>         cellItem.add(new DownloadLink(id, new File(fileDirectory, csvFile),
> myClass.getFile()));
>         }
> }
>
> Issue 2 :::
> I tried on more approach. For the download link I declared a Label with id
> and href for the link. We are able to get the link but when clicked it is
> appending the ip of the server which I do not want. I could not find any
> way
> to remove that IP. Following is the code snippet used in side the column:
>
> cellItem.add(new Label(componentId, "<a onclick=\&quot;window.open('&quot;
> +
> filePath + &quot;', '_blank'); target=\&quot;_blank\&quot;
> href=\&quot;&quot; + filePath + &quot;\&quot; > " + fileName + "
> ").setEscapeModelStrings(false));
>

I think my answer for #1 should help you.
Please give more details and examples if I'm not answering your question.


>
> Thanks
> Karthik S Patawardhan
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-display-download-link-with-file-name-in-wicket-tp4670270.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to display download link with file name in wicket

kspat
Hello Martin,

Your understanding on the Issue 1 is correct. I want to show the file name as a label for the link ? And this link should lead me to file download when clicked.

I will try the approach given by you. Thanks a ton for the swift response. Really appreciate it.!

Best Regards,
Karthik S Patawardhan
Reply | Threaded
Open this post in threaded view
|

Re: How to display download link with file name in wicket

kspat
Hi Martin,

I tried the approach suggested by you and its working as expected. The file name is displayed in the filed, and when clicked the file download pop up is displayed.

However the file name is displayed as a link, but as a plain text. Is there any way out to make sure it is displayed as a link ?

Regards,
Karthik S Patawardhan
Reply | Threaded
Open this post in threaded view
|

Re: How to display download link with file name in wicket

Martin Grigorov-4
Hi,

You have to add a Panel to the CellItem.
The panel should contain a link (<a>)
On Apr 14, 2015 12:47 AM, "kspat" <[hidden email]> wrote:

> Hi Martin,
>
> I tried the approach suggested by you and its working as expected. The file
> name is displayed in the filed, and when clicked the file download pop up
> is
> displayed.
>
> However the file name is displayed as a link, but as a plain text. Is there
> any way out to make sure it is displayed as a link ?
>
> Regards,
> Karthik S Patawardhan
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-display-download-link-with-file-name-in-wicket-tp4670270p4670281.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to display download link with file name in wicket

kspat
Hi,

Thanks for the response. As I have not given separate wickets ids for each column will the approach of adding Panel to CellItem and creating one more wicket id in Panel with a  link . Please confirm this.
Reply | Threaded
Open this post in threaded view
|

Re: How to display download link with file name in wicket

Martin Grigorov-4
confirming!
On Apr 14, 2015 6:04 AM, "kspat" <[hidden email]> wrote:

> Hi,
>
> Thanks for the response. As I have not given separate wickets ids for each
> column will the approach of adding Panel to CellItem and creating one more
> wicket id in Panel with a  link  . Please confirm this.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-display-download-link-with-file-name-in-wicket-tp4670270p4670290.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>