将值从Jquery函数传递到JSF ManagedBean [英] Passing Value from Jquery function to JSF ManagedBean
问题描述
我已经实现了与primefaces的datagrid的拖放.它运作良好. 然后我想获取可拖动对象的位置: 我通过以下方式将其包含在我的handleDrop jQuery函数中:
I have implemented the drag and drop with datagrid of primefaces. It works well. Then i wanted to get the position of the draggable object: i included that in my handleDrop jquery function, this way:
function handleDrop(event, ui) {
var droppedQuery = ui.draggable;
var p = ui.offset;
var myvalue = "thisvalue" + p.left;
$("#form1\\:position").val(myvalue); }
<p:inputText id="position" value="#{dragQueryMB.changevalue}" />
问题在于,每当我拖动对象时,都会显示并更新文本,但是dragQueryMB ManagedBean中的changevalue的值为alawys为空.
The problem is that the text is shown and updated everytime i drag the obrject, but the value of changevalue in the dragQueryMB ManagedBean is alawys is null.
谢谢,我在这里是进一步的解释
Thank you, i am here for further explanation
推荐答案
我发现了问题所在.
实际上,handleDrop是在放置事件时调用的.
myvalue的值传递给inputText,每次我调用handleDrop函数时都会更改,但是所有这些都是客户端.
因此,我不得不使调用handleDrop函数的事件处理一个请求,以便后备Bean响应并且其属性是最新的.所以我在这里将process =:form1"添加到与droppable元素相关的ajax行为
<p:droppable for="report" tolerance="touch" activeStyleClass="ui-state-highlight"
datasource="availablequeries" onDrop="handleDrop" dropListener="#{dragQueryMB.dropQuery()}" >
<p:ajax listener="#{dragQueryMB.dropQuery}" update="dropArea" process=":form1"/>
</p:droppable>
我希望我足够清楚
I have found what was the problem.
Actually, the handleDrop was called on drop event.
The value of myvalue was passed to the inputText, changes everyTime i call handleDrop function, but all these was client side.
So I have had to make the event calling the handleDrop function process a request so that the backing bean responds and its attributes are up to date. So i added here process=":form1" to the ajax behavior associated to the droppable element
<p:droppable for="report" tolerance="touch" activeStyleClass="ui-state-highlight"
datasource="availablequeries" onDrop="handleDrop" dropListener="#{dragQueryMB.dropQuery()}" >
<p:ajax listener="#{dragQueryMB.dropQuery}" update="dropArea" process=":form1"/>
</p:droppable>
I hope i was clear enough
这篇关于将值从Jquery函数传递到JSF ManagedBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!