声明本人刚学jsf三天 如有不足请指教....

本人总结了三种取得参数的方法

这是jsf中的代码 

<h:commandLink  action="#{}">
      <h:outputText value="删除"></h:outputText>
      <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;
 }

}

 

代码没有贴完

相关文章:

  • 2021-12-26
  • 2021-08-03
  • 2022-12-23
  • 2021-09-14
  • 2021-07-19
  • 2022-01-05
猜你喜欢
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2021-11-10
  • 2022-01-12
  • 2022-12-23
相关资源
相似解决方案