Search code examples
jsfelcrudjsf-1.2

The function [functionName] must be used with a prefix when a default namespace is not specified


I'm using JSF 1.2 and I'm trying to delete and/or update a row in a <h:dataTable> whereby the current row is passed as argument of action method.

View:

<h:dataTable value="#{myBean.list}" var="categoria">
  ...
  <h:column>
    <h:commandButton value="Update" action="#{myBean.updateCat(categoria)}" />
    <h:commandLink value="Delete" action="#{myBean.deleteCat(categoria.cod)}" />
  </h:column>
</h:dataTable>

Controller:

public void deleteCat(int cod) {
  this.controller.deleteCat(cod);
}

public void updateCat(Categoria cat) {
  this.controller.updateCat(cat);
}

But I'm getting the following error:

The function deleteCat must be used with a prefix when a default namespace is not specified

How is this caused and how can I solve it?


Solution

  • The function deleteCat must be used with a prefix when a default namespace is not specified

    This error message is typical when the new EL 2.2 feature of invoking bean methods with arguments isn't supported in the current EL environment. That can happen when the current EL environment is actually not comply EL version 2.2 at all. EL 2.2 is part of Servlet 3.0 and thus requires a Servlet 3.0 compatible container (Tomcat 7, Glassfish 3, JBoss 6, etc) with a Servlet 3.0 compatible web.xml in order to work.

    Before EL 2.2, parentheses () in EL expressions are by default interpreted as EL function arguments. However EL functions are in turn expected to be referenced by a colon prefix on a taglib namespace like so #{fn:length(bean.list)} instead of a period. That explains at least the at first sight rather strange error message.

    Given that you're using the legacy JSF 1.2, you're most likely using Servlet 2.5 (Tomcat 6, Glassfish 2, JBoss 4, etc) and thus implicitly also EL 2.1. In order to simulate the new EL 2.2 feature of invoking bean methods with arguments, your best bet is downloading and installing JBoss EL as outlined in this answer: Invoking methods with parameters by EL in JSF 1.2.