Get value of an attribute in JSF -The class 'xxx' does not have the property 'yyy'

0

Greetings, I am developing an application in JSF, in which, a message is displayed, the typical "Hello World". For this, I have in a package hello a class Hello , with the annotation ManagedBean, in which I define an attribute message and a method to consult the value. So far no problems. I get the value as follows:

<h:head>
        <title>Hola mundo...</title>
</h:head>
<h:body>
   #{hello.mensaje}      
</h:body>

But if in the same project I create another package called salute , and add a class Hello , with the annotation ManagedBean, and an attribute mensajedos , when I try to check this value,

<h:body>
       #{hello.mensaje}        
       #{hello.mensajedos}        
</h:body>

has an error, since it is not possible to read the attribute:

The class 'saludo.Hello' does not have the property 'mensaje'.

It's understandable, because I'm not specifying the package. In a way I was already waiting for the error. The question is, how do I specify the class package?

Thanks in advance

    
asked by chenio 02.11.2016 в 00:06
source

2 answers

0

You have two managed bean with the same name "hello" and "hello". If you add to one of the MB: @Named (value="hello2") and your html update it to: # {hello2.message}, it should work.

    
answered by 11.01.2017 / 22:44
source
1

If you are using CDI managed beans, be sure to assign a scope since the default is @Dependent and it does not work on its own.

You have to make sure you have the setters and getters of the properties you are trying to use by means of Expression Language and how it is a bean means that you have to use encapsulation, implement Serializable and have an empty constructor.

E.G.:

@Named
@RequestScoped
public class Hello2 implements Serializable{

   private String saludo = "Saludo 2";

   public void Hello2(){}

   public void setSaludo(String s){
      saludo = s;
   }

   public void getSaludo(){
     return saludo;
   }
}

and in the facet:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

      <h:head>
      </h:head>

      <h:body>
          #{hello2.saludo}
      </h:body>
</html>
    
answered by 09.11.2016 в 17:06