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

Custom Component in JSF  RSS feed

 
Narendran Nair
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello every one .. i am new to JSF and very new to JSF components ..

I want to know your suggestions in this ..

I have a set of Input field where a user enters all the details like first name, last name , social security number etc etc .. if a validation error happens . i need to highlight the component(intput field) .. how can this be done ... i want suggestion in this ..

regards
Narendran J S
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to do something like this and specify your own validator that later sets the Style

<h:inputText value="#{payment.card}" styleClass="#{payment.currentStyle}"

required="true" validator="#{payment.luhnCheck}"/>

Basically luhnCheck gets called, if valid nothing happens and card gets stored. Otherwise the currentStyle returns a string with the name of the style to use in error cells (or input fields)
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is another solution which might help others.

Create a listener with for render_response phase and also define the id's of the components ending with "_lbl" which you want to highlight.

and the add the following code in listener.




also add the reset method in which you can remove the style.

Thanks,
Rahul
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't going to work flawlessly in iterated components like UIData. The posted code at its own does also not make much sense at some places.

You may find this example more useful: http://balusc.blogspot.com/2007/12/set-focus-in-jsf.html
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks dude and definately i forgot to mention that this was for UIComponent but definately BalusC Code is universal but not sure if this will work with icefaces as id's in icefaces are changed dynamically on the page rendered.

Thanks,
Rahul
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That contradicts the JSF specification. So either IceFaces is bogus or your interpretation is wrong.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF IDs should only be dynamic if you don't explicitly set them using the "id=" attribute. However, the "true" ID may actually be a compound of the component's ID concatenated with the id's of containing components. Mostly this comes as an issue when you're referencing them via Javascript.

You might want to check out the new MyFaces Estension Validation package and see if that serves your needs (http://myfaces.apache.org/extensions/validator/).
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, the "true" ID may actually be a compound of the component's ID concatenated with the id's of containing components.


This is what exactly icefaces does. So I think we can use startswith to compare the id but that's not 100% full proof.

Thanks,
Rahul
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to insist that the ID´s are changed when the page is rendered. This is totally wrong.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!