1. 程式人生 > >JSF中的h:commandLink如何傳遞引數 三種取值比較

JSF中的h:commandLink如何傳遞引數 三種取值比較

<h:commandLink  action="#{}">
      <h:outputText value="刪除"></h:outputText>
      <f:param id="id" name="id" value="123"></f:param> //假如要傳遞的引數為id
</h:commandLink>

這是BackBean中的程式碼 下邊是如何在後臺取得這個id引數的值

public class Person
{

 public void verify(ActionEvent e)
 {
  /*這是第一種取得引數的方法


  UIComponent com = e.getComponent();
  UIParameter param = (UIParameter) com.findComponent("id");
  Integer id = (Integer) param.getValue();
  System.out.println(id);
  */
  /*這是第二種取得引數值的方法
  HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
  
  int id = Integer.parseInt(request.getParameter("id"));
  System.out.println(id);
  */
  //這是第三種取得引數的方法

  int id = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"));
  
  System.out.println(id);
 }
 
 public String outcome()
 {
  return outcome;
 }

}