views:

29

answers:

1

I got the checkbox working, but I can't remember what modification I have done to my code. it's never working again. it keeps saying:

org.springframework.web.servlet.tags.form.Checkbox Tag - 
java.lang.NullPointerException
at org.springframework.web.servlet.tags.form.Selected ValueComparator.exhaustiveCompare(SelectedValueCom parator.java:157)

the java looks like this:

public class ServiceRequest implements Serializable {
 ......
    private GenericAddress serviceAddress;
    private String problemDescription;
    private String referenceNumber;   
    private String[] optionExchangeList = new String[10];
        ......

the jsp code looks like this:

<INPUT TYPE="checkbox" NAME="addPrima" onclick="showHideDiv(this,'exchangeOfOption')">
   <spring:message code="serviceRequest.label.ExchangeOfOption"/><br />
   <div id="exchangeOfOption" style="display:none; margin-left : 15px;" >
    <spring:message code="serviceRequest.label.OnsiteExchangeOfDevice"/> <form:checkbox path="serviceRequest.optionExchangeList" value="Duplex"/><br />
                <spring:message code="serviceRequest.label.Drawer"/> <form:checkbox path="serviceRequest.optionExchangeList" value="Drawer"/><br />
                <spring:message code="serviceRequest.label.Feeder"/> <form:checkbox path="serviceRequest.optionExchangeList" value="Feeder"/><br />
                <spring:message code="serviceRequest.label.MaintenanceKit"/> <form:checkbox path="serviceRequest.optionExchangeList" value="Maintenance Kit"/><br />
                <spring:message code="serviceRequest.label.Other"/> <form:checkbox path="serviceRequest.optionExchangeList" value="Other"/>
            </div>  

it worked before. I even use optionExchangeList.toString() to look at the result. it was the names for the one I checked. (it's impossible huh? should be something like @afaswe) . and for now. I have to initialize the optionExchangeList as something like:

private String[] optionExchangeList = new String[]{"Duplex","Drawer"};

and for Duplex and Drawer, they stayed checked in the browser. but for the rest field. they stayed unchecked, and even if I check them, they don't appear in the optionExchangeList if I print them out in the action method using something like:

for (String s:serviceRequest.optionExchangeList){
 System.out.println(s+"\n");
}

the list stayed the same regardless the Checkbox status.

Did I just have a dream??? or did I meet a ghost??? I am going crazy. HELP!!!!

A: 

when I about to use another approach, the light shed on me. to keep it short and clear. define your String list with something like

private String[] optionExchangeList = new String[]{};

no more Exception. it just works.

Alex Zhou