how to generate a commandButton's id dynamically

UI Components for JSF
Post Reply
sdeandres
Posts: 1
Joined: 16 Apr 2013, 13:37

28 Oct 2013, 19:03

Hi!

I have a commandButton that execute an overlayPanel into a dataGrid, but I increment rows dynamically; that is the problem because I want than each commandButton execute an unique overlayPanel.

I have using the rowIndexVar param (of the dataGrid) to change the name of the commandButton and the value of 'for' into the overlayPanel, but is impossible, this value (rowIndexVar) return null or '0'.

Somebody knows how I set a dynamic ID to my commandButton???

THX!

Code: Select all

<p:dataGrid value="#{empresasBean.listActividades}" var="item" columns="1" id="dataGridCNAE" rowIndexVar="rowIndex"  > 
	 			
	<p:commandButton id="btn_#{rowIndex}" value="VALOR #{rowIndex}" >
		<f:attribute name="selectedCNAE" value="0#{rowIndex}"   />
	</p:commandButton>
		
		<p:overlayPanel dynamic="true" for="btn_#{rowIndex}" hideEffect="fade" 
			widgetVar="SANTI_lista" styleClass="comboOveAd" appendToBody="false"
			my="left top" at="left bottom" style="width:300px">
				<h:form>
				....
				....
[Using PF 4.0 - extensions 1.0.0]
Spain

rikup
Posts: 459
Joined: 29 Jan 2013, 14:27

28 Oct 2013, 22:23

If I remember correctly, you can't use id like this because of how id's are assigned. I don't have the links here, but if you Google for something like JSF ui:repeat dynamic id you should find stuff where this issue is discussed.
PrimeNG 2.0.0
Angular 2.4.5

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

28 Oct 2013, 23:13

rikup wrote:if you Google for something like JSF ui:repeat dynamic id you should find stuff where this issue is discussed.
searched google for

jsf balusc dynamic id

and found this below; I think this is the one that you are talking about. right?

Dynamically added input field in ui:repeat is not processed during form submit

and

JSF generating dynamic id for component
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

rikup
Posts: 459
Joined: 29 Jan 2013, 14:27

29 Oct 2013, 09:44

Actually it was this one, that I was looking for. Look for BalusC's answer right after the accepted answer, it explains how this will work. http://stackoverflow.com/questions/1071 ... repeat-tag
PrimeNG 2.0.0
Angular 2.4.5

Chara76
Posts: 1
Joined: 05 Feb 2019, 07:39

08 Feb 2019, 09:29

I have the same need. In my case, its to create an id for a commandLink that is repeated for each row of a dataTable (creating a link that works as a rowSelector). This link is in the first (left-most) column and not in others. The last column has a checkbox that precludes use of the standard rowSelector (which fires when the checkbox is clicked) MyPremierCreditCard.

Frankly, regardless of why I need/want to do this, it ought to work. The syntax used in the original posting is the same as what I used and certainly what one would expect. So, how come it doesn't work?
Last edited by Chara76 on 09 Feb 2019, 07:30, edited 1 time in total.

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

08 Feb 2019, 22:37

There is no need to 'generate' the id's in repeat like components (ui:repeat, h/p: datatable, p:datagrid etc...) since they already get that by default from JSF.

https://stackoverflow.com/questions/731 ... -component

See the showcase and 'inspect the different magnifying glasses. They e.g. have

Code: Select all

id="form:cars:6:j_idt700"

id="form:cars:7:j_idt700"

id="form:cars:8:j_idt700"
where the 6, 7, 8 is the index. It starts
See https://stackoverflow.com/questions/415 ... f-uirepeat

So since they already have it, you can easily use the rowIndexVar as already used in the for attribute to reference the **FULL** client id (or maybe that is even done automagically https://stackoverflow.com/questions/157 ... ynamically)

https://stackoverflow.com/questions/604 ... es#tab-top

but the 'datatable integration' way from https://www.primefaces.org/showcase/ui/ ... anel.xhtml might be a better solution

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 54 guests