tags:

views:

24

answers:

1

When the Apache My Faces JSF 1.2 Implementation renders an HTML page behind the scenes , is it even possible to set/code something which will display a pure HTML Table / DIV (NOT the jsf component ) conditionally. When I searched , I saw that , using h:panelGroup is a solution, but I haven't tried yet, posting here for any better methods or approaches.

Its almost like wanting to say - writing a javascript code in java and inject it when the HTML is rendered - is it possible?

Thanks,

+3  A: 

Several ways.

  1. Use <h:panelGroup layout="block">. It renders a HTML <div> element.

    <h:panelGroup layout="block" rendered="#{bean.condition}">
        content
    </h:panelGroup>
    
  2. Wrap the HTML <div> element inside a <h:panelGroup>. Without any client-side attribtues like id, styleClass, onclick, etc, the <h:panelGroup> won't render anything. With them it would however render a <span> element (or <div> if layout is set to block).

    <h:panelGroup rendered="#{bean.condition}">
        <div>content</div>
    </h:panelGroup>
    
  3. Wrap the HTML <div> element inside a <f:verbatim>.

    <f:verbatim rendered="#{bean.condition}">
        <div>content</div>
    </f:verbatim>
    

It's by the way not so special that MyFaces generates HTML. The Mojarra JSF implementation also does that. The competitors Struts2, Spring MVC, Wicket, Tapestry, etc..etc.. also. Microsoft ASP.NET MVC also. PHP also. All server side languages in fact. Simply because of the fact that the webbrowser doesn't understand them. It only understands HTML/CSS/JS ;)

As to mixing JavaScript with Java/JSP/JSF, you may find this article useful.

BalusC
+1 for the nice explanation of server side languages. I will try these approaches. Thanks.
gurupriyan.e