0

Simply I have an array in my back-bean included some values like '1'-'2'-'3'-'4'-'5' In JSF I want to use rendered attribute in h:outputlink to visible or invisible a link on data-table rows based on some value from each row for example I can have the unique id in each row like rowvar.accountType.entity.id which return an unique id, then I wanna check if that array which I filled it in a back bean contains this id, then rendered value should be true and the row should be visible. like this <h:outputLink rendered="#{Arrays.asList(acceptedIds).contains(rowvar.accountType.entity.id) }"

but of course it isn't correct !

Could you help me to how to handle it ?

soheilz92
  • 127
  • 2
  • 19

3 Answers3

1

I solved my problem by using these statement

<c:set var="theString" value="#{MyBean.payByShetabAccount}"/>
<c:set var="theString2" value="#{rowvar.accountType.entity.name}" />

<h:outputLink styleClass="fancybox-iframe  tipsy" 
        rendered="#{fn:contains(theString, theString2) || theString == '*'}"                                        
        title="#{AccountBeanbeanMessages['property_settleToAccount_caption']}"
        value="hello.jsf">
        <h:graphicImage url="img/small-icons/list-operations/left.png" styleClass="standardTable_Icon"></h:graphicImage>
        </h:outputLink>
soheilz92
  • 127
  • 2
  • 19
0

You are right, it won't work this way.

One option is to refactor your code so it uses a Collection/List which provide a contains() method instead of using an array. This way it makes the whole story a lot easier.

Another solution would be to implement a method on your bean which accepts an array as parameter and returns a Collection instance of the array values.

You can also implement a custom EL function. Have a look at this answer to get an idea how to do that.

Community
  • 1
  • 1
unwichtich
  • 13,712
  • 4
  • 53
  • 66
0

I would create a method that takes in an array and id and returns a boolean. Then the EL expression could look something like "#{existsInArray(array, id)}"

Omoro
  • 972
  • 11
  • 22
  • I tried it also, I cant pass argument from JSF to mybacjbean, I means I could not pass 'rowvar.accountType.entity.id' – soheilz92 Feb 03 '14 at 14:59
  • Are you using older JSF version? From JSF 2+ that should be possible. We need to see your code, otherwise we can go on guessing forever. – Omoro Feb 03 '14 at 15:01