2

I have a PrimeFaces (2.2.1) Editor on a page where I want to allow the user to append text to the editor by selecting a value from a drop-down list and pressing a button indicating that they want it appended to the text. I can add the text to the editor using JavaScript like this:

document.getElementById('form:editor').value = document.getElementById('form:editor').value + 'NEW TEXT!';

However, unlike an inputTextarea, the PrimeFaces Editor component doesn't refresh automatically when its value is changed. I have to press the browser's reload button or hit the editor's Show Source button to get the appended text to display. Is there anything I can do from JavaScript to get the editor to refresh itself after changing its value?

2
  • 1
    Why don't you use an actionListener to update the text on the server-side? Commented Jan 12, 2012 at 5:44
  • Actually, simply pressing a commandButton will cause the value of the backing bean to be updated with the Editor's current value, and the button's action can then append the text. The problem with that technique is that whatever code the PrimeFaces Editor uses to refresh itself is faulty, as it ends up rendering a new copy of itself inside the text area of the original component, precluding the use of Ajax to handle this. The solution was to avoid Ajax and simply refresh the whole page after appending the text on the server side. Commented Jan 12, 2012 at 15:26

1 Answer 1

1

Not a good solution, but it should work.

editorWidgetVar.jqInput.var()

stores a value which would be submited on a form submit.

$(editorWidgetVar.jq.find('iframe')[0].contentDocument).find('body').html()

but this is actually visible for user element. So if you want to change content of editor, then you should change both fields (hidden for proper submitting and visible for proper display). I am almost sure there is a normal API for it. This method would be good for a temporary workaround.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.