开始使用智能gwt

时间:2011-05-04 15:31:38

标签: autocomplete combobox module smartgwt

我正在使用智能gwt 2.4开发一个小型应用程序。我选择智能gwt优于其他特定于HTML的RIA,因为它具有丰富的ui并避免跨浏览器问题。 我的应用程序中有2页。最初,用户在第1页中输入的详细信息用于获取必须在第2页中显示的数据,从那时起,必须在第2页本身进行任何必须进行的更改。用户无需导航回第1页以获取新的数据集。 1)现在,我如何在页面之间导航。我已将这些页面定义为两个单独的模块。我需要将数据从第1页传递到第2页。有没有一种有效的方法可以做到这一点? 2)在我的一个页面中,我定义了两个自动完成组合框。其中一个组合框的数据将在加载时获取,而第二个组合框的数据将取决于第一个组合框的值。我尝试为第一个组合框添加更改并更改事件侦听器,但是每个字母类型都会触发这两个事件。我需要在用户选择值后获取数据。

public void onModuleLoad() 
{ 
        final ComboBoxItem category = new ComboBoxItem("categoryName", "Category");  
        category.setTitle("Select");  
        category.setChangeOnKeypress(false) ;
        category.setType("comboBox");  
        category.setWidth(250);
        category.setIcons(icon);
        category.setChangeOnKeypress(false);
        final ComboBoxItem subCategory = new ComboBoxItem("subCategoryName", "Sub Category");  
        subCategory.setTitle("Select");  
        subCategory.setType("comboBox");  
        subCategory.setWidth(250);
        subCategory.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler()
        {
            @Override
            public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) 
            {
                    // call to servlet[url] to get the sub categories for the selected category.
                    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, "url"+ selectedCategoryName);
                    try {
                        requestBuilder.sendRequest(null, new RequestCallback() {

                            @Override
                            public void onResponseReceived(Request request, Response response) 
                            {
                                   String xmlText = response.getText();
                                   // Code to handle the received response.
                            }

                            @Override
                            public void onError(Request request, Throwable exception) 
                            {
                                exception.printStackTrace();

                            }});
                    } catch (RequestException e) {
                        e.printStackTrace();
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                    }


            }
        });
        category.addChangeHandler(new ChangeHandler() 
        {
            @Override
            public void onChange(ChangeEvent event) 
            {
                if(null!=event.getValue() && event.getValue()!="")
                {
                    selectedCategoryName = event.getValue().toString();
                    System.out.println(selectedCategoryName);
                }
            }
        });
}

这里我有一个组合框类别,其值将在加载时获取。当用户通过在组合框中键入类别来选择类别时,控件通过在下拉列表中显示匹配的值来帮助。对于每一次按键,事件都会被解雇。我添加了一个syso来打印输入的值。我只需在用户选择类别时获取子类别。

任何指针都非常有用。 感谢

1 个答案:

答案 0 :(得分:1)

关于第二个问题:根据您的需要,我认为您可以按照link实施模块。 或者,如果您想通过处理已更改的事件自行实现,要在每次按键时停止触发更改事件,您可以使用此选项:

comboBoxItem.setChangeOnKeypress(false);
相关问题