<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-112  評(píng)論-73  文章-0  trackbacks-0
    jsf 傳參數(shù)主要有以下幾種方式:

    As to the cause, the <f:attribute> is specific to the component itself (populated during view build time), not to the iterated row (populated during view render time).

    There are several ways to achieve the requirement.

    1. Use <f:param> instead. It adds a request parameter.

      <h:commandLink action="#{bean.insert}" value="insert">
         
      <f:param name="id" value="#{item.id}" />
      </h:commandLink>

      If your bean is request scoped, let JSF set it by @ManagedProperty

      @ManagedProperty(value="#{param.id}")
      private Long id; // +setter

      Or if your bean has a broader scope or if you want more fine grained validation/conversion, use<f:viewParam> on the target view, see also f:viewParam vs @ManagedProperty:

      <f:viewParam name="id" value="#{bean.id}" required="true" />

      Either way, this has the advantage that the datamodel doesn't necessarily need to be preserved for the form submit (for the case that your bean is request scoped).


    2. Use <f:setPropertyActionListener> instead. The advantage is that this removes the need for accessing the request parameter map when the bean has a broader scope than the request scope.

      <h:commandLink action="#{bean.insert}" value="insert">
         
      <f:setPropertyActionListener target="#{bean.id}" value="#{item.id}" />
      </h:commandLink>

      In combination with

      private Long id; // +setter

      It'll be just available by property id in action method. This only requires that the datamodel is preserved for the form submit request. Best is to put the bean in the view scope by @ViewScoped.


    3. If your servletcontainer supports Servlet 3.0 / EL 2.2, then just pass it as method argument. This also requires that the datamodel is preserved for the form submit request. Best is to put the bean in the view scope by @ViewScoped.

      <h:commandLink action="#{bean.insert(item.id)}" value="insert" />

      In combination with:

      public void insert(Long id) {
         
      // ...
      }

      You can even pass the entire item object:

      <h:commandLink action="#{bean.insert(item)}" value="insert" />

      with:

      public void insert(Item item) {
         
      // ...
      }

      On Servlet 2.5 containers, this is also possible if you supply an EL implementation which supports this, like as JBoss EL. For configuration detail, see this answer.


    4. Bind the datatable value to DataModel<E> instead which in turn wraps the items.

      <h:dataTable value="#{bean.model}" var="item">

      with

      private transient DataModel<Item> model;

      public DataModel<Item> getModel() {
         
      if (model == null) {
              model
      = new ListDataModel<Item>(items);
         
      }
         
      return model;
      }

      (making it transient and lazily instantiating it in the getter is mandatory when you're using this on a view or session scoped bean since DataModel doesn't implement Serializable)

      Then you'll be able to access the current row by DataModel#getRowData() without passing anything around (JSF determines the row based on the request parameter name of the clicked command link/button).

      public void insert() {
         
      Item item = model.getRowData();
         
      Long id = item.getId();
         
      // ...
      }

      This also requires that the datamodel is preserved for the form submit request. Best is to put the bean in the view scope by @ViewScoped.


    5. You can use Application#evaluateExpressionGet() to programmatically evaluate the current #{item}.

      public void insert() {
         
      FacesContext context = FacesContext.getCurrentInstance();
         
      Item item = context.getApplication().evaluateExpressionGet(context, "#{item}", Item.class);
         
      Long id = item.getId();
         
      // ...
      }

    Which way to choose depends on the functional requirements and whether the one or the other offers more advantages for other purposes. I personally would go ahead with #3 or, when you'd like to support servlet 2.5 containers as well, with #2.

    posted on 2012-07-13 19:42 Libo 閱讀(620) 評(píng)論(0)  編輯  收藏 所屬分類: JSF 2
    主站蜘蛛池模板: 97国产免费全部免费观看| 久久精品国产亚洲av麻豆蜜芽| 免费一级毛片清高播放| 全免费a级毛片免费看无码| 7723日本高清完整版免费| 国产免费不卡v片在线观看| 18禁网站免费无遮挡无码中文| jjizz全部免费看片| 台湾一级毛片永久免费| 国产成人无码免费看视频软件| 成人免费一级毛片在线播放视频| 很黄很黄的网站免费的| 一个人免费观看视频www| 成年性生交大片免费看| 四虎影视免费在线| 又大又粗又爽a级毛片免费看| 免费人成网站在线播放| 精品亚洲视频在线观看| 亚洲色WWW成人永久网址| 亚洲AV无码第一区二区三区| 久久亚洲精品国产精品| 亚洲伊人久久大香线蕉影院| 亚洲人成77777在线观看网| 亚洲AV无码AV吞精久久| 免费无码又爽又黄又刺激网站| selaoban在线视频免费精品| 免费观看一区二区三区| 最近免费中文字幕mv电影| 成人毛片免费观看视频大全| 免费人成在线观看网站品爱网日本| 亚洲精品视频免费观看| 亚洲AV色香蕉一区二区| 亚洲精品伊人久久久久| 黄色免费网址在线观看| 日韩免费高清播放器| 91久久成人免费| 免费观看日本污污ww网站一区| 国产成人综合亚洲AV第一页| 中文字幕亚洲综合久久2| 亚洲AV一区二区三区四区| 国产乱子伦精品免费视频|