You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ray Weidner <ra...@gmail.com> on 2010/06/16 08:17:38 UTC

Making rows of DefaultDataTable into links

Hi all,

Forgive my ignorance if this is too obvious.  I'm using DefaultDataTable to
display search results, and that's working fine.  What I'd like to do is
make each row of the table a hyperlink to the view/edit page of the record
in question.  How can I do this?

I was able to add links to a column, although they don't show up in the
browser as actual links.  Rather, they appear as text with associate
javascript to process an onclick event.  Here's the custom column I created
for this purpose:

private class IncidentLinkPropertyColumn extends PropertyColumn
<IncidentReport> {

public IncidentLinkPropertyColumn (IModel <String> nameModel, String
propertyName) {
super (nameModel, propertyName);
}
 @Override
public void populateItem (Item <ICellPopulator <IncidentReport>> item,
String componentId,
IModel <IncidentReport> model) {
PageParameters params = new PageParameters ();
params.put ("incidentId", model.getObject ().getRecordId ());
item.add (new LabelLink (componentId, CreateOrEditIncidentPage.class,
params));
}

private class LabelLink extends BookmarkablePageLink <Object> {
private static final long serialVersionUID = 3429331456890689136L;

public LabelLink (String componentId, Class <? extends Page> pageType,
PageParameters parameters) {
super (componentId, pageType, parameters);
}
 @Override
protected void onComponentTagBody (MarkupStream markupStream, ComponentTag
openTag) {
replaceComponentTagBody (markupStream, openTag, "click here!");
}
}
}

As I said, I'd like the rows to be links to the IncidentReport, but barring
that, it would be nice if the link column actually appeared as links, so
users can right-click to open in a separate tab.  If necessary, I can draft
an informational column (like ID) to serve as a link, as long as it is a
true link (so it will be visually obvious, as well as retaining right-click
functionality).

Any ideas?  Thanks in advance.

Re: Making rows of DefaultDataTable into links

Posted by Ray Weidner <ra...@gmail.com>.
Thanks, Jeremy, I think having a real link outweighs having the whole row
being a pseudo link, so I'm going to just have the ID column value be a
link.  But thanks for the advice; it's still informative.

On Wed, Jun 16, 2010 at 2:20 AM, Jeremy Thomerson <jeremy@wickettraining.com
> wrote:

> On Wed, Jun 16, 2010 at 1:17 AM, Ray Weidner <
> ray.weidner.developer@gmail.com> wrote:
>
> > Hi all,
> >
> > Forgive my ignorance if this is too obvious.  I'm using DefaultDataTable
> to
> > display search results, and that's working fine.  What I'd like to do is
> > make each row of the table a hyperlink to the view/edit page of the
> record
> > in question.  How can I do this?
> >
> > I was able to add links to a column, although they don't show up in the
> > browser as actual links.  Rather, they appear as text with associate
> > javascript to process an onclick event.  Here's the custom column I
> created
> > for this purpose:
> >
> > private class IncidentLinkPropertyColumn extends PropertyColumn
> > <IncidentReport> {
> >
> > public IncidentLinkPropertyColumn (IModel <String> nameModel, String
> > propertyName) {
> > super (nameModel, propertyName);
> > }
> >  @Override
> > public void populateItem (Item <ICellPopulator <IncidentReport>> item,
> > String componentId,
> > IModel <IncidentReport> model) {
> > PageParameters params = new PageParameters ();
> > params.put ("incidentId", model.getObject ().getRecordId ());
> > item.add (new LabelLink (componentId, CreateOrEditIncidentPage.class,
> > params));
> > }
> >
> > private class LabelLink extends BookmarkablePageLink <Object> {
> > private static final long serialVersionUID = 3429331456890689136L;
> >
> > public LabelLink (String componentId, Class <? extends Page> pageType,
> > PageParameters parameters) {
> > super (componentId, pageType, parameters);
> > }
> >  @Override
> > protected void onComponentTagBody (MarkupStream markupStream,
> ComponentTag
> > openTag) {
> > replaceComponentTagBody (markupStream, openTag, "click here!");
> > }
> > }
> > }
> >
> > As I said, I'd like the rows to be links to the IncidentReport, but
> barring
> > that, it would be nice if the link column actually appeared as links, so
> > users can right-click to open in a separate tab.  If necessary, I can
> draft
> > an informational column (like ID) to serve as a link, as long as it is a
> > true link (so it will be visually obvious, as well as retaining
> right-click
> > functionality).
> >
> > Any ideas?  Thanks in advance.
> >
>
> to make the rows into links, override newItem (or whatever the name is - it
> starts with new) that creates a new row.  then you could add an onclick to
> the row item, or even an ajaxeventbehavior("onclick") to do some ajax
> behavior....
>
> to make the column into a real link, you'll need to use a fragment since
> the
> default html for a cell is just a span.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>

Re: Making rows of DefaultDataTable into links

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Jun 16, 2010 at 1:17 AM, Ray Weidner <
ray.weidner.developer@gmail.com> wrote:

> Hi all,
>
> Forgive my ignorance if this is too obvious.  I'm using DefaultDataTable to
> display search results, and that's working fine.  What I'd like to do is
> make each row of the table a hyperlink to the view/edit page of the record
> in question.  How can I do this?
>
> I was able to add links to a column, although they don't show up in the
> browser as actual links.  Rather, they appear as text with associate
> javascript to process an onclick event.  Here's the custom column I created
> for this purpose:
>
> private class IncidentLinkPropertyColumn extends PropertyColumn
> <IncidentReport> {
>
> public IncidentLinkPropertyColumn (IModel <String> nameModel, String
> propertyName) {
> super (nameModel, propertyName);
> }
>  @Override
> public void populateItem (Item <ICellPopulator <IncidentReport>> item,
> String componentId,
> IModel <IncidentReport> model) {
> PageParameters params = new PageParameters ();
> params.put ("incidentId", model.getObject ().getRecordId ());
> item.add (new LabelLink (componentId, CreateOrEditIncidentPage.class,
> params));
> }
>
> private class LabelLink extends BookmarkablePageLink <Object> {
> private static final long serialVersionUID = 3429331456890689136L;
>
> public LabelLink (String componentId, Class <? extends Page> pageType,
> PageParameters parameters) {
> super (componentId, pageType, parameters);
> }
>  @Override
> protected void onComponentTagBody (MarkupStream markupStream, ComponentTag
> openTag) {
> replaceComponentTagBody (markupStream, openTag, "click here!");
> }
> }
> }
>
> As I said, I'd like the rows to be links to the IncidentReport, but barring
> that, it would be nice if the link column actually appeared as links, so
> users can right-click to open in a separate tab.  If necessary, I can draft
> an informational column (like ID) to serve as a link, as long as it is a
> true link (so it will be visually obvious, as well as retaining right-click
> functionality).
>
> Any ideas?  Thanks in advance.
>

to make the rows into links, override newItem (or whatever the name is - it
starts with new) that creates a new row.  then you could add an onclick to
the row item, or even an ajaxeventbehavior("onclick") to do some ajax
behavior....

to make the column into a real link, you'll need to use a fragment since the
default html for a cell is just a span.

-- 
Jeremy Thomerson
http://www.wickettraining.com