简体   繁体   English

通过JSF ui:repeat中的jQuery UI小部件访问添加的值

[英]Access added values through jQuery UI widget inside ui:repeat in JSF

  • I have added a ui:repeat within a ul-list to produce a unordered list 我在ul列表中添加了ui:repeat以产生无序列表
  • Through jQuery Tag-It widget the list get´s nicely editable (unfortunately primefaces doen't have a similar component yet) 通过jQuery Tag-It小部件 ,列表可以很好地进行编辑(不幸的是,primefaces还没有类似的组件)
  • when saving the form i can't access the new created values (only the values of the other primefaces components) 保存表单时,我无法访问新创建的值(仅其他primefaces组件的值)

XHTML XHTML

<ul id="keywordList">
<ui:repeat value="#{bean.selectedObject.keywords}" var="keyword">
    <li><h:outputText value="#{keyword.name}" /></li>
    </ui:repeat>
</ul>

Bean 豆角,扁豆

public class Bean implements Serializable {
    private MyObject selectedObject;
}

Model 模型

public List<String> getKeywords() {
    return keywords;
} 

public void setKeywords(List<String> keywords) {
    this.keywords = keywords;
}

Any idea, how i can access the values which are added to the UL-List? 任何想法,我如何访问添加到UL列表中的值? Thanks! 谢谢!

EDIT : The bean is session scoped 编辑 :bean是会话范围的

According to its documentation and demos the jQuery tag-it plugin autocreates a hidden input element with the (configureable) name syntax item[tags][] . 根据其文档演示 ,jQuery tag-it插件会自动创建一个具有(可配置)名称语法item[tags][]的隐藏输入元素。 You should be able to grab it from the HTTP request parameter values map by ExternalContext#getRequestParameterValuesMap() in JSF as follows: 您应该能够通过JSF中的ExternalContext#getRequestParameterValuesMap()从HTTP请求参数值映射中获取它,如下所示:

String[] tags = FacesContext.getCurrentInstance().getExternalContext()
    .getRequestParameterValuesMap().get("item[tags][]");

You could also set it as a managed property, but this requires the bean to be request scoped. 您也可以将其设置为托管属性,但这需要将bean限定在请求范围内。

@ManagedProperty("#{paramValues['item[tags][]']}")
private String[] tags;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM