Pain points in the HTML input Raido radio button

Source: Internet
Author: User

Background: Recently I need to write a form, that is, the simplest Java Web crud, but it took me two days to get a radio. Well, I admit it was my own mistake, so I will mark it here.

One of the bean classes has more than 80 fields, and the other 70 fields are Boolean. So I thought of using radio to write a radio. By default, all the fields are selected as false and then copied, paste, rename, it took nearly two hours to complete, and then test.

Open the page in the browser and select two groups of Radio. Because I select "false" by default, When I select "true", the "false" option is selected, but it does not disappear, I suspect that the name was not changed when I copied it.CodeThe check may be due to the long time spent in the dense radio. The mind is not clear, and there are more than 70 fields, 100 or 200 rows, one by one, I did not find out if I wrote the wrong name (it turns out that I wrote the wrong name ),

No error is found. I want to use js to solve this problem and let JS solve it. js will bind events to an object, but I will not traverse and bind multiple identical objects, then I asked in the Group. As a result, we all said that radio was originally based on groups and wrote examples for me. So I sent the code to the group, some of my friends found out that this problem was caused by different names. I found another article seriously. It took nearly two hours to solve the problem. The data has not been sent to the background.

Because the form is too large, I borrowed struts2 to encapsulate objects. Because there are too many fields and the default values are added, I did not manually modify some data and directly submit the data. The results can be saved to the database, in this case, no other tests are performed, so that they can be used normally.

The next day is an update. After more than half an hour of effort, you can use ajax to query data and dynamically generate forms.

However, I found that no matter how I select radio and the result is uploaded to the background, it is false. I began to wonder if I added the default value: checked on the false option, so today I want to use js to manually change the value of Radio checked again. tm, I wrote it myself (I'm glad)

The happy result is that there is no result, and the value sent to the background is still false. Oh, God ....

This time I began to suspect that struts2 could not convert the value of radio, So I went online to find information and confirmed my thoughts. I found that the radio value transmitted by struts2 is an array, write a conversion of global struts2. This is the final time.

Technical Summary:

1. html <input type = "radio"/> as long as the name is the same, it will automatically be a group. Only one of them will be selected and no more will be selected, if one of them is added with checked = "checked" by default, multiple names are not selected at the same time. If multiple names are selected at the same time, check carefully.

2. Struts's radio value transfer problem: If it is Radio, which corresponds to boolean, I come to the conclusion that I need to write the converter myself. For the code writing of the converter, refer to a buddy in the garden. Write a global converter directly: http://www.cnblogs.com/linjiqin/archive/2011/03/16/1986565.html

Experience summary:

First, write the minimum functional module, connect the entire process, and then perform a variety of possible tests. When all the tests are passed, complete other modules with the same task, in this way, when there are few codes, it is easy to troubleshoot errors accurately. The above is because the code is too much to write, and then we test the problem. Even if we guess the cause of the problem, I couldn't find the problem, and finally suspected that HTML itself was not supported.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.