在smartgwt的htmlflow中获取值文本框

时间:2013-09-26 16:53:42

标签: java html gwt smartgwt

我使用GWT的htmlflow为我的代码添加了一个动态文本框。现在我想从文本框中检索值。以下是代码,任何帮助将是可感知的。通过使用Rootpanel.get(elementID)。能够将元素值作为

O / p:

<input id="value1" 80px;="" border:="" 0px;="" border-bottom:="" 4px="" solid="" #3366ff;'="" type="textstyle='width:">

从中我如何掌握我在文本框中输入的值?

    String alertText = "If pressure > ? and glucoselevel > ? ";
     String newAlertText = alertText.replace("?", "");

    numberOfPlaceHolder = alertText.length() - newAlertText.length();
    System.out.println("Num of Place holder :"+numberOfPlaceHolder);

    String[] alertblock = alertText.split("\\?");           



    StringBuffer alertHtml = new StringBuffer();


   for(int i=1; i<=numberOfPlaceHolder;i++){   


       String textbox = "<input id='value"+i+"' type=textstyle='width: 80px; border: 0px;  border-bottom: 4px solid #3366FF;' />";
       String textblock = alertblock[i-1];
       alertHtml.append(textblock);
       alertHtml.append(textbox);              


   }



   String alertTextHtml = "<div>"+alertHtml.toString()+"</div>"; 

   htmlFlow = new HTMLFlow(alertTextHtml);

   alertTextLay.addMember(htmlFlow);

   IButton saveAlertBtn = new IButton();
   saveAlertBtn.setTitle("Save Alert");
    saveAlertBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // TODO Auto-generated method stub
            LinkedHashMap<String, String> alertValueMap = new LinkedHashMap<String, String>();
            for(int i=1; i<=numberOfPlaceHolder;i++){   

                System.out.println(**RootPanel.get("value"+i));**
                //System.out.println(DOM.getElementById("value"+i).getInnerText().toString());

            }
        }
    });

1 个答案:

答案 0 :(得分:1)

我认为你必须使用GWT Dom API获取元素并获取元素的属性

Element yourElement = DOM.getElementById(YOUR_TEXT_INPUT_ELEMENT);

 String the TextOfTheInput = yourElement.getAttribute("value");