PDA

View Full Version : [FIXED] form.isValid()



trophytoolbox
2 May 2008, 6:00 AM
Hi,

I was modifying your FormPanelPage() and the following code throws the below error after isValid() returns true.


panel.addButton(new Button("Save", new SelectionListener()
{
public void componentSelected(ComponentEvent ce)
{
if (panel.isValid())
{
Dialog simple = new Dialog();
simple.setHeading("Form is Valid");
simple.addText(TestData.DUMMY_TEXT_SHORT);
simple.setScrollMode(Scroll.AUTO);
simple.show();
}
}
}));
[ERROR] Uncaught exception escaped
java.lang.NullPointerException: null
at com.extjs.gxt.ui.client.widget.form.Field.getRawValue(Field.java:201)
at com.extjs.gxt.ui.client.widget.form.Field.isValid(Field.java:274)
at com.extjs.gxt.ui.client.widget.form.FormPanel.isValid(FormPanel.java:80)
at com.extjs.gxt.samples.explorer.client.pages.FormPanelValidatePage$3.componentSelected(FormPanelValidatePage.java:178)
at com.extjs.gxt.ui.client.event.TypedListener.handleEvent(TypedListener.java:48)
at com.extjs.gxt.ui.client.util.EventTable.sendEvent(EventTable.java:72)
at com.extjs.gxt.ui.client.util.Observable.fireEvent(Observable.java:94)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:434)
at com.extjs.gxt.ui.client.widget.Button.onClick(Button.java:452)
at com.extjs.gxt.ui.client.widget.Button.onComponentEvent(Button.java:249)
at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:663)

trophytoolbox
2 May 2008, 6:11 AM
If I comment out the following the dialog shows:


//if (panel.isValid())
//{
Dialog simple = new Dialog();
simple.setHeading("Form is Valid");
simple.addText(TestData.DUMMY_TEXT_SHORT);
simple.setScrollMode(Scroll.AUTO);
simple.show();
//}

plusminus
2 May 2008, 11:11 AM
With me it happens only in the Debug-Shell where the "RadioGroups"s produces a NPE with (if I remember right) getValue somewhere deep inside :(

darrellmeyer
2 May 2008, 1:15 PM
If either you can post some sample code in the correct format (http://extjs.com/forum/showthread.php?t=33778), we will take a look.

trophytoolbox
5 May 2008, 5:51 AM
Here you go... Run this and then click the Simple button after you have entered form data. If you comment out the line in the code below, then the error does not occur. Looks like its something to do with isValid and the radio buttons?

// comment out the radio widget and it works fine


/*
* Ext GWT - Ext for GWT
* Copyright(c) 2007, 2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
package com.companioncabinet.ccs.gui.gwt.client.pages;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Button;
import com.extjs.gxt.ui.client.widget.Container;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.TimeField;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;

public class FormPanelTestPage extends Container implements EntryPoint
{

public void onModuleLoad()
{
RootPanel.get().add(this);
}

@Override
protected void onRender(Element parent, int pos)
{
super.onRender(parent, pos);

final FormPanel panel = new FormPanel();
panel.setFrame(true);
panel.setFieldWidth(210);
panel.setLabelWidth(100);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setHeading("Simple Form");
panel.setIconStyle("icon-form");
panel.setWidth(400);
panel.setStyleAttribute("padding", "20");

final TextField textField = new TextField();
textField.setFieldLabel("Name");
textField.setEmptyText("Enter your full name");
textField.setAllowBlank(false);
textField.setMinLength(4);
textField.setValidator(new Validator()
{

public String validate(final Field field, String value)
{

return null;

}
});
panel.add(textField);

NumberField number = new NumberField();
number.setFieldLabel("Age");
number.setEmptyText("Enter your age");
number.setAllowBlank(false);
panel.add(number);

TextField text = new TextField();
text.setFieldLabel("Email");
panel.add(text);

DateField date = new DateField();
date.setFieldLabel("Birthday");
date.setWidth(210);
panel.add(date);

TimeField time = new TimeField();
time.setFieldLabel("Time");
time.setWidth(200);
panel.add(time);

CheckBox check1 = new CheckBox();
check1.setBoxLabel("Classical");

CheckBox check2 = new CheckBox();
check2.setBoxLabel("Rock");
check2.setChecked(true);

CheckBox check3 = new CheckBox();
check3.setFieldLabel("Blue");

CheckBoxGroup checkGroup = new CheckBoxGroup();
checkGroup.setFieldLabel("Music");
checkGroup.add(check1);
checkGroup.add(check2);
checkGroup.add(check3);
panel.add(checkGroup);

Radio radio = new Radio();
radio.setName("radio");
radio.setFieldLabel("Red");
radio.setChecked(true);

Radio radio2 = new Radio();
radio2.setName("radio");
radio2.setFieldLabel("Blue");

RadioGroup radioGroup = new RadioGroup("test");
radioGroup.setFieldLabel("Favorite Color");
radioGroup.add(radio);
radioGroup.add(radio2);

// comment out the radio widget and it works fine
panel.add(radioGroup);

panel.addButton(new Button("Simple", new SelectionListener()
{
public void componentSelected(ComponentEvent ce)
{
if (panel.isValid())
{
Window window = new Window();
window.setHeading("Simple Window");
window.setWidth(250);
window.addText("test data");
window.setScrollMode(Scroll.AUTO);
window.show();
}
}
}));

add(panel);
}

}

darrellmeyer
20 May 2008, 8:58 PM
I tested your code with beta 3 and it works fine.