Collect user supplied data after rendering

Help
Paul Pech
2011-11-24
2013-04-29
  • Paul Pech
    Paul Pech
    2011-11-24

    Hi,

    I'm new to all things Lobo/Cobra and I'm looking for help on the following task:

    - I want to display a html document with a couple of input field where the user may enter data after the page displays
    - Outside the htmlPanel there is a JButton which should output all data the user entered into the input fields of the html document when it's clicked

    private  static  LocalHtmlRendererContext rcontext;
    public static void main(String[] args) throws Exception {
    UserAgentContext uacontext = new LocalUserAgentContext();
            rcontext = new LocalHtmlRendererContext(uacontext);
            rcontext.navigate("file:///test.html");
    
                  htmlPanel = new HtmlPanel();
    
            JButton testb=new JButton("Test button");       
            testb.setSize(80, 40);
            testb.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e)
                {
                    
                    
                    NodeList test = rcontext.getCurrentDocument().getElementsByName("test_input");
                    for(int i = 0;i<test.getLength();i++) {
                        for(int j=0;j<test.item(i).getAttributes().getLength();j++)
                            System.out.println(test.item(i).getAttributes().item(j).getNodeName() + ": " + test.item(i).getAttributes().item(j).getNodeValue());
                    }
                }
            });
    
            htmlPanel.setPreferredWidth(800);
            htmlPanel.setDocument(startingDoc, rcontext);
    
            final JFrame frame = new JFrame();
            frame.getContentPane().add(testb);
            frame.getContentPane().add(htmlPanel);
            frame.getContentPane().validate();
    

    When the JButton is clicked, the original values of the input fields (those found in "test.html") with name "test_input" are listed, not the values the user entered into them.

    How can I get the user supplied data in those input fields?

    Any help is greatly appreciated,

    Paul