0

I've got a pretty simple code snippet that is really giving me some trouble. I've got a very simple method that hits the "URL" parameter and when there is a value it is returned. When it hits the "fragment" parameter it doesn't return anything and for the life of me can't figure out why I don't get any errors I simply get an empty string.

url = properties.get("url", "")
fragment = properties.get("fragment", "")
Page checkedPage = resource.resourceResolver.getResource(url).adaptTo(Page)

url = chatOverlay ? headerURL(checkedPage, url, fragment) : ""

private static String headerURL(Page checkedPage, String url, String fragment) {
    url += (checkedPage) ? ".html" : ""
    url += (fragment) ? "#$fragment" : ""
}

Any help is greatly appreciated. I'm a newb so code snippets are really helpful.

Delmon Young
  • 2,013
  • 5
  • 39
  • 51

2 Answers2

1

You are using checkedPage and fragment as booleans, while they are a Page and String.

Plus your method should return a String and you are not returning anything. Plus you cannot pass a String by reference.

private static String headerURL(Page checkedPage, String url, String fragment) {
    url += (checkedPage!=null) ? ".html" : "";
    url += (!"".equals(fragment)) ? "#$fragment" : "";
    return url;
}

P.S. In Java a statement ends with semicolon

notdang
  • 500
  • 2
  • 8
0

Try to put your code in try catch block if not. Your code may be hitting an exception and if you are not catching it, you may not be knowing exactly what is happening.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136