You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Solum <dj...@yahoo.com> on 2013/06/14 18:22:17 UTC

How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

I am using Wicket 6.8 and have a sortable DefaultDataTable that gets its
columns programmatically. 

The markup to get this table and the dynamically generated columns simple
(I've added spaces so it all shows):

        < wicket:panel>
            < table wicket:id="dataTable" border="0" cellpadding="1"
cellspacing="1" width="90%" / >
        < /wicket:panel>

All of the columns are generated from a passed in LinkedHashMap of labels
and attributes:

    for (Entry<String, String> entry : entrySet) {
        final String label = entry.getKey();
        final String attribute = entry.getValue();
        columns.add(new PsPropertyColumn(label, attribute) {

            @Override
            public void populateItem(Item cellItem, String componentId,
IModel model)
            {
                final Object modelObject = model.getObject();
                final Object value = PropertyResolver.getValue(attribute,
modelObject);
                // Add an edit link
                BookmarkablePageLink link = new ...;
                ...
                cellItem.add(link);
            }
        }
    }

    DefaultDataTable table = new DefaultDataTable("dataTable", columns,
dataProvider, MAX_ROWS) {
        ...
    }
    add(table);

So this properly displays as a sortable table with clickable columns that
send the user to the required page.  However, as many posts have mentioned,
this is rendered as a cell with an onclick handler rather than an anchor (<
a href="..." />) tag. I want the anchor tag for a couple of reasons, one if
which is that I want to add my own onclick handler without having an
existing onclick handler in the way.

I have seen a solution that says to put an anchor tag inside a panel in the
HTML markup, and to add the link inside of a Panel subclass.  Sadly for me
the markup in the examples wasn't complete, and whatever I try (anchor tags,
tr/td tags, panel tags, etc.), I get the same error:

     Last cause: Close tag not found for tag: 
. For Components only raw markup is allow in between the tags but not other
Wicket Component. Component: [DefaultDataTable [Component id = dataTable]] 

Here is the simplest thing I've tried:

        < wicket:panel>
            < table wicket:id="dataTable" border="0" cellpadding="1"
cellspacing="1" width="90%">
                < a href="#" wicket:id="link">< /a>
            < /table>
        < /wicket:panel>

Again, no success.  I would love to see markup that allows the
BookmarkablePageLinks be rendered insided the DefaultDataTable as anchor
tags.  Thanks in advance for any help.





--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by Martin Grigorov <mg...@apache.org>.
Please create a mini application (a quickstart) that shows the problem and
upload it somewhere. Or put it in GitHub/BitBucket.
Then someone of us will fix it and send it back to you.


On Tue, Jun 18, 2013 at 12:25 AM, David Solum <dj...@yahoo.com> wrote:

> If you're saying to add the fragment tag outside the table tag, I don't get
> any errors, but the Links I add are still rendered as div tags with onclick
> handlers.  What would tie the BookmarkablePageLinks that I add to the
> DefaultDataTable to the anchor tags in your markup?  Thank you.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659570.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by David Solum <dj...@yahoo.com>.
If you're saying to add the fragment tag outside the table tag, I don't get
any errors, but the Links I add are still rendered as div tags with onclick
handlers.  What would tie the BookmarkablePageLinks that I add to the
DefaultDataTable to the anchor tags in your markup?  Thank you.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659570.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by Martin Grigorov <mg...@apache.org>.
You have to use just <table wicket:id="..." ...></table> for the DataTable.
And a separate markup for the cell content. For example with a Fragment:
<wicket:fragment id="linkFragment"><a
wicket:id="link"></a></wicket:fragment>
Or use Panel if you don't have experience with Fragments


On Mon, Jun 17, 2013 at 6:19 PM, David Solum <dj...@yahoo.com> wrote:

> Here is the simplest thing I've tried:
>
>         < wicket:panel>
>             < table wicket:id="dataTable" border="0" cellpadding="1"
> cellspacing="1" width="90%">
>                 < a href="#" wicket:id="link">< /a>
>             < /table>
>         < /wicket:panel>
>
> (I added the spaces after the angled brackets just for posting, they are
> not
> part of the markup in my code.)
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659556.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by David Solum <dj...@yahoo.com>.
Here is the simplest thing I've tried: 

        < wicket:panel> 
            < table wicket:id="dataTable" border="0" cellpadding="1"
cellspacing="1" width="90%"> 
                < a href="#" wicket:id="link">< /a> 
            < /table> 
        < /wicket:panel> 

(I added the spaces after the angled brackets just for posting, they are not
part of the markup in my code.)



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659556.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by Martin Grigorov <mg...@apache.org>.
Show us your new markup.


On Mon, Jun 17, 2013 at 5:09 PM, David Solum <dj...@yahoo.com> wrote:

> Hi,
>
> As I said in my original post, that markup works, but the
> BookmarkablePageLinks that I add are rendered as div tags with onclick
> handlers.  I am trying to get anchor tags.
>
> I believe the post that Sven referred to is a step in the right direction,
> but my markup gives me the unclosed tag error.
>
> Has anyone gotten a BookmarkablePageLink to render as an anchor tag?  If
> so,
> may I see the markup you used?  Thank you very much in advance.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659551.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by David Solum <dj...@yahoo.com>.
Hi,

As I said in my original post, that markup works, but the
BookmarkablePageLinks that I add are rendered as div tags with onclick
handlers.  I am trying to get anchor tags.

I believe the post that Sven referred to is a step in the right direction,
but my markup gives me the unclosed tag error.

Has anyone gotten a BookmarkablePageLink to render as an anchor tag?  If so,
may I see the markup you used?  Thank you very much in advance.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659551.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

DataTable should be used with markup like:
<table wicket:id="tableId"></table>

If you want complex markup for the cells' content than you have to add
Panel|Fragment|Border component to the column's item, as described in the
Wiki page.


On Fri, Jun 14, 2013 at 10:40 PM, David Solum <dj...@yahoo.com> wrote:

> Yes Sven, that is where I got the HTML I posted that gives me the "Close
> tag
> not found" error.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659514.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by David Solum <dj...@yahoo.com>.
Yes Sven, that is where I got the HTML I posted that gives me the "Close tag
not found" error.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502p4659514.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by Sven Meier <sv...@meiers.net>.
Have you read the following?

https://cwiki.apache.org/WICKET/adding-links-in-a-defaultdatatable.html

Sven

On 06/14/2013 06:22 PM, David Solum wrote:
> I am using Wicket 6.8 and have a sortable DefaultDataTable that gets its
> columns programmatically.
>
> The markup to get this table and the dynamically generated columns simple
> (I've added spaces so it all shows):
>
>          < wicket:panel>
>              < table wicket:id="dataTable" border="0" cellpadding="1"
> cellspacing="1" width="90%" / >
>          < /wicket:panel>
>
> All of the columns are generated from a passed in LinkedHashMap of labels
> and attributes:
>
>      for (Entry<String, String> entry : entrySet) {
>          final String label = entry.getKey();
>          final String attribute = entry.getValue();
>          columns.add(new PsPropertyColumn(label, attribute) {
>
>              @Override
>              public void populateItem(Item cellItem, String componentId,
> IModel model)
>              {
>                  final Object modelObject = model.getObject();
>                  final Object value = PropertyResolver.getValue(attribute,
> modelObject);
>                  // Add an edit link
>                  BookmarkablePageLink link = new ...;
>                  ...
>                  cellItem.add(link);
>              }
>          }
>      }
>
>      DefaultDataTable table = new DefaultDataTable("dataTable", columns,
> dataProvider, MAX_ROWS) {
>          ...
>      }
>      add(table);
>
> So this properly displays as a sortable table with clickable columns that
> send the user to the required page.  However, as many posts have mentioned,
> this is rendered as a cell with an onclick handler rather than an anchor (<
> a href="..." />) tag. I want the anchor tag for a couple of reasons, one if
> which is that I want to add my own onclick handler without having an
> existing onclick handler in the way.
>
> I have seen a solution that says to put an anchor tag inside a panel in the
> HTML markup, and to add the link inside of a Panel subclass.  Sadly for me
> the markup in the examples wasn't complete, and whatever I try (anchor tags,
> tr/td tags, panel tags, etc.), I get the same error:
>
>       Last cause: Close tag not found for tag:
> . For Components only raw markup is allow in between the tags but not other
> Wicket Component. Component: [DefaultDataTable [Component id = dataTable]]
>
> Here is the simplest thing I've tried:
>
>          < wicket:panel>
>              < table wicket:id="dataTable" border="0" cellpadding="1"
> cellspacing="1" width="90%">
>                  < a href="#" wicket:id="link">< /a>
>              < /table>
>          < /wicket:panel>
>
> Again, no success.  I would love to see markup that allows the
> BookmarkablePageLinks be rendered insided the DefaultDataTable as anchor
> tags.  Thanks in advance for any help.
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to dynamically add a hyperlink (BookmarkablePageLink) to DefaultDataTable that is rendered as an anchor

Posted by Jesse Long <jp...@unknown.za.net>.
Hi David,

The IColumn#populateItem method populates a cell in the HTML table. It 
is as if you are adding your components to markup like this:

<td wicket:id="xyz"></td>

If you have that, and you do:

add(new Link<Void>("xyz"){...});

then you will have the same results. Why? Because Link was not designed 
to be added to <td> markup. Actually, it can be added to <td>, but then 
you get the onclick behaviour you are describing.

What the link Sven sent is trying to say is this: you cant add a Link 
directly to the cellItem. You must create an intermediate component, the 
example shows it as the LinkPanel. The LinkPanel is added to the <td>, 
and this works nicely. The link panel then makes <a> markup available, 
and you add the link to that.

I usually use an abstract LinkPanel that has one abstract factory method 
to create the link, so my populateItem method looks like:

cellItem.add(
// adding link panel to cell
new LinkPanel<RowType>(componentId, rowModel){
     // link panel has abstract factory method for link
     @Override
     protected Component createLink(String componentId, IModel<RowType> 
model)
     {
         return new Link<RowType>(componentId, model)
         {
             @Override
             public void onClick()
             {
                 getModel().doSomething();
                 setResponsePage(....);
             }
         }.setBody(Model.of("Whatever"));
     }
});

hth,
Jesse

On 14/06/2013 18:22, David Solum wrote:
> I am using Wicket 6.8 and have a sortable DefaultDataTable that gets its
> columns programmatically.
>
> The markup to get this table and the dynamically generated columns simple
> (I've added spaces so it all shows):
>
>          < wicket:panel>
>              < table wicket:id="dataTable" border="0" cellpadding="1"
> cellspacing="1" width="90%" / >
>          < /wicket:panel>
>
> All of the columns are generated from a passed in LinkedHashMap of labels
> and attributes:
>
>      for (Entry<String, String> entry : entrySet) {
>          final String label = entry.getKey();
>          final String attribute = entry.getValue();
>          columns.add(new PsPropertyColumn(label, attribute) {
>
>              @Override
>              public void populateItem(Item cellItem, String componentId,
> IModel model)
>              {
>                  final Object modelObject = model.getObject();
>                  final Object value = PropertyResolver.getValue(attribute,
> modelObject);
>                  // Add an edit link
>                  BookmarkablePageLink link = new ...;
>                  ...
>                  cellItem.add(link);
>              }
>          }
>      }
>
>      DefaultDataTable table = new DefaultDataTable("dataTable", columns,
> dataProvider, MAX_ROWS) {
>          ...
>      }
>      add(table);
>
> So this properly displays as a sortable table with clickable columns that
> send the user to the required page.  However, as many posts have mentioned,
> this is rendered as a cell with an onclick handler rather than an anchor (<
> a href="..." />) tag. I want the anchor tag for a couple of reasons, one if
> which is that I want to add my own onclick handler without having an
> existing onclick handler in the way.
>
> I have seen a solution that says to put an anchor tag inside a panel in the
> HTML markup, and to add the link inside of a Panel subclass.  Sadly for me
> the markup in the examples wasn't complete, and whatever I try (anchor tags,
> tr/td tags, panel tags, etc.), I get the same error:
>
>       Last cause: Close tag not found for tag:
> . For Components only raw markup is allow in between the tags but not other
> Wicket Component. Component: [DefaultDataTable [Component id = dataTable]]
>
> Here is the simplest thing I've tried:
>
>          < wicket:panel>
>              < table wicket:id="dataTable" border="0" cellpadding="1"
> cellspacing="1" width="90%">
>                  < a href="#" wicket:id="link">< /a>
>              < /table>
>          < /wicket:panel>
>
> Again, no success.  I would love to see markup that allows the
> BookmarkablePageLinks be rendered insided the DefaultDataTable as anchor
> tags.  Thanks in advance for any help.
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-dynamically-add-a-hyperlink-BookmarkablePageLink-to-DefaultDataTable-that-is-rendered-as-an-ar-tp4659502.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org