简体   繁体   中英

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
  • Through jQuery Tag-It widget the list get´s nicely editable (unfortunately primefaces doen't have a similar component yet)
  • when saving the form i can't access the new created values (only the values of the other primefaces components)

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? Thanks!

EDIT : The bean is session scoped

According to its documentation and demos the jQuery tag-it plugin autocreates a hidden input element with the (configureable) name syntax item[tags][] . You should be able to grab it from the HTTP request parameter values map by ExternalContext#getRequestParameterValuesMap() in JSF as follows:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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