jimmybondy
jimmybondy

Reputation: 2152

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

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

Upvotes: 2

Views: 472

Answers (1)

BalusC
BalusC

Reputation: 1108632

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;

Upvotes: 1

Related Questions