1

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}" />
</h:commandButton>

My extTableSelectionBean:

@ManagedBean
@ViewScoped
public class ExtTableSelectionBean implements Serializable {
    private Account sender;

    public void setSender(Account sender){
        this.sender=sender;
    }


    public Account getSender(){
        return sender;
    }

and the moneyTransferBean:

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

     public void transferAccounts() throws IOException {        

         if (sender != null)
         {  
             FacesContext.getCurrentInstance().getExternalContext().redirect("transferaccount.xhtml");
         }
     }
}

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?

Thanks

yrazlik
  • 10,411
  • 33
  • 99
  • 165

1 Answers1

2

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

@ManagedProperty(value="#{param.sender}")
private Account sender;

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

Related Post

https://stackoverflow.com/a/4994833/892994

Community
  • 1
  • 1
erencan
  • 3,725
  • 5
  • 32
  • 50