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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:07:22+00:00 2026-06-01T09:07:22+00:00

Suppose i have JSF page <h:body> <h:form id=formID prependId=false> <h:outputText id=randomID value=#{randomNumber.random}/> <h:commandButton id=buttonID

  • 0

Suppose i have JSF page

 <h:body>       
    <h:form id="formID" prependId="false">      

        <h:outputText id="randomID" value="#{randomNumber.random}"/>      
        <h:commandButton id="buttonID" 
                         value="Random"
                         onclick="myArrayList(countries)" />   //just example  
    </h:form>
</h:body>

@ViewScoped
public class RandomNumber {

    private int totalCountries;
    private String data = "Afghanistan, Albania, Zimbabwe";
    private List<String> countries;

    public RandomNumber() {

        countries = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(data, ",");

        while(st.hasMoreTokens()) {
            countries.add(st.nextToken().trim());
        }
        totalCountries = countries.size();

    } //end of constructor

} //end of class RandomNumber 

.js file

function myArrayList(countries) {

    .....

}

See when user click on button then i want to call Jquery function whom i am passing my ArrayList. Is it possible to pass your current JSF variable with values to javascript or jQuery?

Thanks

EDIT
**_________________________________________________-*

<h:body>
    <h:form id="formID" prependId="false">

        <h:outputText id="countries" value="#{countries.countries}" style="display:none"/>
        <h:inputHidden id="hiddenCountries" value="#{countries.countries}" />

        <h:commandButton id="buttonID"
                         value="Random"
                         onclick="myArrayList()"/>

    </h:form>

</h:body>

@ViewScoped
public class Countries {

    private int totalCountries;
    private String data = "Afghanistan, Albania, Zimbabwe";
    private List<String> countries;

    /** Creates a new instance of Countries */
    public Countries() {

        countries = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(data, ",");

        while(st.hasMoreTokens()) {
            countries.add(st.nextToken().trim());
        }
        totalCountries = countries.size();

    } //end of constructor

    public List<String> getCountries() {
        return countries;
    }

    public void setCountries(List<String> countries) {
        this.countries = countries;
    }

} //end of class Countries

function myArrayList() {

    alert(jQuery('#countries').html());
    alert(jQuery('#hiddenCountries').val()) //when using h:inputHidden

} //end of function myArrayList
  • 1 1 Answer
  • 1 View
  • 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-01T09:07:24+00:00Added an answer on June 1, 2026 at 9:07 am

    You can do

    <h:inputHidden id="someID" value="#{randomNumber.data}/>
    

    (dont forget to added getter/setter to your data in the bean )

    change your onclick of the h:commandButton

    onclick="myArrayList()" // or onclick="myArrayList(#{SomeELExpressioGoesHere})"
    

    change your js function into

    function myArrayList(inputParam) {
        alert(jQuery('#someID').val());
        var yourJSString = jQuery('#someID').val();
        var myArray = yourJSString.split(','); //when string is Afghanistan,Albania,Zimbabwe (no spaces)
        alert(myArray[inputParam]);
    }
    

    in order to transfer your js string into array just use

    var yourJSString = jQuery('#someID').val()
    var myArray = yourJSString.split(','); //when string is Afghanistan,Albania,Zimbabwe (no spaces)
    

    you might be needed to change someID into other id selector if you wont set prependId=false in your form… or simply use a broaded jquery selector like

     alert(('input[id$="someID"]').val());
    

    EDIT

    Look at my example , you should work with your String data variable and not the countries , cause you should pass the data as string only and not as array… after you will pass the data variable to js you can manipulate it with simple slpit js function to make it back an array in your js… you are getting Conversion Error setting value ‘[Afghanistan, Albania, Zimbabwe]’ for ‘null cause you are trying to set String into array… probably the getter of countries converted implicitly the java array into string and when you try to submit it back (string into array) you getting the exception

    in order to set from js back to to bean :

    jQuery('#someID').val("Some new String goes here");
    

    then when you will submit the form.. the value will be set back to server

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

Sidebar

Related Questions

Suppose I have the following CSS rule in my page: body { font-family: Calibri,
Suppose I have the following HTML: <form id=myform> <input type='checkbox' name='foo[]'/> Check 1<br/> <input
I have a JSF file with a rather large form, the form consists of
Suppose I have a JSF bean with @PostConstruct method. I would like to know
i have an object that holds an imageIcon, in a jsf page this line
I have a JSF page (using MyFaces 2.0) that does a bit of data
Suppose that I have Spring service classes or JSF beans. I wire these classes
Suppose I have: public class foobar { public int lorem; public int ipsum; }
Suppose we have the following table data: ID parent stage submitted 1 1 1
Suppose I have an IEnumerable such as a List(TValue) and I want to keep

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.