1

I have my sites content saved as plain html in my database. It is only simple data no input from the user is possible. I like to show the content as follows: if content.jsf?Sitename gets called i want to show the content of the site "Sitename". I already have the content saved in my ApplicationScoped Bean. content.xhtml:

<ui:composition template="template/common/commonLayout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="content">
//show content here
</ui:define>
</ui:composition>

I want to do this because, i'd like to add new pages/subpages without redeploying the whole application.

How can I make this work?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

3

You can use <h:outputText escape="false"> to show plain HTML from a bean property.

<h:outputText value="#{yourApplicationScopedBean.html}" escape="false" />

If you want to parameterize it, use EL 2.2 feature of passing method arguments, or use a Map.

Beware of potential XSS attack holes if this concerns user-controlled data though.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thank you very much. I'm new to jsf. Can you please give me an example for the paramaterization by using a map? – user1251628 Jan 27 '13 at 17:11
  • Have a `Map` property. Imagine that the desired HTML is been put in the map with the key `someKey`, then you can get it by `#{bean.map.someKey}`. – BalusC Jan 27 '13 at 18:20
  • the first part I already had implemented like that. But what I don't get is the second part. First of all someKey is a key of the map? How do I get this key from the url (content.jsf?Sitename)? – user1251628 Jan 27 '13 at 20:01
  • You can get request parameters in EL by `#{param}` map. So e.g. `content.jsf?foo=bar` will give you string "bar" on `#{param.foo}`. So using `#{bean.map[param.foo]}` will return the map entry associated with string key "bar". To learn more about EL, see also http://stackoverflow.com/tags/el/info – BalusC Jan 27 '13 at 20:03
  • Thank you very much, that was the part I was looking for! – user1251628 Jan 27 '13 at 20:37