Fórum

Set JSF value in two different beans

Besart Jashari, modificado 9 Anos atrás.

Set JSF value in two different beans

New Member Postagens: 5 Data de Entrada: 16/04/15 Postagens Recentes
I have a SelectOneMenu dropdown list in JSF. I need selected value from dropdown list to use in two different ManagedBean. How can I solve this.

view.xhtml

<p:selectonemenu id="staticEmployeeListEId" value="#{tableAdminMBean.staticEmployeeListEmployee}" onchange="selectEmployeeByStaticEmployeeList()">
	
	<f:selectitems value="#{tableAdminMBean.staticEmployeeLists}" var="staticEmployeeList" itemLabel="#{staticEmployeeList.name}" itemValue="#{staticEmployeeList}" />
</p:selectonemenu>



TableAdminMBean.java

@ManagedBean(name = "tableAdminMBean")
@ViewScoped
public class TableAdminMBean extends BaseMBean implements Serializable
{
	//EmployeeListEmployee represent many-to-many relationship betweeb Employee table and StaticEmployeeList table in database
	private StaticEmployeeList staticEmployeeListEmployee;
	
}



EmployeeMBean.java

@ManagedBean(name = "employeeMBean")
@ViewScoped
public class EmployeeMBean extends BaseMBean implements Serializable
{
	public void setToList()
	{
		try
		{
			EmployeeStaticEmployeeList a = new EmployeeStaticEmployeeListImpl();
			a.setEmployeeId(getEmployeeId());  // getEmployeeId()
			a.setStaticEmployeeListId( staticEmployeeListEmployee.getStaticEmplyeeListId() );  // I need "staticEmployeeListEmployee" to get from TableAdminMBean
			EmployeeStaticEmployeeListLocalServiceUtil.addEmployeeStaticEmployeeList(a);
		}
		catch(SystemException s)
		{
			s.printStackTrace();
		}
	}
}
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: Set JSF value in two different beans

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Hi Besart,

you can use the standard injection mechanism, using @ManagedProperty annotation and then specify there an EL expression pointing to the Managed bean that is used to store that value in xhtml.