Results 1 to 5 of 5

Thread: Combobox does not list the values

  1. #1

    Default Combobox does not list the values

    Hello,

    I am new to extjs and struts2.
    I need to load a set of values from the server into a combobox inside a grid.
    The appropriate method is invoked (twice, I wonder why!!) at the server side on request, however at the browser side, the combobox is still empty.

    Any help is appreciated

    my jsp
    HTML Code:
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <script type="text/javascript" src="/Project/javaScript/createWP.js"></script>
    </head>
    <body>
    <div id="loadWP">
    </div>
    my java script
    Code:
    Ext.onReady(function() { // Initiate the quick tips. Ext.QuickTips.init(); var jsonReaderSuperWP = new Ext.data.JsonReader( { root : 'superwps', idProperty : 'id', successProperty : 'success', totalProperty : 'total', fields : [ { name : 'id' }, { name : 'swpName' }, { name : 'lowerLimit' }, { name : 'upperLimit' }, { name : 'category' }, { name : 'description' } ]
    }); var superWPDataStore = new Ext.data.JsonStore( { storeId: 'super-wps',
    baseParams : { type : "json",
    searchall : true }, url : "getallswps.action", method : 'POST', reader : jsonReaderSuperWP
    });
    var wpForm = new Ext.FormPanel( { standardSubmit : true, url : 'createWP',
    labelAlign : 'left', collapsible : true, title : WP details', bodyStyle : 'padding:5px',
    width : 970, items : [ { layout : 'column', border : false, items : [ {
    // removed other fields columnWidth : 0.5,
    layout : 'form',
    border : false, items : [ { xtype : 'combo', fieldLabel : 'Workpackage Category', name : 'category', anchor : '93%', allowBlank:false, store:superWPDataStore, loadingText: "loading", displayField:'category', valueField:'category', mode: 'remote', triggerAction: 'all', typeAhead: true, selectOnFocus:false, forceSelection:true, minChars: 3, lazyRenderer: true, resizable:true, emptyText: "select" } ]
    // removed other fields } ], buttons : [ {
    text : 'Save',
    }, { text : 'Cancel', } ]
    });
    wpForm.render('loadWP'); alert(superWPDataStore.getTotalCount()); // This says total count is zero even if I set "autoLoad: true" for the store !
    my Action class
    Code:
     
    
    public class SuperWorkPackageAction extends ActionSupport {
    /** *
    */ private Integer id = null;
    /** *
    */ private String swpName = null;
    /** *
    */ private Integer lowerLimit = null;
    /** *
    */ private Integer upperLimit = null;
    /** *
    */ private String category = null;
    /** *
    */ private String description = null;
    /** * The total number of rows to be read by the JSON reader
    */
    private int total = 0;
    /**
    *
    */
    private List superwps = new ArrayList();
    /** * The success or failure property to be read by the JSON reader */ private boolean success = true;
    /**
    *
    @return */ public String getAllSuperPackages() {
    System.out.println("getting all super packages");
    superwps = SuperWorkPackages.superWorkPackageList; System.out.println(superwps.size()); // this says the length is 3
    setTotal(superwps.size());
    setSuccess(true);
    return SUCCESS;
    }
    // setters and getters below }
    my struts.xml
    HTML Code:
    [LEFT]<!-- The package for json related actions -->
    <package name="jsondefault" extends="json-default">
    <!-- AJAX for all the super work packages -->
    <action name="getallswps" class="com.company.project.action.SuperWorkPackageAction"
    method="getAllSuperPackages">
    <result type="json"></result>
    </action>
    </package>
    [/LEFT]

  2. #2
    Sencha User vishalnnsingh's Avatar
    Join Date
    Sep 2010
    Location
    Kolkata, India
    Posts
    115

    Default See if this helps

    First of all i can't see nay grid in your .js file.
    Secondly I think there is a lot of redundant codes in your js file.

    Please replace
    Code:
    var superWPDataStore = new Ext.data.JsonStore( {
    storeId: 'super-wps', 
    baseParams : { type : "json",
    searchall : true }, url : "getallswps.action", method : 'POST', reader : jsonReaderSuperWP
    });
    with this

    Code:
    var superWPDataStore = new Ext.data.Store({
        reader: new Ext.data.JsonReader({
        //id is the valueField shud match the name in the json , //text is the display field
            fields:['id','text'],
            root:'rows'
            //your returned json shud be like this {rows:[{"id":"1","text":"Delhi"},{"id":"2","text":"Kolkata"}]}
        }),
        proxy: new Ext.data.HttpProxy({
            url: 'getallswps.action'
        })
        
    });
    and make sure your to replace existing value and displayfoeld config options with this or the names in your json object

    displayField:'text',
    valueField:'id',

    In the meantime please make sure that you are recieving the json with data without any errors to check your json, just copy paste it in jsonlint.com
    I Meet Challenge with Excitement & My Only Gossip is Love

  3. #3

    Default It works!!

    Thanks Vishal,

    Quote Originally Posted by vishalnnsingh View Post
    First of all i can't see nay grid in your .js file.
    I meant a form! Sorry.

    I just replaced the declaration
    Code:
    JsonStore
    with
    Code:
    Store
    and removed the

    Code:
     
    baseParams : {type : "json",
    
    searchall : true },
    as a starting point and it works like charm.
    Could you direct me towards the problem. Is it the redundant code?

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    1. JsonStore doesn't have a 'reader' property. It creates its own JsonReader from the config you specified. Since you specify your own reader, you need a plain Store.

    2. The combobox is configured as mode:'remote', so it will load the store when required. Alternatively, you could configure the store with autoLoad:true, but then you would configure the combobox as mode:'local'.

    3. Loading is asynchronous. You have to wait for the server to respond before you can query the result (which is why you got 0 from getTotalCount).

  5. #5

    Thumbs up

    Thanks Condor.

Similar Threads

  1. Combobox inner list not aligning list items propertly ?
    By ritesh.kapse in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 29 Oct 2010, 5:29 AM
  2. remote Combobox suggestions list full of empty values
    By raphinou in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 29 Oct 2009, 5:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •