0

アクション メソッド内のパラメーターを別のページに送信すると、2 番目のクラスから読み取ることができません。

page1.xhtml:

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

マネージド Bean1

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

2 番目のクラス MBean2 で、次のコード ブロックでパラメーターを取得しようとしましたが、送信したパラメーターを取得できません。

@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"));
}

param1 と param2 は null になります。mbean1 のアクション メソッドから param1 と param2 を取得するにはどうすればよいですか。

4

1 に答える 1

0

このタイプミスretrunでしょうか?編集して再試行してください。

@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
  }
}

参考までに、注釈を使用@ManagedPropertyして、ある ManagedBean から別の ManagedBean にプロパティを注入できます。他の ManagedBean にプロパティがあるということは、パラメーターを渡す必要がないことを意味します。

Injecting Managed Bean in JSF 2.0を見てください。

于 2012-07-02T01:06:10.160 に答える