留言板

Set JSF value in two different beans

Besart Jashari,修改在9 年前。

Set JSF value in two different beans

New Member 帖子: 5 加入日期: 15-4-16 最近的帖子
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,修改在9 年前。

RE: Set JSF value in two different beans

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
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.