• JSF中的h:commandLink如何传递参数 三种取值比较


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

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

    这是jsf中的代码 

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

    }

    代码没有贴完

  • 相关阅读:
    你看那个人他像一条狗
    jvm系列(八):jvm知识点总览
    jvm系列(七):jvm调优-工具篇
    百亿互金平台救火故事
    一个脚本引发的血案
    一次dns缓存引发的惨案
    一次生产事故的优化经历
    从零到百亿互联网金融架构发展史
    2016颠倒梦想,2017静心前行
    Spring Boot(九):定时任务
  • 原文地址:https://www.cnblogs.com/lyglcheng/p/1495207.html
Copyright © 2020-2023  润新知