wood burning stoves 2.0*
The moose likes JSF and the fly likes Dynamic rendering of html content on jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Dynamic rendering of html content on jsf" Watch "Dynamic rendering of html content on jsf" New topic
Author

Dynamic rendering of html content on jsf

sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 124
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

Joined: Oct 22, 2011
Posts: 21
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

Joined: Jul 17, 2006
Posts: 124
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

Joined: Oct 20, 2011
Posts: 6
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

Joined: Jul 17, 2006
Posts: 124
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

Joined: Jun 25, 2001
Posts: 15958
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 124
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

Joined: Jun 25, 2001
Posts: 15958
    
  19

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic rendering of html content on jsf
 
Similar Threads
JSF 2.0 Login
json object send to JSF backing bean to xhtml page
javax.el.PropertyNotFoundException
Issue with my webApp
Facelets and JSF