0

I am trying to update an UI text field in primefaces 6.2 using java script method. Though I am able to update the value from UI side, it is not reflecting in backing managed bean

Xhtml:

<h:inputHidden id="test" value="#{mybean.fieldname}" valueChangeListener="#            
{mybean.method}">
    <f:ajax/>
</h:inputHidden>

Javascript:

function update(){
    document.getElementByID('form:test').value="change";
    alert(document.getElementByID('form:test').value);
}

I expect my value changehandler to get called since I updated my value but nothing occurs.can some one pls tell where I am getting wrong

Edit :Actually I am trying to submit the value changed from UI side alone using Js to the actual bean value, basically dom alone is changed and kind of trying to submit the same using any ajax calls. but still it is not working. Refered this link:When to use valueChangeListener or f:ajax listener? Can some one pls give some insights on how this can be achieved?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
user3729090
  • 25
  • 1
  • 8
  • 1
    Changing the value client-side does not make it submit the value... And there is nothing PrimeFaces in here... – Kukeltje Jan 31 '19 at 09:56
  • And some basic searching like https://www.google.com/search?client=firefox-b-ab&q=jsf+change+value+from+javascript+site%3Astackoverflow.com results in many hits that might help... – Kukeltje Jan 31 '19 at 09:57
  • Possible duplicate of [When to use valueChangeListener or f:ajax listener?](https://stackoverflow.com/questions/11879138/when-to-use-valuechangelistener-or-fajax-listener) – Jasper de Vries Jan 31 '19 at 09:57
  • Hi , thanks all for the inputs. I actually tried out https://stackoverflow.com/questions/11879138/when-to-use-valuechangelistener-or-fajax-listener this. But that does not work though :( – user3729090 Jan 31 '19 at 10:40
  • There are lots of things in there, **what** did you try? What was the result? 'Did not work' is to vage and to little info to help with. [mcve] please! – Kukeltje Jan 31 '19 at 10:43
  • I just added a f:ajax code as mentioned in Baluc's answer. as it has been specified that a change in the dom will be submitted automatically which is what i actually want. Just now updated the code. pls help – user3729090 Jan 31 '19 at 10:45
  • Please debug as a developer... is the value send to the server in an http request at all? Is the setter called? What if you add a listener to ajax? Is that called? – Kukeltje Jan 31 '19 at 10:48
  • By the way.. this all smells like a XY problem. Shouldn't you just use a remoteCommand with parameters? – Jasper de Vries Jan 31 '19 at 10:49
  • Thanks for the reply @Kukeltje I tried debugging it by adding listener and also the setters are not at all called. – user3729090 Jan 31 '19 at 11:12
  • Thanks for the reply @JasperdeVries I am not aware of this. I will explore this and try. Thanks for the inputs – user3729090 Jan 31 '19 at 11:13

1 Answers1

0

You have to trigger explicitly a change event by JavaScript if you set a value by JavaScript.

Toru
  • 905
  • 1
  • 9
  • 28