I am not sure of what you want to do at the end, but why don't you use a <h:commandLink>
(that will generate a <a>
HTML tag) instead (don't forget to nest your <h:datatable>
in a <h:form>
)?
<h:form id="myForm">
...
<h:dataTable id="grid1" value="#{postControle.lista}" var="post1">
...
<h:column>
<f:facet name="header"><h:outputText style="float: left; font-weight: bold;" value="Opções"/></f:facet>
<h:commandLink action="#{postControle.alterar}" value="Alterar"/>
<h:commandLink action="#{postControle.consultar}" value="Consultar"/>
</h:column>
</h:dataTable>
Then, you define two actions in your Java bean (the String
returned defines the navigation case to apply after the execution of the method):
public String alterar() {
...
}
public String consultar() {
...
}
And in each action method, you can retrieve the corresponding element (i.e. post1
) using the getRowData()
method of the HtmlDatatable
component:
public String alterar() {
HtmlDatatable table = (HtmlDatatable) FacesContext.getCurrentInstance().getViewRoot().findComponent("myForm:id1");
YourClass element = (YourClass) table.getRowData();
...
romaintaz
2010-10-27 06:57:20