Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic rendering of html content on jsf

 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have to render my html code snippet at run time and include it on my jsf page (.xhtml) My code template would be stored in db and I have to get and show it on display.
1) I am rendering the code from the db and setting it to a string field in the model
2) on jsf (.xhtml) page i am using like this <hutputText value="#{model.htmlContent}" escape="false" />
but instead of rendering the page its not able to resolve the tags in the content and so not rendering it properly

for example <h:panelGrid><h<tw:inputText name="userName /></h:panelGrid> is not transformed in run time
if instead if i use <div><input type="text" name="userName" /></div> its rendered properly and i can see text box on the screen.
I guess jsf is not transforming it properly in run time
Is there any solution or work around for this?

Thanks
Sudharshan Tettu.
 
sachin potu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first check your web.xml, if the faces servet is there or not
if yes check your page, if the name spaces/ taglibs are correct not
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks sachin for your quick post.
Yeah everything is fine , if i copy paste the same content directly on to the xhtml page the tag <h:input... properly gets rendered
but if try to do the same using string outputText
1) like i set my xhtml content in a field in the model (contentHtml)
model.setContentHtml("><h:inputText value=\"#{model.username}\"");

2) on the xhtml page i do this
><hutputText value="#{model.contentHtml}" escape="false"/>


but if the same content is plain html its rendering properly , if i use any jsf tags like core or html , its notrendering properly.
 
Carl Manschold
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you declaring your jsf tags in a database? That wont work, the tags need to be part of the jsf/facelet when jsf builds the component tree.

Try a different approach instead, what is the purpose of this? It's likely that you will be able to meet your demands with using standard jsf functionality like <ui:fragment/>, rendered attributes based on your conditions, you can even write custom components to display your content based on your conditions.
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi carl
A standard template would be saved in a file system /db and i would retrieve it and i want that to be rendered in run time.
For example i can get this predefined code snippet from db/filesystem ...


I have my jsf (.xhtml) page , i want to include the above code snippet in that and render it dynamically at run time. its instead placing the code as such on xhtml page,rather than resolving it and transforming it to html page.


 
Tim Holloway
Saloon Keeper
Posts: 18302
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, this is a bit of a challenge. The "escape=false" attribute on outputText is for HTML, and you want to insert JSF View Definition Language (xhtml). However, that would effectively require recursion on the VDL compiler.

To get JSF tags to be included and compiled from a database would probably require writing an extension to the Facelets subsystem. Since Facelets is retrieving the xthml files as resources (I presume), you'd need to do something on the order of either adding a custom classloader or an extra functionality in the facelets resource locator itself. And I'd guess that you'd have to implement a custom Facelets tag to direct it.
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim
Thanks for posting the reply. Could you please elaborate what you meant "And I'd guess that you'd have to implement a custom Facelets tag to direct it."
Or do you have any idea how can we go about this?
Thanks
Sudharshan tettu
 
Tim Holloway
Saloon Keeper
Posts: 18302
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 2 reasons why a custom Facelets tag would probably be the way to go:

1. It would make a more abstract and programmer-friendly way of incorporating the function (which, among other things, lowers maintenance costs).

2. It would provide you a place to specific database specific qualifiers (parameters) on where and how to retrieve the content.

I would do this as a Facelets tag because I think you'll have to have binary-level feature access, which rules out Facelets components, and I'm pretty sure that a low-level JSF custom tag would be too low-level to be able to interact well with the View Definition Language compilation process.

Actual implementation of such a creature would require a lot of study. It's possible that there are some hooks in the APIs that would make this fairly easy, but unlike raw HTML, JSF makes direct 2-way logic references, which means that dynamic JSF would require a very flexible set of backing beans to refer to. So expect that a solution would likely take a lot of time and money and may well result in an app that's unusually expensive to keep maintained.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic