Skip to content

Commit

Permalink
Added application root to link's target url
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 6, 2015
1 parent 46ffc66 commit 2a78d8f
Showing 1 changed file with 19 additions and 1 deletion.
Expand Up @@ -9,7 +9,12 @@
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.RequestUtils;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.cycle.RequestCycle;

import javax.servlet.ServletContext;
import java.util.List;

/**
Expand Down Expand Up @@ -62,7 +67,20 @@ public void onClick() {
@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
tag.put("href", link.getTargetUrl());
String rootContext = "";
if (link.getTargetUrl() != null && !link.getTargetUrl().startsWith("http://") &&
!link.getTargetUrl().startsWith("https://") &&
!link.getTargetUrl().startsWith("www://") &&
!link.getTargetUrl().startsWith("//")) {
WebApplication webApplication = WebApplication.get();
if (webApplication != null) {
ServletContext servletContext = webApplication.getServletContext();
if (servletContext != null) {
rootContext = servletContext.getServletContextName();
}
}
}
tag.put("href", rootContext + link.getTargetUrl());
}
};
linkItem.add(new Label(ID_IMAGE) {
Expand Down

0 comments on commit 2a78d8f

Please sign in to comment.