Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Struts 2 Checkbox checked / unchecked value as yes / no instead of true / false

 
Mitesh K Agrawal
Greenhorn
Posts: 5
Android Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using struts 2 framework. I have got checkbox which while saving , saves true / false if it is checked / uncheked.
Instead of true / false I want to change it to yes / no. I tried a lot, even googled but no luck.

Can anyone please tell me is there any configuration or setting where I can achieve my requirement.

Thanks in advance
 
jatan bhavsar
Ranch Hand
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mitesh,

If you are getting values true/False then why dont you put simple condition when value is true store yes and when false save no.

Regards
Jatan
 
Mitesh K Agrawal
Greenhorn
Posts: 5
Android Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats true I can do that if the checkbox used once or twice in my product. But what if it has been used more than 100 times, I can't go and put that condition everywhere.

Though It can be done but it is very time taking and tedious job. Thats why I am looking for such setting or configuration where changing in one or two places will effect in all places.

If at all no such configuration available , what you said is my last option
 
Mitesh K Agrawal
Greenhorn
Posts: 5
Android Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Waiting for the response guys
 
Nope Torres
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can set `fieldValue=` in `<s:checkbox />` to submit the value you want into you action. For example, you can set a simple function to define the value:

<s:checkbox .... fieldValue="myFunction()" />

function myFunction() {
if (this.checked = 'checked'){
return "yes";
} else {
return "no";
}
}

Read Mykong's Struts 2 Checkbox guide. Well explained.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic