0

Clicking commandLink button in below code does not redirect to destination page:

<h:form>
   <h:dataTable value="#{studentController.students}" var="studentData" >
      <h:column>
         <f:facet name="header">Action</f:facet>
         <h:commandLink value="Update" action="update.xhtml"/>
      </h:column>
   </h:dataTable>               
</h:form>
pirho
  • 10,579
  • 12
  • 42
  • 61

1 Answers1

-1

This is not how h:commandLink works. Take a look at the documentation. Attribute action should contain a

javax.el.MethodExpression (signature must match java.lang.Object action())

MethodExpression representing the application action to invoke when this component is activated by the user. The expression must evaluate to a public method that takes no parameters, and returns an Object (the toString() of which is called to derive the logical outcome) which is passed to the NavigationHandler for this application.

So it should look like this:

<h:commandLink value="Update" action="#{someBean.action}" />

And your bean should have a method:

public String action() {
    // Do something
    return "update";
}

And in faces-config.xml you should add a navigation rule:

<navigation-rule>
    <from-view-id>/list.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>update</from-outcome>
        <to-view-id>/update.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

You can simplify all this by using the outcome directly in the action attribute and skip the Java method.

<h:commandLink value="Update" action="update"/>