Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enable/Disable one inputmask out of two in PrimeFaces  RSS feed

 
Dhiraj Nangare
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing one form in jsf/primefaces. I have two inputText(inputMask) for e.g moble number and telephone number. I want to restrict the user to put only one of these two fields . That means if user starts putting value in mobile no. then telephone no. field should be disabled and if user starts putting value in telephone no. then mobile no. field should be disabled.

Please tell me how should I do this.
 
Tim Cooke
Marshal
Posts: 3632
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, welcome to the Ranch!

I've edited the title of your post, using all capitals gives the impression you're shouting so please KeepItDown (<- read this article)

You'll get the most help here if you ShowSomeEffort first. We are NotACodeMill so nobody is going to do it for you. So, show us what you've tried so far and tell us what particular thing you're having trouble with. Something along the lines of "I thought doing this thing here would work but it didn't. I expected this to happen but instead that happened" would be a good place to start.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To actually disable a mutually-exclusive field in real time (when you are typing into the form) is something that you'd have to use Javascript for.

There are some things you'll have to take into account when doing this with JSF, however:

1. The actual field IDs that Javascript needs are the low-level element IDs, not the JSF high-level (template) IDs. So, instead of "homePhone" and "cellPhone", you'd have to code the Javascript to work with something like "myForm:homePhone" and "myForm:cellPhone". The exact names are determined by the IDs you give the naming containers (such as h:form), or will be randomly generated if you don't supply an id for the naming container (and it won't be predicatable, so give an explict id!)

2. Certain characteristics are set by JSF in ways that are not javascript-friendly, and the "disabled" attribute is one of them, so instead of declaring "disabled=true" on the View template, keep both fields enabled on the template and let the javascript handle the enable/disable.

You can attempt to use ajax instead of Javascript, but it would probably be trickier to do for stuff like this, and almost certainly less responsive. I prefer AJAX normally, because it's simpler, but perhaps not for this case.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!