I have a Datatable that begins to work well.
Code: Select all
<p:dataTable id="listeDesAssociations" var="a" value="#{vivo.associations}" paginator="true" rows="${v001.datatable_rows}"
selection="#{asso.selection}" selectionMode="single">
<p:column>
<f:facet name="header"><h:outputText value="Code" /></f:facet>
<h:outputText value="#{a.id}" />
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Nom" /></f:facet>
<h:outputText value="#{a.nom}" />
</p:column>
</p:dataTable>
Code: Select all
<h:form id="saisieAssociation">
<table>
<tr>
<td><h:outputText value="${v001.col_code}" /></td>
<td><h:inputText id="code" value="#{asso.code}" /></td>
</tr>
<tr>
<td><h:outputText value="${v001.col_nom}" /></td>
<td><h:inputText id="nom" value="#{asso.nom}" /></td>
</tr>
<tr>
<td colspan="2">
<p:editor id="activite" width="${v001.w_activité}" height="${v001.h_activité}"
value="#{asso.activité}" title="${v001.col_activité}" />
</td>
</tr>
<tr>
<td></td>
<td><p:commandButton update="listeDesAssociations" actionListener="#{asso.soumission()}" value="${v001.btn_creation}" /></td>
</tr>
</table>
</h:form>
I've made my datatable selectable.
But what I don't know about, is how to react dynamically to a row selection.
I have a:
Code: Select all
selection="#{asso.selection}"
But what is the way to ask the datatable to transmit data immediately from the datatable columns to the form field that is below, at the time I want to display to the user the details of his selection? (in order to allow him to update or remove the datatable entry)?
I saw a onSelectComplete attribute for the <p:datatable> component. It relies on Javascript.
Is it the cleanest way to do what I want? Adding a script like:
Code: Select all
<p:dataTable id="listeDesAssociations" var="a" value="#{vivo.associations}" paginator="true" rows="${v001.datatable_rows}"
selection="#{asso.selection}" selectionMode="single" onSelectComplete="onRowSelection()">
Code: Select all
<script>
function onRowSelection()
{
document.element('saisieAssociation:code') = #{a.id};
document.element('saisieAssociation:nom') = #{a.nom};
}
</script>
I do not think it could work.
I am not a fan of Javascript. In fact I started Primefaces to avoid writing some.
I guess I am not using the good way to reach the goal I am looking for.
How should I do this? : copying some attributes content of the managed bean associated with the datatable selected row to some other fields of my saisieAssociation form, at selection time?
Regards,
Grunt.