< F:selectItems的> JSF标签定制属性提示 [英] <f:selectItems> JSF tag custom tooltip attribute

查看:419
本文介绍了< F:selectItems的> JSF标签定制属性提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在JSF中添加一个title属性的标签,例如:

< F:selectItems的值=#{} foo.fooList称号={} foo.fooDescription/ >

生成的HTML:

<选择>
    <期权价值=foo1称号=内容描述>富EX1< /选项>
    <期权价值=foo2的标题=内容描述>富EX2< /选项>
< /选择>


解决方案

我没有一个完美的解决方案,但它可以做到的。我假设JSF 2+和放大器; Facelets的VDL。

有关托管bean

  @ManagedBean @RequestScoped
公共类Foo {
  私人列表<&的SelectItem GT; fooList = Arrays.asList(
            新的SelectItem(值1,LABEL1,内容描述),
            新的SelectItem(值2,LABEL2,说明2));  公开名单<&的SelectItem GT; getFooList(){
    返回fooList;
  }
}

您可以使用JavaScript来设置标题的DOM节点上的属性:

< H:selectOneMenu用于绑定=#{} requestScope.fooSelectOne>
  < F:selectItems的值=#{} foo.fooList/>
< /小时:selectOneMenu用于>
<脚本>
(函数(){
  VAR selectName ='#{} requestScope.fooSelectOne.clientId';
  变种孩子= document.getElementsByName(selectName)[0]
                     .getElementsByTagName(选项);
  变种索引= 0;
  < UI:重复值=#{} foo.fooListVAR =_选择>
  孩子们[指数++]标题='#{_ opt.description}。 // TODO:逃离这个
  < / UI:重复>
}());
< / SCRIPT>

Is it possible to add a "title" attribute to the tag in JSF, for example:

<f:selectItems value="#{foo.fooList}" title="{foo.fooDescription}"/>

Generated HTML:

<select>
    <option value="foo1" title="description1">foo ex1</option>
    <option value="foo2" title="description2">foo ex2</option>
</select>

解决方案

I don't have an elegant solution, but it can be done. I'm assuming JSF 2+ & Facelets VDL.

For a managed bean Foo:

@ManagedBean @RequestScoped
public class Foo {
  private List<SelectItem> fooList = Arrays.asList(
            new SelectItem("value1", "label1", "description1"),
            new SelectItem("value2", "label2", "description2"));

  public List<SelectItem> getFooList() {
    return fooList;
  }
}

You can use JavaScript to set the title attribute on the DOM node:

<h:selectOneMenu binding="#{requestScope.fooSelectOne}">
  <f:selectItems value="#{foo.fooList}" />
</h:selectOneMenu>
<script>
(function() {
  var selectName = '#{requestScope.fooSelectOne.clientId}';
  var kids = document.getElementsByName(selectName)[0]
                     .getElementsByTagName("option");
  var index = 0;
  <ui:repeat value="#{foo.fooList}" var="_opt">
  kids[index++].title = '#{_opt.description}'; //TODO: escape this
  </ui:repeat>
}());
</script>

这篇关于&LT; F:selectItems的&GT; JSF标签定制属性提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆