开发者

How to pre-populate check box on jsp

开发者 https://www.devze.com 2023-01-21 04:35 出处:网络
I want to pre populate check boxes on jsp. I have following code on my Mycheckbox.jsp Code MyDTO [] dtoArr = Context.getParameter(\"PREFdtoSettings\");

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 <开发者_JAVA百科/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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消