In a Java Web Project(JSF+Spring), i want to do this:
i have a search box in index.xhtml, i want that when i click search button, a method called from a class, and then result get's back:
this is index.xhtml
:
<h:body>
<h:form>
<h:inputText value="#{searchBean.phrase}"></h:inputText>
<h:commandButton value="Search" action="result"></h:commandButton>
</h:form>
</h:body>
this is result.xhtml
:
<h:body>
#{searchBean.result}
</h:body>
this is searchBean.java
:
@ManagedBean
@SessionScoped
public class SearchBean {
private String phrase;
private String result;
private SearchClass searchObject;
public String getPhrase(){
return this.phrase;
}
public void setPhrase(String value){
this.phrase = value;
}
public String getResult(){
this.result = searchObject.search(getPhrase()); // here throws to an error
return this.result;
}
public void setResult(String value){
}
}
and this is searchClass
:
public class SearchClass{
public String search(String searchPhrase)
{
return "this is a sample result";
}
}
but when i run this, this sections throws to an error:
public String getResult(){
this.result = searchObject.search(getPhrase()); // here throws to an error
return this.result;
}
it seems calling a method from another class not allowed. this is error 500
that i get:
java.lang.NullPointerException
com.media.search.web.controller.SearchBean.getResult(SearchBean.java:35)
i just want to get some information from a method, whats the wrong here? should i do something in xml config files related to JSF or Spring?