How to render JSF tags on html page from String field in a bean
How can I render JSF tags like HTML tags?
For example I have some html code in a string field:
<pre>String code = "example <br/> example";</pre>
If I use
<pre><h:outputText value="#{bean.code}" escape="false"/></pre>
I will get
<pre>example
example</pre>
Now I want to render jsf component in the same way. For example:
<pre>String code = '<h:button value="something" action="something"/>';</pre>
But it will be rendered as it is. As I think it must be translated first by JSF servlet to html tags. How could I render JSF controlls in that way? I've got texts containing lots of JSF controls (articles) stored in a database and I need to easy render JSF controlls fr开发者_开发百科om that.
This is a very bad idea. The JSF tags has to go in a Facelet file and the text has to go in DB. You should not manually add JSF tags to the text before storing in DB. You should do it in the Facelet file while displaying text from DB. That's how the "V" of MVC is supposed to work.
If you really insist to do so (this is prone to security attacks and you have to do a lot of validation to prevent that), then best what you could do is to create a Facelets ResourceResolver
which gets the data from the DB, saves it as a Facelet file in memory or on disk and returns the URL
to it.
精彩评论