Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2.0 with Expression is a method error

I have this line in my jsf page

<h:dataTable value="#{customer.getCustomerList()}"

and in my bean I have

public List<Customer> getCustomerList(){
        return customerBo.findAllCustomer();
    }

I am using JSF 2.0 with Eclipse Helios with servlet 2.5 and when I validate I am getting

Expression must be a value expression but is a method expression

How can I resolve this issue?

like image 236
Jacob Avatar asked Dec 05 '22 13:12

Jacob


2 Answers

I have a similar problem, despite the fact i was doing right, like PermGenError posted. I had this:

<h:commandButton action="#{bean.registry}"></h:commandButton>

And i got error: Expression must be a method expression but is a value expression

In my Bean, there was:

class Bean{

    Registry registry = new Registry();

    public Registry getRegistry() {
        return registry;
    }
}

Reason of this message is that Eclipse doesn't recognize that this is actually method calling, in JSF manner, and give this message like an error. This can be turned off on this way:

Window/ Preferences/ Web/ JavaServer Faces Tools/ Validation/ Type Assignment Problems/ Method expression expected

change to Warning or Ignore

I hope this will help someone!

like image 50
akelec Avatar answered Jan 02 '23 10:01

akelec


View:

<h:dataTable value="#{customer.customerList}"

The value attribute of your h:dataTable expects a value expression, not a method expression. You have to create a property called customerList in your #{customer} managed bean.

@ManagedBean(name="customer")
public class Customer implements Serializable {
    private List<Customer> custormerList= new ArrayList<Customer>();

    public void setCustomerList(List<Customer> cust){
       this.customerList = cust;
    }
    public List<Customer> getCustomerList(){
        return customerBo.findAllCustomer();
    }
}

Refer to the h:dataTable tag documentation

like image 26
PermGenError Avatar answered Jan 02 '23 10:01

PermGenError