0

I have a URL as a string stored as an attribute in a class, and I am trying to retrieve it through EL in the outputLink like below:

<h:dataTable value="#{flagData.countries}" var="country"
            styleClass="table table-striped table-hover" border="1">
            <h:column>
                <f:facet name="header">Name</f:facet>
                #{country.name}
            </h:column>
            <h:column>
                <f:facet name="header">Flag</f:facet>
                <h:outputLink value="#{country.flag}"></h:outputLink>
                #{country.flag}
            </h:column> 
</h:dataTable>

But this isn't working.

I want the URL stored in #{country.flag} to be a clickable URL link. How do I do this?

EDIT:

This is the generated html:

<td>
                Argentina
            </td>
<td><a href="http://www.flags-and-anthems.com/flag-argentina.html" class="btn btn-link"></a>
                http://www.flags-and-anthems.com/flag-argentina.html
            </td>
Kingamere
  • 9,496
  • 23
  • 71
  • 110
  • Did you check how the generated HTML output looks like? Does it look all right? Hint: This is not a JSF specific problem. You'd have had exactly the same problem when using plain vanilla HTML the same way. – BalusC May 11 '16 at 12:03
  • @BalusC, oh yes I remember that. The solution had to do with using the class for the CSS bootstrap template I was using for my web app. thanks – Kingamere May 11 '16 at 12:34
  • @BalusC, that was last year. How did you remember that? – Kingamere May 11 '16 at 12:36
  • @BalusC, actually removing the CSS didn't work. Here is the source that is generated: ` Belgium http://www.flags-and-anthems.com/flag-belgium.html ` – Kingamere May 11 '16 at 13:32
  • 1
    "You'd" stands for "You would". And, does the generated HTML output look all right? The link's body is actually empty, right? – BalusC May 11 '16 at 13:36
  • @BalusC please see edit above. Seems like in the `` tag where `href` is stored the body isn't empty – Kingamere May 11 '16 at 13:45
  • Surely it is empty. Look once again, the text you want to appear in the link is displayed outside `` element and not inside (its body). – BalusC May 11 '16 at 13:45
  • @BalusC hmm that's strange that the link isn't clickable. let me try making a simple html file with `href` – Kingamere May 11 '16 at 13:46
  • How would you solve it if you were to edit the plain HTML code? Once you figure out that, it's merely a matter of doing exactly the same in JSF side (so that it generates exactly the desired HTML output). – BalusC May 11 '16 at 13:47
  • @BalusC oh wow, `#{country.flag}` had to go inside inside ``. Wonder how I missed that, seems obvious thinking about it – Kingamere May 11 '16 at 13:55

1 Answers1

0

you have to put the url you want to render as a clickable URL inside the tag

<h:outputLink value="#{country.flag}">#{country.flag}</h:outputLink>

the value of the output link is the url you will reach and the content of the tag is the text you have to click on

LCanosa
  • 9
  • 1
  • 3