Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Checkbox validation

 
Richard Ellison
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a requirement where a JSP will be populated by rows in a Java Bean.Now each row has a checkbox.The checkbox is
grayed out based on a value of one of the properties in the bean.Now earlier I used to write a simple loop to check the value of
the property in the Jsp itself.Instead of writing this piece of code in the JSP how do I write in the Java class itself.I believe
that the JSP should have only tags with no explicit loops.Please correct me if I am wrong.

Thanks
Richard
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65545
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, I'm not sure exactly where you are headed, but wherever it is doesn't sound right. Perhaps you can elaborate?

Are you perhaps alluding to replacing scriptlets with JSTL?
 
Richard Ellison
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Bear.What I meant to ask was is it okay to have an if-else loop in the JSP to check for the value of
a flag.Based on the value of this flag,checkboxes will be grayed out.My thinking is that as a principle the JSP should only have
code in the form of Tags.No explicit Java loops are allowed.Maybe I am wrong.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65545
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct in that modern JSP pages should have no Java code within them. That however, does not discount the possibility of conditionals and loops which are available in tag form via the JSTL (JSP Standard Tag Library).
 
Richard Ellison
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear.
 
gp krish
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using struts, this shouldn't be an issue. You can do this without java code. But still in a non-struts JSP you can achieve this with a very minimal of java code.

<input type=checkbox .... disable = <%=formBean.getCheckboxDisableProperty()%>

your formBean.getCheckboxDisableProperty() should return TRUE or FALSE.

Hope this helps.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65545
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gp krish wrote:If you are using struts

This is not the Struts forum. Please do not assume that Struts is being used when posting in this forum.

<input type=checkbox .... disable = <%=formBean.getCheckboxDisableProperty()%>

That code uses Java scriptlets. That code is outdated by about 7 years!

Modern JSP pages should use no Java code at all. Rather, the JSTL and EL should be used.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!