Introduction
In this blog, we are going to learn what a suggested box is and how we implement a Hidden widget using GWT, and also we will get to know about some inbuilt methods of GWT that will assist us in efficiently implementing it. But before that let's get to know about GWT.
GWT

A development toolkit called GWT enables programmers to create internet or web applications. For typical web-app chores like bookmarking, UI abstraction, cross-browser compatibility, etc., GWT insists on reusable techniques. It offers characteristics like:
- Because GWT solves browser incompatibilities through various bindings, developers do not need to be experts in this area.
- The client and server code bases for GWT are the same.
- Java was the platform of choice for GWT because it offers features like code navigation and refactoring that make development more efficient.
- GWT MVP (Model View Presenter) enables collaborative working and more rapid JUnit testing. By adding events to the event bus, the client-side program can make several modifications.
- It enables the integration of numerous Java technologies, including hibernate via gilead.
GWT Hidden Widget
A hidden field in an HTML form is represented by the Hidden widget. It means any data we will send this particular field of HTML will not be present on the screen instead that will get saved on the client side.
Constructor methods available for the hidden widget class:
Sr,no |
Constructor |
1 |
Hidden()
constructor for Hidden. |
2 |
Hidden (Element element)
Subclasses may explicitly use an existing element using this function Object() { [native code] }. |
3 |
Hidden (java.lang.String name)
constructor for Hidden. |
4 |
Hidden(java.lang.String name, java,lang.String value)
constructor for Hidden. |
Following are the methods available for the Hidden widget class in GWT:
Sr.no |
Methods name and Description |
1 |
java.lang.String getDefaultValue()
gets the hidden field's default value. |
2 |
java.lang.String getID()
Obtains the hidden field's ID. |
3 |
java.lang.String getName()
obtains the hidden field's name. |
4 |
java.lang.String getValue()
get the hidden field's value. |
5 |
void setDefaultValue(java.lang.String defaultValue)
sets the hidden field's default value. |
6 |
void setID(java.lang.String id) establishes the concealed field's id. |
7 |
void setName(java.lang.String name)
establishes the concealed field's name. |
8 |
void setValue(java.lang.String value)
sets the hidden field's value |
9 |
static Hidden wrap(Element element)
surrounds an existing input type='hidden'> element in a Hidden widget that is created. |
The changed Style Sheet file war/Helloworld.css are listed below.
body {
text-align: center;
font-family: verdana, sans-serif;
}
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
Here is what the amended HTML host file war/HelloWorld.html contains
<html>
<head>
<title>Hello World</title>
<link rel = "stylesheet" href = "Helloworld.css"/>
<script language = "javascript" src = "helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>Hidden Widget Demonstration</h1>
<div id = "gwtContainer"></div>
</body>
</html>
Let's look at the code in the Java file src/com.hellofriend/Helloworld.java that uses the Hidden widget.
package com.hellofriend.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
public class Helloworld implements EntryPoint {
public void onModuleLoad() {
//create textboxes
final TextBox textBox = new TextBox();
textBox.setWidth("275");
Button button1 = new Button("Set Value of Hidden Input");
Button button2 = new Button("Get Value of Hidden Input");
final Hidden hidden = new Hidden();
button1.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
hidden.setValue(textBox.getValue());
Window.alert("Value of Hidden Widget Updated!");
}
});
button2.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("Value of Hidden Widget: " + hidden.getValue());
}
});
// Add widgets to the root panel.
VerticalPanel panel = new VerticalPanel();
panel.setSpacing(10);
panel.add(textBox);
panel.add(button1);
panel.add(hidden);
panel.add(button2);
RootPanel.get("gwtContainer").add(panel);
}
}Output






