0

I have a backing bean and an XHTML that is tied to this backing bean. I have a private instance variable called testerString.

Here is an excerpt of the backingbean

public class LinkDataBackingBean {

    Map<String, LinkInfo> linkMap = new HashMap<String, LinkInfo>();
    List<LinkInfo> list = new ArrayList<LinkInfo>();
    private String testerString = "http://www.google.com";

    public String getTesterString() {
            return testerString;
    }
    public LinkDataBackingBean() throws FileNotFoundException {
        System.out.println("hello");
        for(int i = 0; i < 10; i++){
        list.add(new LinkInfo("hi", "www.google.com"));
        //linkMap = getLinkData()
        }
    }

As you can see, I've manually populated the variable with http://www.google.com. There comes a time in my XHTML where I would like to have someone click on a link and then it will go to the URL described by testerString.

  1. One way I tried this was this, as a passed variable.

    <f:metadata>
        <f:viewParam name="id" value="#{linkDataBackingBean.testerString}" />
    </f:metadata>
    

    And then:

    <a href="#{param['id']}">TEST</a>
    

    This did not work, in the sense that "TEST" did not appear as a hyperlink at all (whereas if I manually put in "http://www.google.com" for the value of the former statement, it DOES appear as a hyperlink and works fine).

  2. I've also tried the following, plugging the backing bean value directly (have to screw up formatting or SO won't show):

    <a href="#{linkDataBackingBean.testerString}">TEST</a>
    

    This yielded a similar result - TEST did not appear as an underlined hyperlink kind of thing.

  3. I considered using outputLink, but faced similar woes, I do get the Text to be a hyperlink, but it does not link to the domain I specified:

    <h:outputLink id="link1" value="#{ linkDataBackingBean.testerString}">
        <h:outputText value="TEST" />
    </h:outputLink>
    

    This links to the base dir of my whole project - http://localhost:8080/name-of-my-proj/faces/

    When I do the same as above, but populate value with "http://www.google.com", it properly goes there. It doesn't seem to get/understand my reference to the backingbean.

What sticking me is identifying what would be required to have TEST appear as a hyperlink and, when someone clicks on it, them being directed to the URL indicated by testerString? Surely there is some JSF "plumbing" I am missing.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
PinkElephantsOnParade
  • 6,452
  • 12
  • 53
  • 91
  • Possible duplicate of [Redirect to external URL in JSF](http://stackoverflow.com/questions/5092439/redirect-to-external-url-in-jsf) – Luiggi Mendoza Dec 28 '15 at 19:58
  • Add `"http://"` to your url, use `"http://www.google.com"` not just `"www.google.com"`. That's how web works. – Luiggi Mendoza Dec 28 '15 at 19:59
  • @LuiggiMendoza all references to google include the http:// in front – PinkElephantsOnParade Dec 28 '15 at 20:02
  • Symptoms suggest `#{param.id}` and `#{linkDataBackingBean}` simply doesn't exist. Another thing which caught my eye is that you initially mentioned JSP in tags and title while you said to use XHTML. Those are mutually exclusive and abuse could be another probable cause of your problem. – BalusC Dec 28 '15 at 20:24
  • please try to print the value of `#{linkDataBackingBean.testerString}` anywhere in the page to see if the managed bean and the property are correctly fetched. just put it anywhere in the page and see if the value appears correctly – Laabidi Raissi Dec 28 '15 at 20:55
  • @LaabidiRaissi: a link with an empty href is unclickable and not underlined. This matches the described symptoms. – BalusC Dec 28 '15 at 20:57
  • @BalusC: yep, as you mentioned it in the comment before mine. But as OP seems to be starting with JSF, I wanted to give him some hint to check it – Laabidi Raissi Dec 28 '15 at 21:04
  • Right click, *View page source* in a webbrowser is often more enlightening to web development starters toying with a server side web framework. – BalusC Dec 28 '15 at 21:05

0 Answers0