Javascript / Jquery dont' work

Splash Forums PrettyFaces Users Javascript / Jquery dont' work

This topic contains 4 replies, has 4 voices, and was last updated by  rafaeltc 6 years, 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #17851

    lucasmurata
    Participant

    Hello everybody. I am from Brazil. First, I’d like to thanks the team of PrettyFaces and Lincon.

    I’m developing a project with JSF2, Primefaces, PrettyFaces and Hibernate.

    I have an archive containing Javascript Functions (Jquery) that I coded.

    In welcome page of site, Primefaces and my JS functions works together, and them works fine.

    the call to the JS files (in faces/index.xhtml) is so:

    <script type=”text/javascript” src=”js/jquery.js” />

    <script type=”text/javascript” src=”js/functions.js” />

    But in other pages that are in (faces/pages/somePage.xhtml) only work primefaces or JS funtions.

    For exemple. If I put the code:

    <script type=”text/javascript” src=”/MyApp/js/jquery.js” />

    <script type=”text/javascript” src=”/MyApp/js/functions.js” />

    JS functions work fine but Primefaces dont’t work…

    If I put the code:

    <script type=”text/javascript” src=”../js/jquery.js” />

    <script type=”text/javascript” src=”../js/functions.js” />

    Primefaces work fine and JS functions don’t work…

    I guess that my rules is wrong

    <rewrite trailingSlash=”ignore” toCase=”lowercase” />

    <rewrite match=”^((?!.*.w*).)*$” trailingSlash=”append” toCase=”lowercase” />

    Can somebody help me?

    Thank you.

    #20610

    Hey lucasmurata,

    here a few notes on your problem.

    1. It seems like you want to manually add jQuery to your page. I don’t think this is a good idea as PrimeFaces already includes jQuery. If your are using a different version of jQuery than PrimeFaces this may get a problem.

    2. I recommend to always use absolute URLs when loading CSS or Javascript. Use something like:

    <script type="text/javascript" src="#{request.contextPath}/js/jquery.js" />

    3. You should restrict your rewrite rules to match only desired pages. If you add a rewrite rules without or with a very general pattern all request (even resources loaded by PrimeFaces/JSF) will be rewritten. This may not be what you want as it may break PrimeFaces.

    I hope this helps

    Christian

    #20611

    I also recommend using the JSF2 h:outputScript and h:outputStylesheet tags instead of directly using the HTML, this will make sure that the correct URL is used no matter from which page or URL you use it.

    #20612

    lucasmurata
    Participant

    Hi Lincoln and Christian. Thank you for reply.

    I suspected it was conflict between my manually Jquery insertion and Primefaces JQuery insertion, but but it seems that this is not.

    I put <script type=”text/javascript” src=”#{request.contextPath}/js/jquery.js” />, still did not work.

    Strange thing is that in index.xhtml page, page that is outside folder /faces/pages, Primefaces and JQuery functions work together.

    Should I find help in Primefaces Forum?

    Thanks!

    #20613

    rafaeltc
    Participant

    Hey Lucas. You should do what Christian told you to. You cannot import jquery.js using primeFaces because it already does it for you.

    You can just use the jQuery functions you want with no problems, unless if you want to use a different version of jQuery. And that would be a problem.

    Also, when using jQuery plugins together with primeFaces, before calling the jQuery functions, you should do the following:

    1- use jQuery.noConflict();

    2- switch all the $ you have in your functions calls to “jQuery”

    Example:

    if you have the code $(‘#menu ul’).hide();

    you should do:

    jQuery.noConflict();

    jQuery(‘#menu ul’).hide();

    the noConflict needs to be called only once!

    This will avoid coflicts among the 2 libs functions.

    BTW, I am Brazilian too! o/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.