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.
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).
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.
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.