支持Bean无法获取javascript发送的值 [英] Backing Bean not getting values sent by javascript

查看:103
本文介绍了支持Bean无法获取javascript发送的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个下拉列表,其值通过以下JavaScript函数复制到<h:inputHidden>组件中:

I have three drop down lists whose values are been copied to <h:inputHidden> components by the following JavaScript function:

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;
}

以下是三个<h:inputHidden>组件:

<h:inputHidden value="#{signupBean.month}" id="monthField"/>
<h:inputHidden value="#{signupBean.day}" id="dayField"/>
<h:inputHidden value="#{signupBean.year}" id="yearField"/>

这是命令按钮,用于调用将值复制到输入,然后将其提交到后备bean的函数.

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.

<h:commandButton image="images/images/signup1.png" 
     styleClass="joinnow" 
     id="joinus" action="#{signupBean.save}"
     onclick="getBirthDate()" />

但是它们作为null到达后备bean.这是怎么引起的,我该如何解决?

But they arrive as null in the backing bean. How is this caused and how can I solve it?

当我尝试从JSF组件中选择元素时,jQuery冻结.元素的ID是否存在问题?

jQuery freezes when I try to select elements from JSF components. Is there a problem with the IDs of the elements?

下面是与HTTP请求一起发送的变量的屏幕快照,该屏幕快照证明了正确发送了这些值.那个豆怎么了?

below is a screenshot of the variables sent along with the HTTP request which proves that the values are properly been sent. What would be the problem with the bean?

推荐答案

您可以使用 alert 语句检查对象是否存在.例子

You can check the object is present or not by using alert statement. Example

function getBirthDate() {
var months = document.getElementById("months")
var hidden1 =  document.getElementById("formsignup:monthField");
alert(months);alert(months.value);
alert(hidden1);alert(hidden1.value);

如果Object值为null,则给出的获取该元素的ID是不正确的.请同时检查您从该对象获取的值.我认为这可能有帮助

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

这篇关于支持Bean无法获取javascript发送的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆