0

When I send parameters within the action method to another page I can not read them from second Class.

page1.xhtml:

....
<h:commandLink action="#{mbean1.gotoMessageDetail(msg)}" value="#{msg.caption}"/>
....

Managed bean1

@ManagedBean(name = "mbean1")
@RequestScoped
public class MBean1 {
 ....
 public String gotoMessageDetail(Message msg) {
    //do some work
    retrun "page2.xhtml?param1=val1&param2=val2";
  }
}

At the second class MBean2 I try to take parameters with the following code block but I cant get the parameters I sent.

@ManagedBean(name = "mbean2")
@ViewScoped
public class MBean2{
   ...
  HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
  param1=Long.parseLong(request.getParameter("param1")==null ? "0" : request.getParameter("param1"));
  param2=Long.parseLong(request.getParameter("param2")==null ? "0" : request.getParameter("param2"));
}

The param1 and param2 come null. How can I get param1 and param2 from mbean1's action method.

Mysophobe
  • 622
  • 2
  • 10
  • 33
Mustafa
  • 98
  • 1
  • 2
  • 10

1 Answers1

0

Could it be this typo retrun? Edit and try again.

@ManagedBean(name = "mbean1")
@RequestScoped
public class MBean1 {
 ....
 public String gotoMessageDetail(Message msg) {
    //do some work
    return "page2.xhtml?param1=val1&param2=val2";
    /////retrun to return
  }
}

For your information, you can use @ManagedProperty annotation to inject properties from one ManagedBean to another. Having the properties over at the other ManagedBean means you will not need to pass any parameters around.

Take a look at Injecting Managed beans in JSF 2.0

Mysophobe
  • 622
  • 2
  • 10
  • 33
  • Thank you for your comment Zany. But retrun is just the type error here. As I know @ManagedProperty works for sessionscoped beans. but my beans are requestscopd and viewscoped. – Mustafa Jul 02 '12 at 07:59
  • @Mustafa: `@ManagedProperty` annotation injects any scoped bean as long as this managed property bean is of higher or equal scope than the managed bean. – Ghasfarost Dec 17 '12 at 18:48