Witam,
Wartości są odczytywane (tzn. a i b) lecz podczas zapisu selectedEntry jest nullem.
<?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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<h:form id="form">
<p:commandButton value="Dodaj nowy wpis" id="newEntry"
icon="ui-icon-plus" ajax="true"
actionListener="#{bean.createNewEntry}" update=":form:display"
immediate="true" onsuccess="entryDialog.show()" />
<p:dialog header="Edycja" widgetVar="entryDialog" resizable="false"
width="400" modal="true" id="entryDialog">
<h:panelGrid id="display" columns="2">
<h:outputText value="Pole A:" style="text-align: right" />
<h:inputText value="#{bean.selectedEntry.a}" id="a" />
<h:outputText value="Pole B:" style="text-align: right" />
<h:inputText value="#{bean.selectedEntry.b}" id="b"
width="360" />
</h:panelGrid>
<h:panelGrid id="buttons" columns="1">
<p:column style="text-align: center">
<p:commandButton value="Zapisz" id="ajbtn" icon="ui-icon-disk"
actionListener="#{bean.save}" onclick="entryDialog.hide()" />
</p:column>
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
</html>
@ViewScoped
@ManagedBean(name = "bean")
public class Bean implements Serializable {
private Entry selectedEntry; // getter && setter
public void save(ActionEvent e) {
//selectedEntry jest null
}
public void createNewEntry(ActionEvent e) {
selectedEntry = new Entry("ala", "ala2");
}
}
public class Entry implements Serializable {
private String a;
private String b;
// getters && settters
public Entry(String a, String b) {
this.a = a;
this.b = b;
}
public Entry() {
}
}
Wie ktoś co źle napisałem?