admin管理员组文章数量:1355604
My requirement is when the user clicks the submit button, a new value calculated should be stored in the inputHidden field value. I have written function in jQuery to calculate the new value for the inputHidden field, when submit button is clicked. The new value is assigned to the inputHidden field value. But the problem is that while retrieving the value in the backing bean using hidden.getValue(), it returns null value.
jQuery code:
function hidden(){
var valueCalculated = '3';
$('#hidden').val(valueCalculated);
alert($('#hidden').val()); //displays 3 when submit button is clicked.
}
JSF code:
<h:inputHidden binding="#{bean.hidden}"/>
In the backing bean, I have getters and setters for hidden of type HTMLInputHidden, and I retrieve the hidden value by using getValue(). This should return the valueCalculated but it returns null. What is the way to obtain the calculated value in the backing bean.
My requirement is when the user clicks the submit button, a new value calculated should be stored in the inputHidden field value. I have written function in jQuery to calculate the new value for the inputHidden field, when submit button is clicked. The new value is assigned to the inputHidden field value. But the problem is that while retrieving the value in the backing bean using hidden.getValue(), it returns null value.
jQuery code:
function hidden(){
var valueCalculated = '3';
$('#hidden').val(valueCalculated);
alert($('#hidden').val()); //displays 3 when submit button is clicked.
}
JSF code:
<h:inputHidden binding="#{bean.hidden}"/>
In the backing bean, I have getters and setters for hidden of type HTMLInputHidden, and I retrieve the hidden value by using getValue(). This should return the valueCalculated but it returns null. What is the way to obtain the calculated value in the backing bean.
Share Improve this question asked May 6, 2011 at 1:54 user679526user679526 8454 gold badges16 silver badges40 bronze badges1 Answer
Reset to default 7The HtmlInputHidden#getValue()
will only return the submitted value when you're inside the invoke action phase. It's namely been set during the update model values phase. So if you're trying to get it during bean's construction or during other JSF phase before invoke action phase, you will get null
.
To fix this, rewrite the code logic so that it is been accessed at the right moment; in the mand button/link action method. Otherwise you have to get it manually from the request parameter map instead.
E.g.
<h:form id="form">
<h:inputHidden id="hidden" value="#{bean.hidden}" />
<h:mandButton value="submit" action="#{bean.submit}" onclick="$('#form\\:hidden').val('foo')" />
</h:form>
with
public void submit() {
// Here, in the bean's action method, it should already be set.
System.out.println(hidden); // "foo"
}
本文标签:
版权声明:本文标题:jsf 2 - How to obtain the value of h:inputHidden element whose value is calculated using jquery javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743997998a2573343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论