JSF значение выражения
Я хотел бы динамически создавать содержимое моей страницы jsf. Что мне нужно сделать, это создать компонент-редактор. Я разместил две кнопки на своей странице. Вот код:
//Various imports;
@ManagedBean
@ViewScoped
public class Elpad implements Serializable{
private String padreCorrente = "Nessun padre è stato creato";
private HtmlPanelGrid customGrid;
private UIComponent padreCorrenteC;
private List<SelectItem> items = new ArrayList<SelectItem>();
private List<UISelectItems> listaItem = new ArrayList<UISelectItems>();
private String itemScelto = "";
public Elpad() {
//items = new ArrayList<SelectItem>();
//items.add(0, new SelectItem("poba", "poba"));
//items.add(1, new SelectItem("ripoba", "ripoba"));
}
public String getItemScelto() {
return itemScelto;
}
public void setItemScelto(String itemScelto) {
this.itemScelto = itemScelto;
}
private String ris ="";
public List<SelectItem> getItems() {
return items;
}
public void setItems(List<SelectItem> items) {
this.items = items;
}
public List<UISelectItems> getListaItem() {
return listaItem;
}
public void setListaItem(List<UISelectItems> listaItem) {
this.listaItem = listaItem;
}
public HtmlRadio getSelectedRadio() {
return selectedRadio;
}
public void setSelectedRadio(HtmlRadio selectedRadio) {
this.selectedRadio = selectedRadio;
}
public String getPadreCorrente() {
return padreCorrente;
}
public void setPadreCorrente(String padreCorrente) {
this.padreCorrente = padreCorrente;
}
public HtmlPanelGrid getCustomGrid() {
return customGrid;
}
public void setCustomGrid(HtmlPanelGrid customGrid) {
this.customGrid = customGrid;
}
public void aggiungiPadre(ActionEvent evt) {
HtmlSelectOneListbox sor = new HtmlSelectOneListbox();
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elcntx = fc.getELContext();
Application app = fc.getApplication();
ExpressionFactory xprfct = app.getExpressionFactory();
ValueExpression ve = xprfct.createValueExpression(elcntx,"#{elpad.itemScelto}", String.class);
ve.getValue(FacesContext.getCurrentInstance().getELContext());
sor.setValueExpression("value", ve);
log.error("Il componente HtmlSelectOneListbox sor è stato creato con ID : " + sor.getClientId() + " e ValueExpression : " + sor.getValueExpression("value") + " quindi ha valore : " + sor.getValue());
UISelectItems a = new UISelectItems();
items.add(0, new SelectItem("poba", "poba"));
ValueExpression ve1 = xprfct.createValueExpression(elcntx,"#{elpad.items}", ArrayList.class);
ve1.getValue(FacesContext.getCurrentInstance().getELContext());
a.setValueExpression("valuee", ve1);
log.error("Il componente UISelectItems a è stato creato con ID : " + a.getClientId() + " e ValueExpression : " + a.getValueExpression("valuee") + " quindi ha valore : " + a.getValue() + " per l'attributo items : " + items.get(0).getLabel() + " di dimensione : " + items.size() + " ;" );
sor.getChildren().add(a);
customGrid.getChildren().add(sor);
padreCorrenteC = sor;
/*FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExpression = facesContext.getApplication().getExpressionFactory()
.createValueExpression(elContext, "#{elpad.items}", String.class);
valueExpression.setValue(elContext, ris);*/
padreCorrente = padreCorrenteC.getId();
}
public void aggiungiFiglio(ActionEvent evt) {
items.add(new SelectItem(padreCorrente, padreCorrente.toString()));
}
}
И это моя страница XHTML
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:icecore="http://www.icefaces.org/icefaces/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:ice="http://www.icesoft.com/icefaces/component"
>
<h:head>
<title>Cambia padre</title>
</h:head>
<h:body>
<ice:form>
<ice:panelGrid binding="#{elpad.customGrid}">
</ice:panelGrid>
<ice:commandButton value="Aggiungi padre" actionListener="# {elpad.aggiungiPadre}"></ice:commandButton>
<ice:commandButton value="Aggiungi figlio" actionListener="# {elpad.aggiungiFiglio}"></ice:commandButton>
</ice:form>
<ice:outputLabel value="#{elpad.padreCorrente}"></ice:outputLabel>
</h:body>
</html>
Кто-нибудь может мне помочь? То, что я пытаюсь сделать, это создать SelectOneList с дочерним элементом SelectItems с первой кнопкой и добавить элементы в список с помощью второй кнопки. Я думаю, что я что-то упустил при создании второго ValueExpression (потому что я пробовал некоторые тесты с регистратором, и он возвращает ноль), но я не знаю, что