-2

Hi am trying to display objectchoicefield by set of data in array.by selecting that comparing with other array automatically another objectchoicefield should get display with corresponding matches.i.e, onchange function, the other objectchoicefield should get load with values.guide me.

Document document=generalXmlAccess.access(generalXmlAccess.getArea());
NodeList list2=document.getElementsByTagName("tuple");  
final String[] area = new String [list2.getLength()];
final String[] areaid = new String [list2.getLength()];

for(int i=0;i<list2.getLength();i++) 
{
    NodeList list=document.getElementsByTagName("NAME");  
    NodeList list3=document.getElementsByTagName("ROW_ID"); 
    area[i]=list.item(i).getFirstChild().toString()+"-"+list3.item(i).getFirstChild().toString(); 
    areaid[i]=list3.item(i).getFirstChild().toString(); 
}

final ObjectChoiceField choiceField=new ObjectChoiceField("Select Area",area);    
choiceField.setChangeListener(new FieldChangeListener() {

public void fieldChanged(Field field, int context) {
    if(field.equals(choiceField))
    {
            int index=choiceField.getSelectedIndex();
            String values=areaid[index].toString(); 
            Document document1=generalXmlAccess.access(generalXmlAccess.getSubArea());
            NodeList list3=document1.getElementsByTagName("tuple");   
            for(int i=0;i<list3.getLength();i++)
            {
                subareaid=new String[list3.getLength()]; 
                NodeList nodeList=document1.getElementsByTagName("PAR_ROW_ID"); 
                if(nodeList.item(i).getFirstChild().toString().equals(values))
                {
                    NodeList list=document1.getElementsByTagName("NAME");
                    subareaid[i]=list.item(i).getFirstChild().toString();
                }
                add(new ObjectChoiceField("Subarea", subareaid)); 
            }
    }
}
});

choiceField.setFont(font1);
Nate
  • 30,589
  • 12
  • 76
  • 201
Pramodhini
  • 37
  • 5

1 Answers1

1

I think, following steps might guide you.

Step 1: Create first objectchoicefield with its data.

Step 2: Implement its field change listener, in which you will use the selected value of first choicefield as parameter to get the array of corresponding values to be set to second objectchoicefield ..

Ritesh Gune
  • 16,050
  • 6
  • 41
  • 70