h:outputLabel and PrimeFaces components

UI Components for JSF
User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

17 Mar 2010, 23:17

Hello,

h:outputLabel with "for" attribute renders a HTML label with "for". If user click on the label the corresponding component - input, checkbox, radio button, etc. gets focus or gets selected.

If we use PrimeFaces components like p:calendar, p:spinner, p:autoComplete, ... the rendered markup has following structure (using example of calendar):

Code: Select all

JSF
<h:outputLabel for="calendarID" value="..."/>
<p:calendar id="calendarID" .../>

HTML
<div id="calendarID" ...>
   <input id="calendarID_input" ...>
   <img .../>
</div>
The label ID points now to the div element and not to the input element which has an ID specified by renderer. A click on label has no effect. Not expected behavior in my opinion. If we write

Code: Select all

<h:outputLabel for="calendarID_input" value="..."/>
<p:calendar id="calendarID" .../>
renderer kit says "no component found for calendarID_input". Sure, there isn't such component.

The question is now would be not better to create UIInput, populate with data, add to the tree and let it render? The second better solution would be to render

Code: Select all

<div id="calendarID_container" ...>
   <input id="calendarID" ...>
   <img .../>
</div>
Input field should get the defined ID so that label works fine together with component specified in "for". At the moment using of outputLabel with some PrimeFaces components doesn't make sense.

What do you think?
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

jfrank
Posts: 3
Joined: 04 Aug 2011, 15:59

04 Aug 2011, 18:46

Did you ever come up with a solution to this?

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

04 Aug 2011, 22:25

No, no solution until now. I don't use h:outputLabel with "problematic" PF components. I write simple h:outputText.

By the way, we had a similar problem with p:focus, but it was fixed by selector adjustment (first editable field). I guess, we need a new component p:outputLabel with an JavaScript based solution or PrimeFaces should do "problematic" components fit for h:outputLabel.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cfr
Posts: 15
Joined: 11 Jan 2012, 12:27

27 Jan 2012, 16:10

The problem still exists. Even the new components like p:selectBooleanCheckbox have a structure where the id of the input field is different to the primefaces component id. Is there a work around to select a chechbox with a click on the h:outputLabel? I would like to have a p:outputLabel component too.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

27 Jan 2012, 17:49

IMHO it's not a good idea to write p:outpuLabel with JavaScript. Heavy JS app for a lot of simple things is not good.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

djmj
Posts: 400
Joined: 16 Dec 2011, 01:23

27 Jan 2012, 20:57

related to this post: viewtopic.php?f=3&t=17389&p=53294#p53294

I filed an issue for it which was marked as WontFix!

This is really a bad design issue since you can't know which element uses "_input", especially if you want to use javascript to access the input element. Now I always need to check the final html which component uses it and which not.
Primefaces: 11.0.0 RC2
Primefaces-Extension: 11.0.0
PrimeFaces-Mobile: 11.0
OmniFaces: 3.11
Jsf: Mojarra 2.3.8
Server: Glassfish 5.1.0

cfr
Posts: 15
Joined: 11 Jan 2012, 12:27

07 Mar 2012, 17:03

If someone else does not know how to combine the outputlabel with the checkbox, check out the following solution by using the widgetVar attribute of the checkbox.

Code: Select all

<p:selectBooleanCheckbox id="checkbox_id"
                                                immediate="true"
                                                value="#{myBean.parameter[myBean.const['MY_PARAMETER']].value}"
                                                widgetVar="checkbox_id">
</p:selectBooleanCheckbox>
<h:outputLabel onclick="checkbox_id.toggle()" for="checkbox_id"/>

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

18 May 2012, 09:55

Writing a p:outputLabel now to support advanced components like autocomplete, spinner and so on. No js included.

martinbudden
Posts: 17
Joined: 29 Apr 2013, 00:59

13 Feb 2014, 01:43

cfr wrote:If someone else does not know how to combine the outputlabel with the checkbox, check out the following solution by using the widgetVar attribute of the checkbox.

Code: Select all

<p:selectBooleanCheckbox id="checkbox_id"
                                                immediate="true"
                                                value="#{myBean.parameter[myBean.const['MY_PARAMETER']].value}"
                                                widgetVar="checkbox_id">
</p:selectBooleanCheckbox>
<h:outputLabel onclick="checkbox_id.toggle()" for="checkbox_id"/>
Sorry but this doesn't work either. Does anyone know a solution which does work?
I'm using PrimeFaces 3.5 with MyFaces 2.0.14 built by Maven 4.0.0 on WebSphere Platform 8.0.0.3

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

13 Feb 2014, 13:14

Please create a new topic

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 18 guests