This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Get JSF inputText Value to JavaScript?

 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to use JSF to pop up a window from the parent window. In the popup window, I have to pass the value that is entered in a <h:inputText> back to a text field in the parent window.

In order to make sure that I know the way to communicate between the parent window and the popup window, I have tried coding it in HTML. And I have done it successfully.

Then, I try to convert the HTML code to JSF. I have searched the internet and I have tried different specifications myself. I am stuck. This is the line that I have been struggling with:

If textField is in HTML parent window <input name=textField .... /> and the inputField is in HTML popup window <input name=inputField .... />, the JavaScript can recognize (No problem! the datum is passed.):

Now, the dataManagement is the "id" attribute in my JSF parent <h:form> tag. The externalFile is the "id" attribute in my JSF popup <h:form> tag.

The textField is in the JSF parent window as both the "id" attribute and a "property" name (i.e. value="#{dataManagementBean.textField}" )in the <h:inputText> tag.

The inputField is in the JSF popup window as both the "id" attribute and a "property" name (i.e. value="#{accessExternalFileBean.inputField}" ) in the <h:inputText> tag.

No matter how I experiment with different specifications, I cannot get the textField and inputField in the JavaScript. I got that "it is null or not an object" JavaScript error. Please advise if you have done it successfully.
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the IDs are as you outlined, this ought to work:



It seems possible that would give you a security or access denied error. If so, you can pass document.getElementById("externalFile:inputField").value into a function in the parent and set the value the same way there.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. Your code works. The datum is passed from the popup to the parent window now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic