Bookmark Topic Watch Topic
  • New Topic

JSF 1.2: nesting custom component in <h:inputText />

 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I don't know if this is possible before JSF2.0, but I got a requirement that basically says that I need to be able to add focus to a certain element on the page using a custom JSF 1.2 component.

Currently, I do this with a short jQuery method where you add a class called 'focus' to the inputText component you want focus on. This works perfectly, but I need to also foresee a nested component inside h:inputText to do this.

example:




I had thought about just putting an element with a certain class and using a jQuery selector to get its parent, but then I realized the html input tag does not allow subtags and that couldn't work, so I need something that won't be rendered but will do the job.

Any ideas?

Migrating is evidently not an option.
I'm using Seam 2.1.2 and richfaces 3.3.4
 
Greg Charles
Sheriff
Posts: 3010
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
Are you trying to mark a particular field to have the focus when the page loads? Normally that would be done with window.onload, or jQuery(document).ready(). You could even mark the field with a class like "defaultFocus", and then put the script in the template. That way the "defaultFocus" field on each page would automatically get the focus on page load.
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
HTML isn't the only thing that doesn't allow sub-elements for controls that are defined as self-contained. Neither does JSF. So you might as well drop that. You'd have to define an entirely new replacement for the h:inputText tag and that's a lot of trouble.

The idea of having a "ondisplay" jQuery event handler lookup a magic class (or ID) sounds like a much simpler solution. You can put that into a tile template and it would be pretty much auto-magic for all Views based on that template.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Report post to moderator
@Greg: that was exactly what I did. I add styleClass="focus" to a tag and execute the selector giving focus on JQuery's document ready. But my architect wanted the component as well.

@Tim: <h:outputLabel/>, <s:validate/>, etc... All possible inside <h:inputText />, I thought?
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Dieter Quickfend wrote:
@Tim: <h:outputLabel/>, <s:validate/>, etc... All possible inside <h:inputText />, I thought?


Ack! You are correct. JSF is building a component tree and certain sub-elements can modify selected parent nodes.

However, I don't think you can use the XML-based custom tag facility to do what you want and I always discourage people from attempting to create binary custom tags unless there is absolutely no alternative.

The magic class thing can be pretty well assured to keep working for a long, long time and can even be applied to non-JSF pages such as straight JSP and HTML, but anything that actually goes in and plays with internal objects in JSF is at serious risk for requiring expensive and tedious re-writes when newer versions of JSF are released. Just writing the thing the first time is likely to take a week or more, whereas the magic class thing is about 15 minutes and is clean enough that just about anyone can understand it and exploit with about 5 minutes of "training". AND it doesn't require adding additional build component(s) to every project that needs it.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!