0

How can I render the contents of an attribute dynamically?

Something like:

style="#{not empty book.image ? 'background-image: url('+ book.image +'); border: 1px; ' : ''}

I don't know how to reference book.image inside the attribute.

I can't place a ui:fragment inside the element either to say whether to render or not style. I don't think it is an efficient idea to duplicate the whole element, which already has some other attributes, inside two different ui:fragments (one with empty rendered and the other one with not empty rendered). I don't think it is a good idea to place my presentation in the Named bean like this: style="#{bookNamedBean.TheStyle}", as it will mix layers.

user1156544
  • 1,725
  • 2
  • 25
  • 51
  • Did you try `resource[book.image]` when `book.image` is something like `/path/to/some/image.jpeg`? See [How to reference CSS / JS / image resource in Facelets template?](https://stackoverflow.com/questions/8367421/how-to-reference-css-js-image-resource-in-facelets-template) – Selaron May 25 '19 at 19:55
  • I haven't. I am not using resources. This is a dynamic value I got from another system, not sure this apply to my situation – user1156544 May 25 '19 at 20:01
  • What is the problem with your suggested solution? It should work. – Selaron May 26 '19 at 05:56
  • @Selaron It was failing with a numeric exception. The solution was pointed by honourable BalusC – user1156544 May 27 '19 at 07:45

0 Answers0