Hi,
There is no anchor widget in GWT default UI widgets, There is more GWT
centered Hyperlink, which is basically anchro tag but with additional
behavior to provide navigation within application itself (history
feature),
People usually simply use HTML widget to quicly create anchors within
application,
if you are using GWT Designer here is example of anchor widget which
will integrate nicely with GWT Designer "design" view,
It could works as link or as anchor within your application,
class implementation:
package example.project.client;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.HasName;
import com.google.gwt.user.client.ui.Widget;
/**
* Basic implementation of raw Anchor <a> widget
* @see
http://www.w3schools.com/tags/tag_a.asp
* @author Peter Blazejewicz
*
*/
public class HTMLLink extends Widget implements HasHTML, HasName {
public HTMLLink() {
setElement(DOM.createAnchor());
}
public String getHref() {
return DOM.getElementAttribute(getElement(), "href");
}
public String getHTML() {
return DOM.getInnerHTML(getElement());
}
public String getId() {
return DOM.getElementAttribute(getElement(), "id");
}
public String getName() {
return DOM.getElementAttribute(getElement(), "name");
}
public int getTabIndex() {
return $getTabIndex(getElement());
}
public String getTarget() {
return DOM.getElementAttribute(getElement(), "target");
}
public String getText() {
return DOM.getInnerText(getElement());
}
public void setHref(String href) {
DOM.setElementAttribute(getElement(), "href", href == null ? "" :
href);
}
public void setHTML(String html) {
DOM.setInnerHTML(getElement(), html == null ? "" : html);
}
public void setId(String id) {
DOM.setElementAttribute(getElement(), "id", id == null ? "" : id);
}
public void setName(String name) {
DOM.setElementAttribute(getElement(), "name", name == null ? "" :
name);
}
public void setTabIndex(int index) {
$setTabIndex(getElement(), index);
}
public void setTarget(String target) {
DOM.setElementAttribute(getElement(), "target", target == null ?
""
: target);
}
public void setText(String text) {
DOM.setInnerText(getElement(), text == null ? "" : text);
}
private native int $getTabIndex(Element element)
/*-{
return element.tabIndex;
}-*/;
private native void $setTabIndex(Element element, int index)
/*-{
element.tabIndex = index;
}-*/;
}
here is example usage code (both features implemented):
package example.project.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class AnchorWidgetUsage implements EntryPoint {
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
// create link to GWT group with new browser window target
final HTMLLink googleGroup = new HTMLLink();
rootPanel.add(googleGroup);
googleGroup.setTarget("_blank");
googleGroup.setId("goglegroup");
googleGroup.setHref("
http://groups.google.com/group/Google-Web-
Toolkit/topics");
googleGroup.setHTML("Visit google GWT group");
// create named page anchor
final HTMLLink topNamedAnchor = new HTMLLink();
rootPanel.add(topNamedAnchor);
topNamedAnchor.setName("top");
// create named page link to scroll to top of page
final HTMLLink topNamedLink = new HTMLLink();
rootPanel.add(topNamedLink, 0, 700);
topNamedLink.setHref("#top");
topNamedLink.setText("Page top");
}
}
hth,
regards,
Peter
On Feb 16, 8:08 pm, Metegs <
meteomer...@gmail.com> wrote:
> hi,
> I would like to give links to pages but I couldn't found it in gwt and
> I am also using gwt designer for eclipse..
>
> I have already visit the pagehttp://
downloads.instantiations.com/DesignerDoc/integration/latest/do...
> but my problem still continues..
> In that example it opens both pages which I don't actually want. I
> would like to have link like if my site iswww.xyz.com-> when I click to a link it will open another page
likewww.xyz.com/abc.asporwww.xyz.com/abc.phpetc..