• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting the Form elements

 
Don boscoo
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ALL,



I have this Check boxes in the JSP which am getting the values to the spring controller

String[] ruleIds = req.getParameterValues("selectedRuleIds");

Now, I can get only the ${subrule.rule_id} in the controller as the value given to the name of the input type check box is that, I want the SELECTED CHECKBOX ${subrule.rule_name} too in the controller, How do i get that?

Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to make it a form element, as only form element get submitted as part of the request.

You can put it in an element of type <input type="text"> with the readonly attribute. Or, you can create a "hidden" element with the value.
 
Don boscoo
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for you reply.

Yes, We can put it in an element of type <input type="text">, But how to get the selected check box value?
 
Don boscoo
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Now that, I've created the hidden element, How do get the selected check box ${subrule.rule_name}?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so you only want the names associated with checkboxes that are actually checked, correct? In that case, you'll probably need to get some JavaScript involved to disable and input elements that you don't want to send.

Another possibility is to gang up both the is and the name in the value of the checkbox using some delimiter that you use to split them on submission. But that's a tad dirty.
 
Don boscoo
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please provide me with some code on javascript?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest way to do this would be to register a submit handler on the form. It will get invoked during form submit, and you can iterate through all the elements and disable or enable the appropriate controls.

Do you have any JavaScript experience?

And, I highly recommend using jQuery for any kind of complex script of this nature. Life is just too short to write the reams of script that would be otherwise needed.
 
Don boscoo
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for your response. I dont have javascript experience. I heard JQuery makes life easy. I will have to look into that.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't have any JavaScript experience, I have two thoughts:

  • This is a good opportunity to get some. After all, if you are going to be working in the area of web applications, you are going to need to know JavaScript.


  • If this is something you need quickly, it might be better to implement using the "gang up in the value" approach which you can handle completely without any JavaScript.


  • You can choose whichever path makes the most sense for your situation.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!