Pregunta

I have a lot of commandlinks in my treetable that I build them dynamically,and if I want to change color of one command link when i have clicked on it,all command links change they color ,i don't know how to change the color of this specified link,becouse i don't know her number or id,if somebody knows the answer can you help me.....

¿Fue útil?

Solución

The <h:commandLink>/<ice:commandLink> will generate HTML <a> elements with a href on # which use JavaScript to submit a hidden POST form, so they basically end up all having the same href and that's why they will all appear as "visited" when you click one of them.

If you really worry about which link was clicked, then you're implicitly also worrying about the idempotency of the link. In that case you should not be using command links, but just plain output links which you can create with <h:outputLink> or, when you're already on JSF2, with <h:link>. You could pass parameters by a nested <f:param> and you could invoke actions on the target view (e.g. to prepare some model object) by <managed-property>/@PostConstruct or, when you're already on JSF2, by <f:viewParam> and <f:event type="preRenderView">.

E.g.

<h:dataTable value="#{bean.list}" var="item">
  <h:column>
    <h:outputLink value="edit.jsf">
      <f:param name="id" value="#{item.id}" />
      <h:outputText value="edit item #{item.id}" />
    </h:outputLink>
  </h:column>
</h:dataTable>

This way every link will be unique and thus will only appear as "visited" when only the actual link was been clicked.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top