0

I want to create a dynamic anchor tag. Let's say I have a database and I want to use them.

Example: Before

<a href="page1.xhtml">Page 1</a>
<a href="page2.xhtml">Page 2</a>
<a href="page3.xhtml">Page 3</a>

It should be something like this --After--

<a href="{Value from database}">{Value from database}</a>
<a href="#{appRoot}/{linkOpsBean.srcNameList[0]}">#{linkOpsBean.srcNameList[0]}</a>
  • I want to create multiple anchor tags with dynamic href values. I don't want to use hard-coded values. – Anushka Raj Jan 24 '23 at 08:44
  • Get the outcomes from a bean. For example https://stackoverflow.com/questions/18150728/iterate-through-liststring-using-jsf-2 – Jasper de Vries Jan 24 '23 at 08:50
  • Hey!! Getting values like this: javax.faces.model.SelectItem@2246fe0d javax.faces.model.SelectItem@64b15db7 javax.faces.model.SelectItem@63b0796e javax.faces.model.SelectItem@53ed9818 javax.faces.model.SelectItem@46ceb2fe javax.faces.model.SelectItem@287c1375 javax.faces.model.SelectItem@48e7641d javax.faces.model.SelectItem@77f50841 javax.faces.model.SelectItem@441f0d03 javax.faces.model.SelectItem@c30594e javax.faces.model.SelectItem@7f040359 javax.faces.model.SelectItem@20ecbbf8 How to convert it to String? – Anushka Raj Jan 24 '23 at 08:53
  • Thank you so much, Jasper!! Your solution helped me a lot! Fixed the above issue too. I was using ArrayList srcNameList; converted it to ArrayList srcNameList; – Anushka Raj Jan 24 '23 at 09:38

1 Answers1

1

Here's what worked for me!

<ui:repeat value="#{Bean.srcNameList}" var="value">
   <li><a class="dropdown-item" href="#{value}">#{value}</a></li>
</ui:repeat>