I have this SearchBean:
@ManagedBean(name = "searchBean")
@RequestScoped
public class SearchBean implements Serializable
{
private String input = null;
// getter methods
public String getInput() {
return input;
}
// setter method
public void setInput(String input) {
this.input = input;
}
public String Submit() {
return null;
}
}
Can I inject it into another bean using @ManagedProperty. For example:
@ManagedBean(name = "bookBean")
@RequestScoped
public class BookBean implements Serializable
{
@ManagedProperty(value = "#{searchBean}")
private SearchBean searchBean;
@PostConstruct
public void init()
{
System.out.println("Value: " + searchBean.getInput());
}
public SearchBean getSearchBean() {
return searchBean;
}
public void setSearchBean(SearchBean searchBean) {
this.searchBean = searchBean;
}
}
And the Facelet (search.xhtml):
<h:form id="formSearch">
<h:commandButton value="Search" action="#{searchBean.Submit}" />
</h:form>
UPDATE: I have search.xhtml
inserted into book.xhtml
via a ui:insert
component as follow:
<h:form id="formBooks">
<ui:insert name="search">
<ui:include src="/templates/common/search.xhtml"/>
</ui:insert>
</h:form>
The searchBean.getInput()
method above should return a value as a result of a form's submission. Is the above method of injection possible?