Reputation: 47945
I need to manage a Hyperlink object in GWT. What i need is :
1 - add it into a span (like InlineLabel)
I tried Hyperlink affitta_3_span_1=new Hyperlink(result.get(i)[0], "");
, but it create somethings like this :
<div class="affitta_3_span_1">
<a href="#">t1</a>
</div>
in fact i need this :
<span class="affitta_3_span_1">
<a href="#">t1</a>
</span>
2 - manage Hyperlink History token
I put my internal links such Hyperlink affitta_3_span_1=new Hyperlink(result.get(i)[1], "article/"+result.get(i)[0])
but i don't know how to get the parameter on token when they call the onValueChange() function. How can I do it?
Cheers
Upvotes: 0
Views: 907
Reputation: 1094
For the first question, use an Anchor
since it's inlined.
For the second one, you need to 'listen' to history change events by extending ValueChangeHandler
and calling History.addValueChangeHandler(this);
in your class. For example,
class MyClass implements ValueChangeHandler<String> {
public MyClass {
...
History.addValueChangeHandler(this);
}
@Override
public void onValueChange(ValueChangeEvent<String> event) {
String token = event.getValue();
if (token.equals("foo")) {
// go to one page
} else if token.equals("bar")) {
// go to another page
}
}
}
Upvotes: 1
Reputation: 20890
Use an Anchor
. The output is just an <a>
tag that has no <div>
or <span>
around it, but if you need a <span>
you can add it with an HTML panel.
To set a URL that history can access, just put a #
at the beginning. Something like
myAnchor.setText(result.get(i)[1]);
myAnchor.setUrl("#article/"+result.get(i)[0]);
Now, when you click myAnchor, onValueChange will be passed the token "article/whatever". The unfortunate side effect is that your urls look like http://example.com/#article/whatever, but that's the only way to get the token to the History object with just GWT.
Upvotes: 1
Reputation: 1577
If you only need a ClickHandler on your link and no history support, you can use the Anchor widget, which is based on an <a>
tag that has display: inline
by default.
Upvotes: 0