<h:outputScript> target problem when using templates
Asked Answered
D

1

5

I have a question about integrating jquery library with JSF 2.0

when using <h:outputScript library="/common/js" name="jquery-1.5.1.min.js" target="head" /> , i should include <h:head> tag also in my xhtml file. so script is rendered at head.

but i have a template.xhtml that contains <h:head>,<h:body> parts. How can i make target="head" /> for my page that derives from this template ui:composition="template.xhtml" ?

target=form> didn't work either.

my template:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><h:outputText value="#{msg['label.titlemsg']}" /></title>
    <h:outputStylesheet library="css" name="style.css"  target="head"/>
</h:head>

<h:body>
<f:view locale="#{localeBean.locale}">

<div id="outer">

  <div id="container"> 
    <div id="inner"> 

      <div class="float">
        <div class="main"> 
          <!-- -->
          <div id="icerik"> 

              <ui:insert name="icerik">



      </ui:insert>
    </div></div></div></div></div></div>

     <div id="langbar" align="center">


    </div>

</f:view>
</h:body>
</html>

so i have "icerik".

in my file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.prime.com.tr/ui"  
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/Template.xhtml">

    <ui:define name="icerik">

    <h:outputScript library="/common/js" name="jquery-1.5.1.min.js"  target="head" />
<h:outputScript library="/common/js" name="jquery.validate.js" target="head" /> 


    </ui:define>

</ui:composition>
</html>
Disregard answered 10/5, 2011 at 18:55 Comment(9)
It should work that way. What happens instead? What do you see when you rightclick page in webbrowser and review the JSF-generated HTML output? Is the desired <script> there?Virulence
hi, i use template so target=head and target=body generates no output about .js files.Disregard
hi again, i updated my question with a bit of code.Disregard
Can you be more clear about what happens instead? Do you see nothing in the head of the generated HTML output? Even no <script type="text/javascript" src="RES_NOT_FOUND"> ?Virulence
yes, without using templates my .js files can be seen in head tag. using tamplates causes this problem for me. nothing shown in head part if ui:define is usedDisregard
mojarra-2.0.3-FCS\ jsf api and impl. may be a lib conflict?Disregard
similar problem here, (not only my mistake i think) the last comment: blogs.oracle.com/rlubke/entry/jsf_2_0_new_feature4Disregard
i solved my problem by adding <ui:insert name="icerikhead"></ui:insert> to template's head and then filling it in my form <ui:define name="icerikhead"> add js files </> thanks for your help. i dont know why previous solution didnt work.Disregard
I have the same issue with Mojarra 2.1.19. Only the solution below works, but it's nonsense to declare the js file in each of the template clients. What if I want to use one for the whole application?Untrimmed
D
7

I think a better way solved my problem : adding <ui:insert name="icerikhead"></ui:insert> to template's head part and then filling it in my form as <ui:define name="icerikhead"> add js files </ui:define>

Disregard answered 12/5, 2011 at 17:57 Comment(1)
4 years later, I was facing the same problem. The script tags were not rendered when using h:outputScript from within a facelets ui:composition. This facelet also uses a template and defines the content via some ui:define tags. Then I realized, I have to put the h:outputScript inside of one of these ui:define tags, not outside of them. Now it works like a charm.Whiteheaded

© 2022 - 2024 — McMap. All rights reserved.