Represents a hidden field for storing data in the user's browser that can be passed back to a handler as a "callback element".
Here is an example of how to use this widget:
function doGet() {
var app = UiApp.createApplication();
// Note that the name "appState" for callbacks, and the id "hidden" for
// getting a reference to the widget, are not required to be the same.
var hidden = app.createHidden("appState", "0").setId("hidden");
app.add(hidden);
var handler = app.createServerHandler("click").addCallbackElement(hidden);
app.add(app.createButton("click me!", handler));
app.add(app.createLabel("clicked 0 times").setId("label"));
return app;
}
function click(eventInfo) {
var app = UiApp.createApplication();
// We have the value of the hidden field because it was a callback element.
var numClicks = Number(eventInfo.parameter.appState);
numClicks++;
// Just store the number as a string. We could actually store arbitrarily complex data
// here using JSON.stringify() to turn a JavaScript object into a string to store, and
// JSON.parse() to turn the string back into an object.
app.getElementById("hidden").setValue(String(numClicks));
app.getElementById("label").setText("clicked " + numClicks + " times");
return app;
}
Internally, UiApp widgets are built on top of the Google Web Toolkit, and it can sometimes be helpful to look at the GWT documentation directly. You can find the Hidden documentation here.
Methods
| Method | Return type | Brief description |
|---|---|---|
getId() | String | Returns the id that has been assigned to this object. |
getTag() | String | Gets the text tag of this Hidden. |
getType() | String | Gets the type of this object. |
setId(id) | Hidden | Sets the id of this Hidden. |
setName(name) | Hidden | Sets the name of the Hidden, which is how it will be referred to when used in a
FormPanel or as a callback element on an event handler. |
setStyleAttributes(attributes) | Hidden | Sets this Hidden's style attributes. |
setTag(tag) | Hidden | Sets the text tag of this Hidden. |
setValue(value) | Hidden | Sets the value of this Hidden. |
Detailed documentation
getId()
Returns the id that has been assigned to this object.
This can be used in conjunction with app.getElementById() to retrieve a reference to this object.
Return
String — the id that has been assigned to this object
getType()
Gets the type of this object.
Return
String — the object type
setId(id)
Sets the id of this Hidden.
Parameters
| Name | Type | Description |
|---|---|---|
id | String | the new id, which can be used to retrieve the Hidden from
app.getElementById(id). |
Return
setName(name)
Sets the name of the Hidden, which is how it will be referred to when used in a
FormPanel or as a callback element on an event handler.
Parameters
| Name | Type | Description |
|---|---|---|
name | String | the new name. |
Return
setStyleAttributes(attributes)
Sets this Hidden's style attributes. This is a convenience method that is equivalent
to calling setStyleAttribute with every key/value pair in the attributes object.
// Change the widget's background to black and text color to green.
widget.setStyleAttributes({background: "black", color: "green"});
Parameters
| Name | Type | Description |
|---|---|---|
attributes | Object | the CSS attributes and values to set. |
Return
setTag(tag)
Sets the text tag of this Hidden.
Parameters
| Name | Type | Description |
|---|---|---|
tag | String | the new text tag, which can be anything you wish to store with the widget. |
Return
setValue(value)
Sets the value of this Hidden.
Parameters
| Name | Type | Description |
|---|---|---|
value | String | the new value. |