Convert String to Clickable Link

684 views Asked by At

I am creating a webpage that displays user history. Written in Java, I have pojo that contains properties that my jsf retrieves via bean injection. The problem: one of the values is a url. Currently, the String is a long url but isn't clickable. Also to note, these values (Strings) are in an ArrayList. How can I assign a String value that contains a url and output a clickable url?

userHistoryDetails.completeData bean may look like this (sudo):

[{status=complete,userid=123,reportUrl=http://www.reporturl.com}]

example of table created in my jsf file. Where #{cRow[cColModel.value]} creates a row in the table with its respective header value.

<ace:dataTable id="completedTable"
    value="#{userHistoryDetails.completeData}" var="cRow"
    paginator="true" rows="50" paginatorPosition="both"
    emptyMessage="NO RECORDS TO DISPLAY">
    <c:forEach items="#{userHistoryDetails.userHistoryHeaders}"
        var="cColModel">
        <ace:column headerText="#{cColModel.headerText}">
                #{cRow[cColModel.value]}
        </ace:column>
                </c:forEach>
</ace:dataTable>

Please let me know if this does not make sense. It is kind of hard to explain. Thanks in advance!

EDIT I have tried changing String to:

    [{status=complete,userid=123,reportUrl=<a href="http://www.reporturl.com">View report</a>}]

but still no luck. I feel like I am on the right track, just missing something.

enter image description here

1

There are 1 answers

3
BalusC On BEST ANSWER

How can I assign a String value that contains a url and output a clickable url?

Two ways:

<a href="#{bean.url}">#{bean.url}</a>
<h:outputLink value="#{bean.url}">#{bean.url}</h:outputLink>

userHistoryDetails.completeData bean may look like this (sudo):

[{status=complete,userid=123,reportUrl=http://www.reporturl.com}]

example of table created in my jsf file. Where #{cRow[cColModel.value]} creates a row in the table with its respective header value.

So .. If #{cColModel.value} equals to reportUrl you want to generate a link? That'll have to look something like this:

<ui:fragment rendered="#{cColModel.value eq 'reportUrl'}">
    <a href="#{cRow[cColModel.value]}">#{cRow[cColModel.value]}</a>
</ui:fragment>
<ui:fragment rendered="#{cColModel.value ne 'reportUrl'}">
    #{cRow[cColModel.value]}
</ui:fragment>