Cannot access the value of the selected item of a disabled drop down, in action class (struts 2)

為{幸葍}努か 提交于 2019-12-23 03:09:47

问题


On a Jsp page I have some select elements which were disabled after a value was selected (Disabled them in javascript). Now when the form is submitted, I can not access those selected values in the action class.

I know for sure that this is caused by the select elements being disabled because, when I tried the same without making them disabled, it worked fine.

Now I don't understand why is this so. I thought maybe I should enable them before the form is submitted, but it does not seem a good idea.

I faced this problem while implementing this : Creating struts 2 forms dynamically on jsp using java script . (You can find the code there. Although I don't think you will need the code, because it is clear where the problem is.)

Here I am able to access the values of text fields but I can not access the values of select elements.

I asked this question separately because I thought this is a different topic.

Thanks!!


回答1:


You can set them in hidden field through java script and pass it to action




回答2:


Disabled fields by W3 specifications will not get posted on the server side so this issue is not related to the Struts2 but in generic an HTML way to go

Disabled controls

i am not sure why you want to use disabled control for your form.things can be done using readOnly attribute or use hidden fields



来源:https://stackoverflow.com/questions/8726237/cannot-access-the-value-of-the-selected-item-of-a-disabled-drop-down-in-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!