Discussion:
how to create an anchor column in a celltable
Ousti Driss
2018-08-28 16:00:00 UTC
Permalink
Hey everyone,

I'm writing the code of a simple web app using gwt, I have a Celltable all
its columns are String type,
one of the columns is a url column , I want to make this column clickable,
which means once you click on a cell
of this column, you are redicted to the url shown, is that possible?
i tried to add an anchor column to the table, but I got error messages
while defining this column when I call the getValue method, the type of
return should be a string!!
Is there a way to do such a thing?

Thank you :)
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Josselin Bardet
2018-08-29 11:42:19 UTC
Permalink
Hi,

You can use a custom cell to do what you want.
You can look at the ButtonCell class for exemple

The render() method is called for each row of the cell table, you can make
your <a href=""> link there

@see com.google.gwt.cell.client.ButtonCell
Post by Ousti Driss
Hey everyone,
I'm writing the code of a simple web app using gwt, I have a Celltable all
its columns are String type,
one of the columns is a url column , I want to make this column clickable,
which means once you click on a cell
of this column, you are redicted to the url shown, is that possible?
i tried to add an anchor column to the table, but I got error messages
while defining this column when I call the getValue method, the type of
return should be a string!!
Is there a way to do such a thing?
Thank you :)
--
You received this message because you are subscribed to the Google Groups
"GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Thomas Broyer
2018-08-29 13:45:27 UTC
Permalink
If you want to display text as-is (e.g. not a link), then you can use a
ClickableTextCell (see it live, with source code,
in http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellSampler),
the FieldUpdater will be called when the cell is clicked.
Alternatively, you could use a TextCell with a custom SafeHtmlRenderer that
would wrap the URL in a link (easiest would probably be to implement this
using a SafeHtmlTemplates: pass the URL as input –you'll want to pass it as
a SafeUri, constructed using UriUtils.fromString()–, use it to construct
something like <a href="{0}" target="_blank">{0}</a>)
Post by Ousti Driss
Hey everyone,
I'm writing the code of a simple web app using gwt, I have a Celltable all
its columns are String type,
one of the columns is a url column , I want to make this column clickable,
which means once you click on a cell
of this column, you are redicted to the url shown, is that possible?
i tried to add an anchor column to the table, but I got error messages
while defining this column when I call the getValue method, the type of
return should be a string!!
Is there a way to do such a thing?
Thank you :)
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Ousti Driss
2018-08-29 14:50:24 UTC
Permalink
What I want is when you click on the cell a new tab opens with the url you
clicked,
my string url column is filled with the response I get from the servlet
can you please give me more details on the alternative response.
Post by Thomas Broyer
If you want to display text as-is (e.g. not a link), then you can use a
ClickableTextCell (see it live, with source code, in
http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellSampler),
the FieldUpdater will be called when the cell is clicked.
Alternatively, you could use a TextCell with a custom SafeHtmlRenderer
that would wrap the URL in a link (easiest would probably be to implement
this using a SafeHtmlTemplates: pass the URL as input –you'll want to pass
it as a SafeUri, constructed using UriUtils.fromString()–, use it to
construct something like <a href="{0}" target="_blank">{0}</a>)
Post by Ousti Driss
Hey everyone,
I'm writing the code of a simple web app using gwt, I have a Celltable
all its columns are String type,
one of the columns is a url column , I want to make this column
clickable, which means once you click on a cell
of this column, you are redicted to the url shown, is that possible?
i tried to add an anchor column to the table, but I got error messages
while defining this column when I call the getValue method, the type of
return should be a string!!
Is there a way to do such a thing?
Thank you :)
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
hy
2018-08-29 16:52:36 UTC
Permalink
Create a class that renders anchor like below:

public class CustomAnchorCell
extends ClickableTextCell {

private String itsHref = "";
private boolean isEnabled = true;

public CustomAnchorCell(String inHref) {
super();
itsHref = inHref;
}

public CustomAnchorCell() {
super();
itsHref = "";
}

public CustomAnchorCell(String inHref, boolean inEnabled) {
this(inHref);
isEnabled = inEnabled;
}

@Override
protected void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
if (value != null) {
String theElementStart = "";
String theElementEnd = "";
if (isEnabled) {
theElementStart = "<a href='" + itsHref + "'";
theElementEnd = "</a>";
} else {
theElementStart = "<span";
theElementEnd = "</span>";
}
sb.appendHtmlConstant(theElementStart + " class='" + itsClassName + "'>")
.append(value)
.appendHtmlConstant(theElementEnd);
}
}

public void setHref(String inHref) {
itsHref = inHref;
}

public void setEnabled(boolean inEnabled) {
isEnabled = inEnabled;
}

public void setClassName(String inClassName) {
itsClassName = inClassName;
}
}



Use it like this:

Column<Report, String> theReport = new Column< Report, String>(new CustomAnchorCell()) {
@Override
public String getValue(Report object) {
return "Hello New Tab";
}

@Override
public void render(Cell.Context context, Report object, SafeHtmlBuilder sb) {
CustomAnchorCell theCustomAnchorCell = (CustomAnchorCell) getCell();
theCustomAnchorCell.setHref("_your new tab url_");
theCustomAnchorCell.setClassName(*"_your custom css class name_"*);

super.render(context, object, sb);
}
};
Post by Ousti Driss
What I want is when you click on the cell a new tab opens with the url you
clicked,
my string url column is filled with the response I get from the servlet
can you please give me more details on the alternative response.
Post by Thomas Broyer
If you want to display text as-is (e.g. not a link), then you can use a
ClickableTextCell (see it live, with source code, in
http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellSampler),
the FieldUpdater will be called when the cell is clicked.
Alternatively, you could use a TextCell with a custom SafeHtmlRenderer
that would wrap the URL in a link (easiest would probably be to implement
this using a SafeHtmlTemplates: pass the URL as input –you'll want to pass
it as a SafeUri, constructed using UriUtils.fromString()–, use it to
construct something like <a href="{0}" target="_blank">{0}</a>)
Post by Ousti Driss
Hey everyone,
I'm writing the code of a simple web app using gwt, I have a Celltable
all its columns are String type,
one of the columns is a url column , I want to make this column
clickable, which means once you click on a cell
of this column, you are redicted to the url shown, is that possible?
i tried to add an anchor column to the table, but I got error messages
while defining this column when I call the getValue method, the type of
return should be a string!!
Is there a way to do such a thing?
Thank you :)
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Ousti Driss
2018-08-30 10:01:27 UTC
Permalink
Problem solved, thank you everyone,
a special thank to hy
Post by hy
public class CustomAnchorCell
extends ClickableTextCell {
private String itsHref = "";
private boolean isEnabled = true;
public CustomAnchorCell(String inHref) {
super();
itsHref = inHref;
}
public CustomAnchorCell() {
super();
itsHref = "";
}
public CustomAnchorCell(String inHref, boolean inEnabled) {
this(inHref);
isEnabled = inEnabled;
}
@Override
protected void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
if (value != null) {
String theElementStart = "";
String theElementEnd = "";
if (isEnabled) {
theElementStart = "<a href='" + itsHref + "'";
theElementEnd = "</a>";
} else {
theElementStart = "<span";
theElementEnd = "</span>";
}
sb.appendHtmlConstant(theElementStart + " class='" + itsClassName + "'>")
.append(value)
.appendHtmlConstant(theElementEnd);
}
}
public void setHref(String inHref) {
itsHref = inHref;
}
public void setEnabled(boolean inEnabled) {
isEnabled = inEnabled;
}
public void setClassName(String inClassName) {
itsClassName = inClassName;
}
}
Column<Report, String> theReport = new Column< Report, String>(new CustomAnchorCell()) {
@Override
public String getValue(Report object) {
return "Hello New Tab";
}
@Override
public void render(Cell.Context context, Report object, SafeHtmlBuilder sb) {
CustomAnchorCell theCustomAnchorCell = (CustomAnchorCell) getCell();
theCustomAnchorCell.setHref("_your new tab url_");
theCustomAnchorCell.setClassName(*"_your custom css class name_"*);
super.render(context, object, sb);
}
};
Post by Ousti Driss
What I want is when you click on the cell a new tab opens with the url
you clicked,
my string url column is filled with the response I get from the servlet
can you please give me more details on the alternative response.
Post by Thomas Broyer
If you want to display text as-is (e.g. not a link), then you can use a
ClickableTextCell (see it live, with source code, in
http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellSampler),
the FieldUpdater will be called when the cell is clicked.
Alternatively, you could use a TextCell with a custom SafeHtmlRenderer
that would wrap the URL in a link (easiest would probably be to implement
this using a SafeHtmlTemplates: pass the URL as input –you'll want to pass
it as a SafeUri, constructed using UriUtils.fromString()–, use it to
construct something like <a href="{0}" target="_blank">{0}</a>)
Post by Ousti Driss
Hey everyone,
I'm writing the code of a simple web app using gwt, I have a Celltable
all its columns are String type,
one of the columns is a url column , I want to make this column
clickable, which means once you click on a cell
of this column, you are redicted to the url shown, is that possible?
i tried to add an anchor column to the table, but I got error messages
while defining this column when I call the getValue method, the type of
return should be a string!!
Is there a way to do such a thing?
Thank you :)
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Ousti Driss
2018-08-30 10:02:07 UTC
Permalink
Problem solved, thank you everyone,
a special thank to hy
Post by Ousti Driss
Hey everyone,
I'm writing the code of a simple web app using gwt, I have a Celltable all
its columns are String type,
one of the columns is a url column , I want to make this column clickable,
which means once you click on a cell
of this column, you are redicted to the url shown, is that possible?
i tried to add an anchor column to the table, but I got error messages
while defining this column when I call the getValue method, the type of
return should be a string!!
Is there a way to do such a thing?
Thank you :)
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Loading...