Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:31:35+00:00 2026-05-31T22:31:35+00:00

I’m building dynamic forms in GWT, but I’m not sure how to dynamically retrieve

  • 0

I’m building dynamic forms in GWT, but I’m not sure how to dynamically retrieve the values upon submission.

I’m reading in question data from a DB and manually building elements that are added to a FormPanel:

    @UiField
    FormPanel formPanel;

    @Override
    protected void onLoad()
    {
       service.getFields(AysncCallbak<Fields> callback)
       {
           public void onSuccess(Fields result)
           {
              for(Object yo : fields.stuff())
              {
                  Element div = DOM.createDiv();
                  div.appendChild(DOM.createInputText());
                  formPanel.getElement().appendChild(div);
              }
           }
       }
    }

That’s the gist in psuedocode, but I’m not sure how to retrieve the values after this point.

I want to serialize the form (get the HTML) and parse it with DOM, but GWT produces invalid XHTML (the input tags are not terminated, causing parse failure).

I could send the data to a Servlet, but there’s a lot more stuff I need (other hidden input fields, etc.).

Most GWT form examples are incredibly trivial, or have explicit fields declared. Should I look at a 3rd party library? How do I get the dynamic values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:31:36+00:00Added an answer on May 31, 2026 at 10:31 pm

    GWT is not JSP. Not PHP.

    Using FormPanel is for beginners or for compatibility with existing form handling servlets, or for quick and dirty tasks. I have to admit, I might have forgotten how to use form panels.

    Once you’re up to speed with Forms, you would probably wish to move to RPC, RequestBuilder, or RES for submitting your data to the server.

    First, in GWT you should avoid getting the elements of widgets unless absolutely necessary (for example tweaking the behaviour thro JSNI).

    The following are some code which may not be too precise, but it gets the idea across.

    protected void onLoad() {
      HashMap<String, Widget> formWidgetHash = new HashMap<String, Widget>();
      FlexTable table = new FlexTable();
      FormPanel form = new FormPanel();
      form.setWidget(table);
    
      service.getFields(AysncCallbak<Fields> callback) {
        public void onSuccess(Fields result) {
          int i = 0;
          for(Object yo : fields.stuff()) {
            mkFormWidget(formWidgetHash, table, i++, yo);
          }
        }
      }
    }
    

    You could memorise the form in the HashMap. You can review the values by the pacing through the HashMap.

    But you don’t have to do that. Just submit the form. The form will resolve the fields.

    private void mkFormWidget(
      HashMap formWidgetHash, FlexTable table, int row, Object yo) {
    
      // LHS of table is field prompt
      String prompt = resolvePrompt(yo);
      table.setText(row, 0, prompt);
      Widget formWidget;
      if (yo instanceof Boolean){
        formWidget = new CheckBox();
      }
      else { ...
      }
      else { ...
      }
      else {
        formWidget = new TextBox();
      }
    
      table.setWidget(row, 1, w);
      formWidgetHash.put(prompt, w);
    }
    
    abstract protected String resolvePrompt(Object o);
    

    I don’t see why you need to access the widgets before sending the form to the server. If you need to add field validator, you should add it to the form widget while it is being instantiated in mkFormWidget.

    However, if you wish to have positional as well as hash key access to the form widgets, you could follow the answer in this question: Maps (collection) that maintains insertion Order in java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.