bigO bigO - 9 months ago 69
Java Question

Passing parameters between managed beans

I am trying to pass some parameters from one managed bean to another. I saw similar question and applied their solutions but does not work. Here is the code:

In my moneytransfer.xhtml file:

<h:commandButton action="#{moneyTransferBean.transferAccounts()}" value="Continue">
<f:param name="sender" value="#{extTableSelectionBean.sender}" />

My extTableSelectionBean:

public class ExtTableSelectionBean implements Serializable {
private Account sender;

public void setSender(Account sender){

public Account getSender(){
return sender;

and the moneyTransferBean:

public class MoneyTransferBean {
@ManagedProperty("#{extTableSelectionBean .sender}")
private Account sender;
//NO SETTER-GETTER FOR sender here

public void transferAccounts() throws IOException {

if (sender != null)

I see that in extTableSelectionBean, the "sender" is succesfully set. The problem is, when i get to the moneyTransferBean, sender becomes null. What should i do about it, what am i doing wrong?


Answer Source

Two things are mixed here. Injecting a bean into another bean and adding a parameter to commandButton.

Account sender is tried to inject to MoneyTransferBean, however there is no action will be performed since there is no getter setter, so injection will be failed.

sender is tried to set through a commandButton to send as parameter, but there is no implementation for it. @ManagedProperty annotation should be changed for reading the parameter from command button. I assume that sender is set in any place before submitting of commandButton

private Account sender;

There are further methods to send or set data in managed beans. Please read the BalusC answer.

Related Post