Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of disabled check box in Spring MVC

I am working on Spring MVC application and I am having a problem of getting the value of the check box when it is disabled.

in report.jsp page :

<form:checkbox type="checkbox" path="corporateColumn" id="corporateColumn" value="true" checked="checked" disabled="true" />

in ReportForm.java :

boolean corporateColumn ;

public boolean isCorporateColumn() {
        return corporateColumn;
}

public void setCorporateColumn(boolean corporateColumn) {
        this.corporateColumn = corporateColumn;
}

In ReportController.java ;

boolean corporateColumn = reportDTO.isCorporateColumn(); // this evaluates to false
//Which expected as true when corporateColumn checkbox is checked

Everything works fine unless it is used as disabled="true" (/ disabled="${'true'}") for checkbox field.

I had the similar issue previously also when getting the value of a disabled textfield and overcome it by making the field readonly. So I am not sure in Spring MVC whether it is not possible to get the value of input field when it is disabled.

Any guidance would be really appreciated.

Thanks!

like image 896
ons1719133 Avatar asked Nov 23 '12 05:11

ons1719133


2 Answers

It's sorry to say that but that's impossible.

Use developer tool(like in Chrome) to check posted data, you can confirm browser will not send your checkbox's data if it's disabled or unchecked.

Why don't you simply use 'readonly' instead of 'disabled'?

like image 106
dgregory Avatar answered Sep 23 '22 05:09

dgregory


Disabled field data is not passed on to server.

like image 45
Akhil K Nambiar Avatar answered Sep 20 '22 05:09

Akhil K Nambiar