PDA

View Full Version : DataBinding with Subclass



Gahgah
21 Sep 2011, 2:08 AM
Hello,

I've a DTO which extends BaseModel. These DTO contains another DTO which also extends BaseModel.
On my FormPanel I want to show Attributes from both DTO's how can I access attributes from the SubDTO?

Example:

PersonDTO extends BaseModel
Two attributes:
String name
CityDTO city

CityDTO extends BaseModel
Two attributes:
String name
String postalCode

My view only knows PersonDTO directly.
How to bind the attributes of CityDTO?

Thanks in advance

Kind regards
Jan

sven
21 Sep 2011, 3:44 AM
Have you tried to do something like "city.postalCode"?

Gahgah
22 Sep 2011, 11:52 AM
Hey Sven,

thanks a lot. That worked, sorry that I haven't figured that out myself (it's so easy and straightforward).

But after solving this there's another thing I'm currently not able to solve. Let's say I set a new instance of CityDTO as attribute of my old instance of PersonDTO.
My view doesn't get updated. The new instances is in the model but my widgets (in my case a TextField) doesn't update! I'm using DataBindig. Once I save my view and reopen it everything is fine. But I want the widget to update on the fly.
Any Event I need to fire?

Would be nice if you have a solution for that too.

Kind regards
Jan

sven
22 Sep 2011, 12:11 PM
Are you using a ListStore? Than you can call store.update.

If not, than you would require more information of your code.

Gahgah
22 Sep 2011, 12:21 PM
Ok in this case I don't have any ListStore. I'm using just two simple Classes which both extend BaseModel.

My TextField:

TextField<String> innendienstMaTelefon = new TextField<String>();
innendienstMaTelefon.setName("innendienstMa.telefon");
innendienstMaTelefon.setFieldLabel(messages.innendienstMaTelefon());
innendienstMaTelefon.setEnabled(false);
return innendienstMaTelefon;

My FormBinding:

FormBinding binding = new FormBinding(panel, true);
binding.autoBind();
binding.bind(customerDTO);

My CustomerDTO

package de.thewes.entrega.shared.dto;import java.io.Serializable;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.ChangeEvent;
import com.extjs.gxt.ui.client.data.ChangeListener;
public class CustomerDTO extends BaseModel implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7044099824496963936L;
private static Boolean dataChanged = Boolean.FALSE;
@SuppressWarnings("unused")
private StandortDTO unusedStandortDTO;
@SuppressWarnings("unused")
private InnendienstMaDTO unusedInnendienstMaDTO;
@SuppressWarnings("unused")
private AussendienstMaDTO unusedAussendienstMaDTO;
public CustomerDTO() {
}
public CustomerDTO(Long kundeId, String kundenNummer1, String bezeichnung1,
String strasse, String ort, String plz, StandortDTO standort,
int version) {
set("kundeId", kundeId);
set("kundenNummer1", kundenNummer1);
set("bezeichnung1", bezeichnung1);
set("strasse", strasse);
set("ort", ort);
set("plz", plz);
set("standort", standort);
set("version", version);
}
{
addChangeListener(new ChangeListener() {
@Override
public void modelChanged(ChangeEvent event) {
dataChanged = Boolean.TRUE;
}
});
}
public Long getKundeId() {
return (Long) get("kundeId");
}
public void setKundeId(Long kundeId) {
set("kundeId", kundeId);
}
public String getKundenNummer1() {
return (String) get("kundenNummer1");
}
public void setKundenNummer1(String kundenNummer1) {
set("kundenNummer1", kundenNummer1);
}
public String getKundenNummer2() {
return (String) get("kundenNummer2");
}
public void setKundenNummer2(String kundenNummer2) {
set("kundenNummer2", kundenNummer2);
}
public String getBezeichnung1() {
return (String) get("bezeichnung1");
}
public void setBezeichnung1(String bezeichnung1) {
set("bezeichnung1", bezeichnung1);
}
public String getBezeichnung2() {
return (String) get("bezeichnung2");
}
public void setBezeichnung2(String bezeichnung2) {
set("bezeichnung2", bezeichnung2);
}
public String getStrasse() {
return (String) get("strasse");
}
public void setStrasse(String strasse) {
set("strasse", strasse);
}
public String getPlz() {
return (String) get("plz");
}
public void setPlz(String plz) {
set("plz", plz);
}
public String getOrt() {
return (String) get("ort");
}
public void setOrt(String ort) {
set("ort", ort);
}
public String getTelefon() {
return (String) get("telefon");
}
public void setTelefon(String telefon) {
set("telefon", telefon);
}
public String getFax() {
return (String) get("fax");
}
public void setFax(String fax) {
set("fax", fax);
}
public String getAnsprechpartner() {
return (String) get("ansprechpartner");
}
public void setAnsprechpartner(String ansprechpartner) {
set("ansprechpartner", ansprechpartner);
}
public String getEMail() {
return (String) get("email");
}
public void setEMail(String email) {
set("email", email);
}
public String getBelieferung() {
return (String) get("belieferung");
}
public void setBelieferung(String belieferung) {
set("belieferung", belieferung);
}
public String getBemerkung() {
return (String) get("bemerkung");
}
public void setBemerkung(String bemerkung) {
set("bemerkung", bemerkung);
}
public String getOeffnungszeiten() {
return (String) get("oeffnungszeiten");
}
public void setOeffnungszeiten(String oeffnungszeiten) {
set("oeffnungszeiten", oeffnungszeiten);
}
public void setStandort(StandortDTO standort) {
set("standort", standort);
}
public StandortDTO getStandort() {
return get("standort");
}
public Boolean getAblademoeglichkeit() {
return (Boolean) get("ablademoeglichkeit");
}
public void setAblademoeglichkeit(Boolean ablademoeglichkeit) {
set("ablademoeglichkeit", ablademoeglichkeit);
}
public InnendienstMaDTO getInnendienstMa() {
return get("innendienstMa");
}
public void setInnendienstMa(InnendienstMaDTO innendienstMa) {
set("innendienstMa", innendienstMa);
}
public AussendienstMaDTO getAussendienstMa() {
return get("aussendienstMa");
}
public void setAussendienstMa(AussendienstMaDTO aussendienstMa) {
set("aussendienstMa", aussendienstMa);
}
public int getVersion() {
return get("version");
}
public void setVersion(int version) {
set("version", version);
}
public Boolean isDataChanged() {
return dataChanged;
}
public void resetDataChanged() {
dataChanged = Boolean.FALSE;
}
}


My InnendienstMaDTO

package de.thewes.entrega.shared.dto;import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.ChangeEvent;
import com.extjs.gxt.ui.client.data.ChangeListener;
public class InnendienstMaDTO extends BaseModel implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 603144604755027667L;
private static Boolean dataChanged = Boolean.FALSE;
public InnendienstMaDTO() {
}
public InnendienstMaDTO(Long innendienstMaId, String bezeichnung,
String telefon, int version) {
set("innendienstMaId", innendienstMaId);
set("bezeichnung", bezeichnung);
set("telefon", telefon);
set("version", version);
}
{
addChangeListener(new ChangeListener() {
@Override
public void modelChanged(ChangeEvent event) {
dataChanged = Boolean.TRUE;
}
});
}
public Long getInnendienstMaId() {
return get("innendienstMaId");
}
public void setInnendienstMaId(Long innendienstMaId) {
set("innendienstMaId", innendienstMaId);
}
public String getTelefon() {
return get("telefon");
}
public void setTelefon(String telefon) {
set("telefon", telefon);
}
public String getBezeichnung() {
return (String) get("bezeichnung");
}
public void setBezeichnung(String bezeichnung) {
set("bezeichnung", bezeichnung);
}
public int getVersion() {
return get("version");
}
public void setVersion(int version) {
set("version", version);
}
public Boolean isDataChanged() {
return dataChanged;
}
}


What happens in my case:
The attribute innendienstMa of CustomerDTO is getting changed because a new entry in my ComboBox is selected. When the new selection happens I want the mentioned TextField to be updated.

I hope this clears things a bit?

Thanks for your effort!
Kind regards
Jan

sven
22 Sep 2011, 1:05 PM
Can you post a simplified testcase of what you are doing exactly? This testcase should implement EntryPoint. The code that changes your values is completely missing.