Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Getting the form values added to SectionStackSection and to SectionStack

    Gurus,
    I have added the form elemts to the form in a loop which is added to Hlayout and then to Vlayout whcih is added to SectionStackSection (created in loop) and then to SectionStack. ON click on the button, I should get the form values, I am struggling with this. thanks in advance. Throwing ClassCast Exception... please see the sample code

    Code:
    	private VLayout vLayout1;
    	private IButton button1;
    	private SectionStack ss1; 
    	private DynamicForm form1;
    	private VLayout vLayout;
    
    	public void onModuleLoad(){
    
    			ss1 = new SectionStack();  
    			ss1.setVisibilityMode(VisibilityMode.MULTIPLE);
    			ss1.setWidth(500);
    			ss1.setHeight(500);
    			ss1.setMargin(10);
    			ss1.setOverflow(Overflow.AUTO);
    
    			vLayout1 = new VLayout();  
    			
    			form1 = new DynamicForm();   
    			form1.setAlign(Alignment.LEFT);
    			
    			button1 = new IButton("Submit");   
    			button1.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler(){
    				public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
    					
    					int counter = 0;
    					//SC.say("SSS size is"+ss1.getSections().length);
    					for (int i = 0; i < ss1.getSections().length ; i++) {
    						++counter;
    						VLayout vLayout = (VLayout)ss1.getMembers()[i];
    						for (int j = 0; j < vLayout.getMembers().length ; j++) {
    							HLayout hLayout = (HLayout)vLayout.getMembers()[j];
    
    							for (int k = 0; k < hLayout .getMembers().length; k++) {
    								if (hLayout.getMembers()[j] instanceof DynamicForm) {
    									DynamicForm form = (DynamicForm)hLayout.getMembers()[k];
    									SC.say("form -"+form.getValueAsString("si1"));
    								}
    							}
    							
    							
    						}
    						
    					
    					}
    
    				}
    			});
    			
    
    
    			SelectItem si1 = new SelectItem();   
    			si1.setWidth(100);
    			si1.setName("si1");
    			si1.setTitle("Select");
    			si1.setDefaultToFirstOption(true);
    			LinkedHashMap<String, String> map1 = new LinkedHashMap<String, String>();
    			map1.put("select1", "select1");
    			map1.put("select2", "select2");
    			map1.put("select3", "select3");
    			si1.setValueMap(map1);
    
    			form1.setFields(si1);
    
    			SectionStackSection sss1 = new SectionStackSection();   
    			sss1.setTitle("Main ");   
    			sss1.setExpanded(true);
    			sss1.setCanCollapse(false);
    			sss1.addItem(form1);
    			
    			//ss1.addSection(sss1);
    			
    			for (int i=1; i <= 3; i=i+1) {
    				
    				vLayout = new VLayout();
    				vLayout.setAutoWidth();
    				vLayout.setAutoHeight();
    
    				HLayout hLayout = null;
    				DynamicForm form1 = null;
    				
    				CheckboxItem cb1 = new CheckboxItem();   
    				cb1.setDefaultValue(true);
    				cb1.setTitle("Section");
    				
    				DynamicForm form2 = new DynamicForm();   
    				form2.setWidth(50);   
     				form2.setFields(cb1);
    
    				SectionStackSection sss2 = new SectionStackSection("Section"+i);
    				sss2.setExpanded(true);
    				sss2.setControls(form2);
    				
    				for (int j = 0; j < 3; j = j+1) {
    					
    					hLayout = new HLayout();
    					hLayout.setAutoHeight();
    					hLayout.setAutoWidth();
    
    					form1 = new DynamicForm();
    					form1.setAlign(Alignment.LEFT);
    					form1.setAutoWidth();
    
    					TextItem txt1 = new TextItem(); 
    					txt1.setName("marks"+i); 
    					txt1.setStartRow(true);
    
    					if (i == 0){
    						txt1.setTitle("Marks");
    					} else {
    						txt1.setTitle("");
    					}
    					txt1.setWidth(200);
    					txt1.setValue(i);
    					txt1.setRequired(true);
    					form1.setFields(txt1);
    					
    					hLayout.addMember(form1);
    					vLayout.addMember(hLayout);
    				}
    				
    				sss2.addItem(vLayout);					
    				ss1.addSection(sss2);
    				
    			}
    
    			vLayout1.addMember(ss1);
    			vLayout1.addMember(button1);
    			vLayout1.draw();
    
    	}
    Last edited by contact77; 3 Jun 2010, 15:30.

    #2
    got it work i think...
    Code:
    				public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
    					
    					int counter = 0;
    					//SC.say("SSS size is"+ss1.getMembers().length);
    					for (int i = 0; i < ss1.getSections().length ; i++) {
    						SectionStackSection sss = (SectionStackSection)ss1.getSections()[i];
    						
    						for (int j = 0; j < sss.getItems().length ; j++){
    							VLayout vLayout = (VLayout)sss.getItems()[j];
    							
    							for (int k = 0; k < vLayout.getMembers().length ; k++) {
    								++counter;
    								HLayout hLayout = (HLayout)vLayout.getMembers()[k];
    
    								for (int l = 0; l < hLayout .getMembers().length; l++) {
    									if (hLayout.getMembers()[l] instanceof DynamicForm) {
    										DynamicForm form = (DynamicForm)hLayout.getMembers()[l];
    										SC.say("len-"+form.getValueAsString("marks1"));
    									}
    								}
    								
    								
    							}
    						}
    
    				
    					}
    
    				}
    			});

    Comment

    Working...
    X