0

I have a form:

public class ActionLogForm extends ActionForm {
    private Long ContractId;
    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long ContractId) {
        this.contractId= contractId;
    }
}

and in JSP, I have:

<html:hidden property="contractId" styleId="contractId" value="" />

Why actionLogForm.getContractId() in my dao have 0L? How can I change default with this to null?

1
  • 1
    Does your actual code have a method named getcontractId or is it getContractId? Commented Apr 26, 2011 at 13:35

1 Answer 1

2

Struts ActionForm and DynaActionForm documentations clearly specifies.

If you do not supply an initial attribute, numbers will be initialized to 0 and objects to null.

I know you're using a Long but (even since before Autoboxing) the following data types are "boxed".

  • Integer/int
  • Double/double
  • Long/long
  • Float/float
  • Boolean/boolean
  • Short/short

When Struts sees an Number object subtype, instead of its primitive type, it autoboxes it for you, hence why you have a default value of 0. It has its own implementation of the primitive/object type conversion (in BeanUtils). The reason for it, is for backward compatibility with the older Struts 1 versions (which ran on JDK 1.4 and JDK 1.3).

I hope this helps.

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.