Reputation:
I'm currently practicing JSF and EJB, but right now I can't get the page to show the information requested, this have input text and submit button (input.xhtml) and the expected result is to show the text submitted.
/input.xhtml @16,56 value="#{welcome.name}": Target Unreachable, identifier 'welcome' resolved to null
I've tried everything to fix it, this is part of the input.xthml
<ui:define name="content">
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Name:"/>
<h:inputText value="#{welcome.name}" title="name" id="name"
required="true" />
<h:message for="name" style="color: red"/>
</h:panelGrid>
<h:commandButton action="show" value="submit"/>
</h:form>
</ui:define>
</ui:composition>
This is the bean.
@ManagedBean
@RequestScoped
public class Welcome {
private String name;
private String message;
public String getMessage() {
return "Hello " + name;
}
public void setMessage(String message) {
this.message = message;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
Upvotes: 0
Views: 195
Reputation: 103
write like this
@ManagedBean(name="welcome")
@RequestScoped
public class welcome implements Serializable {
private String name;
}
In html write like this
<h:inputText value="#{welcome.name}" title="name" id="name"
required="true" />
Upvotes: 0
Reputation: 1109695
The code looks fine and it should work just fine. I only don't see how this is related to JPA and EJB. You would have exactly the same problem when you removed JPA/EJB from your testcase, right? You can just leave those tags and this detail out of the question.
As to the concrete problem, because you omitted the import
declarations, I can given the symptoms only guess that you're actually importing @ManagedBean
from the javax.annotation
package instead of the javax.faces.bean
package. The former won't make the bean to be managed by JSF, but the latter wil do. Check and fix your imports. Note that the @RequestScoped
also needs to be from the same package, not from the javax.enterprise.context
package.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class Welcome {
// ...
}
Upvotes: 3