views:

49

answers:

1

I want to pre populate check boxes on jsp. I have following code on my Mycheckbox.jsp

Code

MyDTO [] dtoArr = Context.getParameter("PREFdtoSettings");
<%=dtoArr.length%> is 6;

dtoArr[i].getId(); gives me the unique ID;

In above code am setting PREFdtoSettings parameter in request context in handler class

There are almost 100 checkboxes on the page as shown in the code

CheckBox No.1
`<input type=”checkbox” id=”dtoArr[i].getid()”> FXX </input>`

Similarly, I am having 100 checkbox which has unique id and that id information am getting by id=”dtoArr[i].getid()”.

Now, I want to pre populate the 6 checkboxes by matching dtoArr[i].getid() among 100 existing checkboxes on the pageload but I am not sure how I can achieve this.

I was going through some blogs and it suggested that I should create JSON Object of dtoArr and use my JSON in my javascript DOJO but I am not sure how can I implement it.

Any suggestions or input would be highly appreciated.

Thanks.

+1  A: 

The question is not 100% clear, but to prepopulate checkboxes on a JSP side, don't use a client-side method.

Set the value when rendering.

<input 
    type="checkbox" 
    id="${dtoArr[i].getid()}" 
    value="${dtoArr[i].getValue()}" 
    checked="${dtoArr[i].checked?'checked':''}"> 
  FXX </input>

This is, assuming that you're using an el factory that allows for method calls. Otherwise it's the same principle, but a bit uglier.

Joeri Hendrickx