Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:44:00+00:00 2026-06-18T09:44:00+00:00

I would like to know how I can pass JSF managed bean properties to

  • 0

I would like to know how I can pass JSF managed bean properties to a JavaScript function.

Something like this:

<script>
  function actualizaMenu(key){
    #{linkedMenu.setKey(key)}
  }
</script>
<ul>
  <ui:repeat value="#{moduleList.modulos}" var="entity">
    <li>
      <a onclick="actualizaMenu(#{entity.key})">#{entity.nombre}</a>
    </li>
  </ui:repeat>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:44:01+00:00Added an answer on June 18, 2026 at 9:44 am

    This is not exactly “passing” of JSF variables. This is just printing JSF variables as if they are JavaScript variables/values. You know, JSF and JS do not run in sync at all. JSF runs in webserver and produces HTML/CSS/JS code which in turn runs in webbrowser once arrived over there.

    Your concrete problem is most likely caused because you wrote JSF code in such way that it generates invalid JS syntax. An easy way to verify that is by just checking the JSF-generated HTML output which you can find by rightclick, View Source in browser, and by checking if you don’t see any syntax error reports in the JS console in browser which you can find by pressing F12 in Chrome/IE9+/Firefox23+.

    Imagine that #{entity.key} here

    <a onclick="actualizaMenu(#{entity.key})">#{entity.nombre}</a>
    

    prints a Java string variable like "foo", then the generated HTML would look like

    <a onclick="actualizaMenu(foo)">some name</a>
    

    But hey, look, that represents a JavaScript variable named foo, not a JS string value! So if you actually want to ultimately end up as

    <a onclick="actualizaMenu('foo')">some name</a>
    

    then you should instruct JSF to generate exactly that HTML:

    <a onclick="actualizaMenu('#{entity.key}')">#{entity.nombre}</a>
    

    Beware of special characters in the JSF variable though. You can use OmniFaces of:escapeJS() function for that.


    Unrelated to the concrete problem, the concrete implementation of actualizaMenu() makes no sense. You seem to be attempting to set a bean property. You should not use JS for that, but a <h:commandLink> instead.

    <h:commandLink value="#{entity.nombre}" action="#{linkedMenu.setKey(entity.key)}" />
    

    Nest if necessary a <f:ajax> to make it asynchronous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how i can pass a pointer to a function
I would like to know how can I pass a ruby variable inside an
I would like to know how I can do a low-pass filter in opencv
I would like to read the backing bean value in JSF and then pass
I would like to know how can I pass pointer to an array in
I would like to know how I can pass url as parameter of an
I would like to know if we can pass a database table as http
I would like to know if instead of void function in thread, I can
Hi I would like to know as to how I can pass an array
I would like to know how I can achieve this using the CActiveRecord in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.