1
I’m starting to study JSF and soon came to me the question of how to reference the View (JSF) with Managed Beans. Because in the examples I see I can’t understand how JSF can see the Bean. For example:
Xhtml file:
...
<p:outputLabel value="Nome" for="nome"/>
<p:inputText id="nome" required="true" value="#{perfilUsuarioBean.nome}"/>
...
Arquivobean.java:
@ManagedBean
public class PerfilUsuarioBean {
...
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
...
}
How JSF Can See Bean Methods?
Thanks Diego, that I understood. I’m not getting access to Bean. I tried to do <h:outputText value="#{searchProducts.ola}" />, but it does not return to String. What I find strange is that you don’t have to specify where Bean is.
– Raphael
@Raphael , for JSF to find the variable
ola
in your Managedbean, it is necessary that Managedbean has thegetter
of the variableola
. Ex:public String getOla() { return this.ola; }
– igventurelli
@igorventurelli I tried this way, but without success :( The bean I created is in the package with.empresa.project.controller JSF will be able to find it on its own?
– Raphael
@Raphael you have assigned a value to the variable
ola
? If you dopublic String getOla() { return "Ola Mundo"; }
works?– igventurelli
@igorventurelli Yes, I did it this way and it didn’t work. I also initialized the variable in the constructor and it wasn’t.
– Raphael