Figured someone might be interested.
-J
On Friday, January 14, 2011 7:57:30 PM UTC+1, Jirka wrote:
Hello all,--
I have a strange problem with my code not working when deployed even
though it works fine in my dev environment (Eclipse GWT plugin). It
is a simple widget in a dialog box that gets opened when one clicks on
a hyperlink in maps info window.
The widget has one ListBox and TextArea and when one switches item in
the ListBox it updates the TextArea with corresponding text and saves
the text from the TextArea that was selected before. The ListBox gets
its data via RPC from app engine on load and the data for the TextArea
is passed to the widget constructor on creation, previously also
fetched via RPC from the app engine. The ListBox represents area of
study, while the TextArea is a goal for that area.
My problem is that when deployed, switching items in the ListBox does
not switch the text at all. I debug this using Window.alert
onChange() and I know that the data the dialog gets from the app
engine are correct and are all there on load from another
Window.alert() debug box I put in. However when I switch items, the
Window.alert debug box says there are no goals set for that area of
study, even though when the dialog first loads, the debug box shows
they are all there. The first item selected does have correct text on
load but the rest is just gone. The ListBox data is also fine. Also
the data is there because it is also correctly displayed in the info
window. What is wrong? Where is the problem since it works fine in
my dev. environment but not when deployed?
Here is the code for the form
public class DotaznikForm extends Composite {
private final OkruhyServiceAsync okruhyService = GWT
.create(OkruhyService.class);
private final Dotaznik dotaznik;
private final List<Okruh> okruhy = new LinkedList<Okruh>();
private VerticalPanel vp = new VerticalPanel();
private final TextArea textCile = new TextArea();
private final ListBox okruhyListBox = new ListBox();
private int lastSelected;
DotaznikForm(Dotaznik d) {
this.dotaznik = d;
((ServiceDefTarget) okruhyService)
.setServiceEntryPoint("/ volebnicile/okruhyService");
okruhyService.getOkruhy(new AsyncCallback<Okruh[]>() {
@Override
public void onSuccess(Okruh[] result) {
// The first debug alert on load
StringBuffer s=new StringBuffer("Number of cilu:
"+dotaznik.getCile().size()+"\n\n");
for (Cil c:dotaznik.getCile())
s.append("ID: "+c.getId()+" ---> "+c.getTextCile()+"\n");
Window.alert(s.toString());
for (Okruh o : result) {
okruhyListBox. addItem(o.getPopisOkruhu());
}
okruhy.addAll(Arrays.asList( result));
okruhyListBox. setSelectedIndex(0);
if (!dotaznik.getCile().isEmpty() ) {
textCile.setText(getCilByOkruh( getSelectedOkruh()). getTextCile());
}
okruhyListBox.setWidth(" 50em");
textCile.setSize("50em", "30em");
okruhyListBox. addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
setLastSelected(okruhyListBox. getSelectedIndex());
}
});
okruhyListBox. addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
saveDotaznik();
updateDotaznikForm();
}
});
vp.setSpacing(5);
vp.add(okruhyListBox);
vp.add(textCile);
}
@Override
public void onFailure(Throwable caught) {
Window.alert("getOkruhy: There was an error getting data from
server");
}
});
initWidget(vp);
}
private void updateDotaznikForm() {
Cil c = getCilByOkruh(getSelectedOkruh());
if (c != null) {
Window.alert("Cil: "+c.getTextCile()+"\nOkruh:
"+getSelectedOkruh().getPopisOkruhu());
textCile.setText(c. getTextCile());}
else {
Window.alert("Pro Okruh "+getSelectedOkruh(). getPopisOkruhu()+"neni
definovan zadny cil");
textCile.setText("");}
}
private Cil getCilByOkruh(Okruh o) {
if (dotaznik.getCile() != null)
for (Cil c : dotaznik.getCile())
if (c.getOkruhKey() == o.getId())
return c;
return null;
}
private Okruh getOkruhByPopis(String popis) {
for (Okruh o : okruhy)
if (o.getPopisOkruhu().equals(popis))
return o;
return null;
}
private Okruh getSelectedOkruh() {
return getOkruhByPopis(okruhyListBox.getItemText(okruhyListBox
.getSelectedIndex()));
}
private void saveDotaznik() {
Okruh o =
getOkruhByPopis(okruhyListBox.getItemText(getLastSelected()) );
if (this.dotaznik.getCile().isEmpty() && !
textCile.getText().equals(""))
this.dotaznik.addCil(new Cil(textCile.getText(), o));
else {
Cil c = getCilByOkruh(o);
if (c == null && !textCile.getText().equals(""))
this.dotaznik.addCil(new Cil(textCile.getText(), o));
else if (c != null && !textCile.getText().equals(""))
c.setTextCile(textCile. getText());
else
dotaznik.deleteCil(c);
}
}
protected void closeDotaznik() {
if (textCile.getText().equals(""))
dotaznik.deleteCil( getCilByOkruh( getSelectedOkruh()));
else {
Cil c=getCilByOkruh(getSelectedOkruh());
if (c==null)
dotaznik.addCil(new Cil(textCile.getText(), getSelectedOkruh()));
else
c.setTextCile(textCile. getText());
}
}
protected Dotaznik getDotaznik() {
return this.dotaznik;
}
private void setLastSelected(int i) {
lastSelected = i;
}
private int getLastSelected() {
return lastSelected;
}
}
and here is a code that creates it and shows it in a dialog
@Override
public void onClick(ClickEvent event) {
ds.getDotaznik(o.getDotaznikId(), new AsyncCallback<Dotaznik>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(" getDotaznik: There was an error getting data from
server");
}
@Override
public void onSuccess(Dotaznik result) {
DotaznikForm dotaznikForm;
if (result == null)
dotaznikForm = new DotaznikForm(new Dotaznik());
else
dotaznikForm = new DotaznikForm(result);
VerticalPanel dotaznikPanel = new VerticalPanel();
HorizontalPanel buttonPanel = new HorizontalPanel();
Button closeButton = new Button("Ukoncit");
closeButton. addClickHandler(new CloseClickHandler(o,
dotaznikForm));
buttonPanel.add( closeButton);
dotaznikPanel.add( dotaznikForm);
dotaznikPanel.add( buttonPanel);
dotaznikDialog. setWidget(dotaznikPanel);
dotaznikDialog. center();
dotaznikDialog.show( );
}
});
}
}
Thanks in advance for any help.
-Jirka
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/NRXL0khVnGoJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment