Question

I got some troubles for attribute binding in JSF 1.2 with EL 1.0

public class Bean {

  private String name;

  public String getName() {
     return name;
  }

  public Bean setName(String name)
     this.name = name;
     return this;
  }

XHTML that give me "Property 'name' not writable" error on form submit:

.. 

<h:inputText value="#{bean.name}" />

..

Why? It is a 3rd party lib, there is any workaround to solve that case?

Was it helpful?

Solution 2

I found a workaround for that case, but clearly it's not the most elegant way to do:

Create a "pseudo extension" of Bean class:

  public class BeanExtension {

  private Bean instance = new Bean();

  public String getName() {
    return instance.getName();
  }

  public void setName(String name)
    instance.setName(name);
  }

  // omitted instance getter and setter methods

  }

Since I wanted to override setName method return to "void", now I must use bean.instance to access it attributes, and bean.name to bind name on JSF with EL.

OTHER TIPS

Change signature of setName method like this

public void setName(String name)
  this.name = name;
}

If you want second constructor in your Bean class, then it should be designed like this

public Bean (String name)
  this.name = name;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top