I created two bean classes and one jsf page. My jsf page having two inputtext and one button. I want to get value from inputtext. value should be come from different-different Bean class. but i'm getting second value is null. so any one know how to achieve second value from secondbean class in firstbean class.
Xhtml code:
<h:form id="form">
<p:panel id="panel" style="padding:0px;">
<p:panelGrid id="textgrid" columns="2">
<p:outputLabel value="Name" />
<p:inputText value="#{firstBean.name}" />
<p:outputLabel value="Profession" />
<p:inputText value="#{secondBean.profession}" />
<p:commandButton value="Save" actionListener="#{firstBean.saveName()}" />
</p:panelGrid>
</p:panel>
</h:form>
firstBean class:
@ManagedBean(name = "firstBean")
public class First implements java.io.Serializable {
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public void saveName() {
System.out.println("Name: "+name);
Second obj=new Second();
obj.saveProfession();
}
}
secondBean class:
@ManagedBean(name = "secondBean")
public class Second implements java.io.Serializable {
private String profession;
public String getProfession() {
return this.profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
public void saveProfession() {
System.out.println("Profession: "+profession);
}
}
Ouput is coming
Name: Charlie
Profession: null //second value is not coming
I am passing profession is job through value="#{secondBean.profession}" but i'm getting null value instead of actual value. so i want to know how to achieve secondBean class value and firstBean class value using single button(in JSF page).