• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

inputText, javascript

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I used h:inputText inside dataTable for the input field. When user clicks(focus) on the input field, I want to have the border changed.

<h:inputText id="field1" onfocus="checkFocus(???)"...>, how can I pass the input field id to checkMouse(??)? I viewed the page source, h:inputText becomes sth. like <input id="form1:table1:0:field1" type="text" name="form1:table1:0:field1" ...(Note "0" in table1:0:field1 dynamically change depends on number of rows, for example, if there are 3 rows in the dataTable, it could be table1:0:field1,table1:1:field1,table1:2:field1)
That means in my jsp, I should use onfocus="checkFocus(form1:table1:?:field1)". But how can I dynamically pass that arg to checkMouse() in JSF?


function checkFocus(fieldId) {
if (check) document.getElementById(fieldId).style.borderColor="#E00000";
else document.getElementById(fieldId).style.borderColor="";
}

Thanks,
Sarina
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a similar setup (with ADF Faces but it should work the same without)...I use something like this:

Within the dataTable :

<af:column>
<f:facet header....
...(more code)...
</f:facet>
<h:inputText id="blah" onchange="javaScriptFunction(this.form,this);"
...(more code)...
/>

In the javascript function:

javaScriptFunction(form,component) {
//This will obtain the id of the textfield
var compid = component.getAttribute("id");
//This will obtain the value of the text
var fieldValue = form[compid].value;
...(more code)...


Hope this helps!

Josh Juneau
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the script

Eric
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This will be moved to JS forum I hope!
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sarina Smith:
But how can I dynamically pass that arg to checkMouse() in JSF?



DataTable has a seperate renderer you may extend and customize the renderer as per your needs.
 
Sarina Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I tried:
javaScriptFunction(form,component) {
//This will obtain the id of the textfield
var compid = component.getAttribute("id");
//This will obtain the value of the text
var fieldValue = form[compid].value;

It WORKS!
I haven't got time to try other solutions other guys provided here.

Thanks a lot, Guys!
Best Regards,

Sarina
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic