Announcement

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

    Need help in getting the form values which were created in loop

    Gurus,
    I have a form (text box added to form)created in a loop which is added to hlayout, and then hlayout is added to the vlayout. I have one more button called submit which is added to vlayout. when the user clicks the submit button, I should get all the values from the text boxes, I can get the lenght of the members but cant get the values of the text items. thanks in advance.

    please see the sample example.

    Code:
    	private VLayout vLayout = null;
    	private VLayout vLayout1;
    	private IButton button1;
    
    	public void onModuleLoad(){
    		
    		vLayout = new VLayout();
    
    		vLayout1 = new VLayout();  
    
    		HLayout hLayout = null;
    		DynamicForm form = null;
    		int counter = 0;
    		
    		button1 = new IButton("Submit");   
    	button1.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler(){
    			public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
    				HashMap<String, String> map = new HashMap<String, String>();
    				SC.say ("members lenght is"+vLayout.getMembers().length);
    				for (int i=1; i<vLayout.getMembers().length; i++){
    					//map.put("MARKS_"+i, vLayout.getValues()[i]);
    				}
    			}
    				
    		});
    		
    		for (int i=0; i < 3; i=i+1) {
    			hLayout = new HLayout();
    			hLayout.setAutoHeight();
    			
    			form = new DynamicForm();
    			++counter;
    			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);
    			form.setFields(txt1);
    			
    			hLayout.addMember(form);
    			vLayout.addMember(hLayout);
    			
    		}
    		vLayout1.addMember(vLayout);
    		vLayout1.addMember(button1);
    		vLayout1.draw();
    	}
    Last edited by contact77; 1 Jun 2010, 12:46.

    #2
    Code:
    for (int i = 0; i < vLayout.getMembers().length; i++) {
      for (int j = 0; j < vLayout.getMembers()[i].getMembers().length; j++) {
        if (vLayout.getMembers()[i].getMembers()[j] instanceof DynamicForm) {
          // Use vLayout.getMembers()[i].getMembers()[j].getValues()
        }
      }
    }

    Comment


      #3
      Thanks, some compile errors ( eg: vLayout.getMembers()[i].getMembers().length) was giving some compile time error, so I changed little bit but didn't help. Thanks in Advance

      Code:
      for (int i = 0; i < vLayout.getMembers().length; i++) {
       for (int j = 0; j < vLayout.getMembers()[i].getChildren().length; j++) {
          if (vLayout.getMembers()[i].getChildren()[j] instanceof DynamicForm) {
            SC.say(""+vLayout.getMembers()[i].getChildren()[j].getValuesManager());
          }
       }
      }
      Originally posted by svjard
      Code:
      for (int i = 0; i < vLayout.getMembers().length; i++) {
        for (int j = 0; j < vLayout.getMembers()[i].getMembers().length; j++) {
          if (vLayout.getMembers()[i].getMembers()[j] instanceof DynamicForm) {
            // Use vLayout.getMembers()[i].getMembers()[j].getValues()
          }
        }
      }
      Last edited by contact77; 1 Jun 2010, 12:49.

      Comment


        #4
        Sorry you need to perform the cast:
        Code:
        for (int i = 0; i < vLayout.getMembers().length; i++) {
          HLayout hLayout = (HLayout)vLayout.getMembers()[i];
          for (int j = 0; j < hLayout .getMembers().length; j++) {
            if (hLayout.getMembers()[j] instanceof DynamicForm) {
              DynamicForm form = (DynamicForm)hLayout.getMembers()[j];
              // Use form.getValues()
            }
          }
        }
        Note should probably do checks along the way (instanceof) type stuff, but this was a quick and dirty solution. Also can use Layout as more generic too.
        Last edited by svjard; 1 Jun 2010, 12:59.

        Comment


          #5
          Thanks !!!

          Originally posted by svjard
          Sorry you need to perform the cast:
          Code:
          for (int i = 0; i < vLayout.getMembers().length; i++) {
            HLayout hLayout = (HLayout)vLayout.getMembers()[i];
            for (int j = 0; j < hLayout .getMembers().length; j++) {
              if (hLayout.getMembers()[j] instanceof DynamicForm) {
                DynamicForm form = (DynamicForm)hLayout.getMembers()[j];
                // Use form.getValues()
              }
            }
          }
          Note should probably do checks along the way (instanceof) type stuff, but this was a quick and dirty solution. Also can use Layout as more generic too.

          Comment

          Working...
          X