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 8739705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:59:22+00:00 2026-06-13T10:59:22+00:00

I would like to read the backing bean value in JSF and then pass

  • 0

I would like to read the backing bean value in JSF and then pass over to JavaScript, may I know how this can be done?

Backing bean sample code:

@ManagedBean(name="enquiry")
@SessionScoped
public class Enquiry {

  public boolean noQuery;

  /** getter and setter **/
}

In XHTML sample code, I would like pass the backing bean value and then pass into showNoQueryPrompt() like this:

<h:commandLink onClick="showNoQueryPrompt(#{enquiry.noQuery})">
</h:commandLink>

And then in JavaScript code, I can read the boolean value to determine whether I should prompt or not prompt. Here is the code:

<script ...>
   var showNoQueryPrompt(Boolean showPrompt) {

     if( showPrompt == "true" ) {
        alert('No query');
     }
   }
</script>
  • 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-13T10:59:23+00:00Added an answer on June 13, 2026 at 10:59 am

    To the point, you need to understand that JSF merely produces HTML code and that JS is part of HTML. So all you need to do is to write JSF/EL code accordingly that it produces valid HTML/JS code. Indeed, using EL to inline bean properties in the generated JavaScript code like as in your attempt is one of the right ways.

    Assuming that this is indeed the real code, you however made some syntax mistakes. The onClick attribute is invalid. It must be in all lowercase. Otherwise JSF simply won’t render the attribute at all.

    <h:commandLink value="link" onclick="showNoQueryPrompt(#{enquiry.noQuery})" />
    

    JavaScript has no notion of strong typing. The Boolean type in function argument is invalid. Remove it. Otherwise you will face a nice JS syntax error (in browser’s JS console).

    function showNoQueryPrompt(showPrompt) {
       if (showPrompt) {
          alert('No query');
       }
    }
    

    Note that I expect that you understand that this runs before commandlink’s own action is been invoked (you should now have understood; JSF generates HTML; rightclick page in browser and View Source to see it yourself). But you didn’t cover that in your concrete question (even more, you didn’t describe the concrete problem with the given code in the question at all), so I can’t give an detailed answer on that.

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

Sidebar

Related Questions

I would like to read multiple XML files in an array and then parse
I would like to read a file which has several lines, and then search
I would like to read MANIFEST.MF of my WAR application. How can I find
I would like to read value in the registry using C#, if the values
I would like to read geographic data (logitude/latitude) from two sources into one Javascript
I would like to read a file like this 1.23213213 0.12321321 -1.12321321 0.23232322 into
I would like to read the deleted statuses on twitter since i can already
I would like to read a pptx file in javascript, so I would like
I would like to read asynchronously from stdin with Qt. I don't want to
I would like to read Rails documentation locally though gem server. I go to

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.