0

I'm learning jsf, using PrimeFaces. I have an array of integers in a Bean that I would write as a var in javascript. The bean:

@ManagedBean
public class ChartJS  {

    private LinkedList <Integer> datos = new LinkedList();

I want to pass the var datos to an integer array in javascript. I succeeded declaring a String variable and transform it into the javascript, but I guess that is not the right way to do it.

In bean

private String datosS;
....
for (Integer i : datos ){
    datosS+= String.ValueOf(i) + " ";

}

In view.xhtml

var intArray = '#{chartJS.datosS}'.split(" ").map(Number).filter(Boolean);
...

I would like to know is how to create a javascript var. Like this

In view.xhtml

var data = {

 datasets: [

    //Iterator itr = #{chartJS.datos}.iterator();
    //while(itr.hasNext()) {
        //Integer i = (Integer) itr.next();
             {
                name: "data num " + i,
                data: i             
             }
        //if (itr.hasNext()){
            ,
        //} 
    //}

    ]};

Sorry for my English. thanks

1 Answer 1

1

should work like this, and you wouldn't need String datosS:

var data = {

    datasets: [
        <ui:repeat value="#{chartJS.datos}" var="currentInt">
            {
                name: "data num " + #{currentInt},
                data: #{currentInt}
            }
            ,
        </ui:repeat>
        null
    ]
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.