Add Ajax to created component/Ajax + dynamic component
brueslymuesh Jun 4, 2011 10:17 PMHi,
Actually two questions:
1.)
I have a bean that creates components and adds them to the view (this actually works fine). One item is a HtmlSelectOneMenu item. Is it possible to add ajax functionality to this component (like the a4j:ajax tag in the xhtml files)?
My guess is that I add an instance of the class: org.ajax4jsf.component.behavior.AjaxBehavior; but I can't get it to work. I have to add this instance via mycomponent.addClientBehavior(eventname, behaviour), right? Basically I'm trying to reproduce the functionality of: http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=ajax&skin=blueSky with dynamic components.
First I tried it without the aj4:ajax-Tag and I added an onchange="submit()" to the HtmlSelectOneMenu-Tag. This works great, but as soon as I add the h:head-Tag to my xhtml, the site gets reloaded with every change (and the event is not called), that is not what I'm looking for.
2.)
If I create components (rich:select) within a c:forEach loop, how can I reference to my created IDs for the elements?
<c:forEach var="value" items="#{uiMappingCreatorForEachBean.valueList}">
<h:panelGrid columns="3">
<h:column>
<rich:select id="#{uiMappingCreatorForEachBean.generateClassID}"
enableManualInput="true" defaultLabel="start typing for select"
valueChangeListener="#{uiMappingCreatorForEachBean.valueChanged}"
value="#{uiMappingCreatorForEachBean.currentClassValue}">
<f:selectItems value="#{uiMappingCreatorForEachBean.classList}" />
<a4j:ajax event="change" render="#{uiMappingCreatorForEachBean.generateFullPropertyID}" execute="this@" />
</rich:select>
</h:column>
<h:column>
<rich:select id="#{uiMappingCreatorForEachBean.generatePropertyID}"
enableManualInput="true" defaultLabel="start typing for select"
value="#{uiMappingCreatorForEachBean.currentClassValue}" >
<f:selectItems value="#{uiMappingCreatorForEachBean.propertyList}" />
</rich:select>
</h:column>
</h:panelGrid>
</c:forEach>
The listener works and I get the valueChanged-Event but the column doesn't get renderd. I thought maybe I got an ID wrong, but I called the function from the valueChanged function and I could retrieve the component (UISelect). So it seems that the Ajax-Request is not working for dynamically created IDs. Is this correct or did I miss something?
Thank you