[英]Backing Bean not getting values sent by javascript
I have three drop down lists whose values are been copied to <h:inputHidden>
components by the following JavaScript function: 我有三个下拉列表,其值通过以下JavaScript函数复制到
<h:inputHidden>
组件:
function getBirthDate() {
var months = document.getElementById("months")
var hidden1 = document.getElementById("formsignup:monthField");
hidden1.value = months.options[months.selectedIndex].text;
var days = document.getElementById("days");
var hidden2 = document.getElementById("formsignup:dayField");
hidden2.value = days.options[days.selectedIndex].value;
var years = document.getElementById("years");
var hidden3 = document.getElementById("formsignup:yearField");
hidden3.value = years.options[years.selectedIndex].value;
}
Here are the three <h:inputHidden>
components: 这是三个
<h:inputHidden>
组件:
<h:inputHidden value="#{signupBean.month}" id="monthField"/>
<h:inputHidden value="#{signupBean.day}" id="dayField"/>
<h:inputHidden value="#{signupBean.year}" id="yearField"/>
This is the command button that is supposed to invoke the function that copies the values to the inputs and then submits them to the backing bean. 这是命令按钮,它应调用将值复制到输入,然后将其提交到支持Bean的函数。
<h:commandButton image="images/images/signup1.png"
styleClass="joinnow"
id="joinus" action="#{signupBean.save}"
onclick="getBirthDate()" />
But they arrive as null
in the backing bean. 但是它们作为
null
到达备用bean。 How is this caused and how can I solve it? 这是怎么引起的,我该如何解决?
Edit: jQuery freezes when I try to select elements from JSF components. 编辑:当我尝试从JSF组件中选择元素时,jQuery冻结。 Is there a problem with the IDs of the elements?
元素的ID是否有问题?
Edit: below is a screenshot of the variables sent along with the HTTP request which proves that the values are properly been sent. 编辑:下面是与HTTP请求一起发送的变量的屏幕快照,证明了正确发送了这些值。 What would be the problem with the bean?
那个豆怎么了?
您可以检查bean的范围以及在提交期间是否重新初始化它的范围吗。在那种情况下,无论值是从客户端发送的,隐藏字段都将获得其初始值。
You can check the object is present or not by using alert statement. 您可以使用Alert语句检查对象是否存在。 Example
例
function getBirthDate() {
var months = document.getElementById("months")
var hidden1 = document.getElementById("formsignup:monthField");
alert(months);alert(months.value);
alert(hidden1);alert(hidden1.value);
If the Object value is null the Id is you given to get the element is not proper.. also check the value you are getting from the object.. I think it may help 如果Object值为null,则给出的ID是不正确的..还检查您从该对象获得的值..我认为这可能会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.