Dynamcially adding panels based on DropdownChoice selection - wicket

am a newbie to wicket and am experimenting few things with it, like, I have four panel but one only should be added based on the selection made in the DropdownChoice component.
i tried to add panels using onSelectChange() method, but it doesn't work. can any one please help me out with proper sample code.

I give you an example for this problem. Hope it helps.
DropDownChoice dropDown = new DropDownChoice(...........);
AjaxFormComponentUpdatingBehavior behavior = new AjaxFormComponentUpdatingBehavior(
"onchange") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
//you should write here the logic that
// replaces the panel, something like: content.addOrReplace(panel)
target.addComponent(form);
}
};
dropDown.add(behavior);
So that's all, you have to use AjaxFormComponentUpdatingBehavior to handle onchange event. If the dropdown menu not a requirement, you can use tabbedpanel. Here you can find the sample code: wicket tabbed panel

Related

How to refresh GXT's combo box after each call

I have a combo box. When I click a link, it opens a popup including a combo box (with data loaded from database). It always keeps data from the first call (it does not refresh).
How can I refresh this?
VerticalPanel vp = new VerticalPanel();
vp.setSpacing(10);
ListStore<State> states = new ListStore<State>();
states.add(getStates());
ComboBox<State> combo = new ComboBox<State>();
combo.setEmptyText("Select a state...");
combo.setDisplayField("name");
combo.setWidth(150);
combo.setStore(states);
combo.setTypeAhead(true);
combo.setTriggerAction(TriggerAction.ALL);
vp.add(combo);
Assuming, that you are working with GXT and there fore are using the GXT Window class, you can do something like this:
myWindow.addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() {
#Override
public void onBeforeShow(BeforeShowEvent event) {
mxComoBox.clear();
}
});
You see the old value, because a popup will be reused. so you have to clear the value of the combo, when the popup get visible.
This code should work with GXT 3.1.2. Older versions of GXT might have a different coding.
Hope that helps.

Gwt, How to code the Right-ClickHandler for Label?

Ok, for label, we got ClickHandler, ie, when we click on the label it will do something.
But I want to do something like Right-ClickHandler for Label, ie, when user right click on the label, it will do something.
Some people say put the widget into DeckPanel & do the RightClick Hanler on it. But if we have a lot of labels, then
does each label have to be put into a deck panel?
If that is the case then the code maybe complicated, so I want to do the RightClick handler for label just like i do normal ClickHandler. How to do do?
I am heavily recommending this example (Which is bit old but the right way to deal with context menu).
lable.sinkEvents(Event.ONCONTEXTMENU);
lable.addHandler(
new ContextMenuHandler() {
#Override
public void onContextMenu(ContextMenuEvent event) {
event.preventDefault();
event.stopPropagation();
popupMenu.setPopupPosition( //custom menu here
event.getNativeEvent().getClientX(),
event.getNativeEvent().getClientY());
popupMenu.show();
}
}, ContextMenuEvent.getType())
Continue reading ....

Cannot uncheck checkbox in smartgwt listgrid

I'm breaking my head since a whole day now but cannot find a solution, I hope someone can help me.
I'm trying to create a simple SmartGWT ListGrid with checkboxes and for some reason I can only check checkboxes but not uncheck them.
Once the checkbok is checked there is no way to uncheck it.
Below the code I'm using to create the grid.
Here I first instantiate the grid that is populated later with a call to the server.
Any idea of what I'm doing wrong? Anything wrong with the initialisation maybe?
Thanks in advance!!
[...]
ListGrid hotelsGrid = new ListGrid();
hotelsGrid.enableHiliting(false);
hotelsGrid.setCanSort(false);
hotelsGrid.setCanResizeFields(false);
hotelsGrid.setShowHeader(false);
hotelsGrid.setAutoFitData(Autofit.BOTH);
hotelsGrid.setStyleName("selectGrid");
hotelsGrid.setCanEdit(false);
hotelsGrid.setShowHover(false);
hotelsGrid.setShowRollOver(false);
hotelsGrid.setShowSelectedStyle(false);
hotelsGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
[...]
private void initGrid(String[] sParams){
ListGridField flagField = new ListGridField("flagField", "Status", 40);
flagField.setAlign(Alignment.CENTER);
flagField.setType(ListGridFieldType.IMAGE);
flagField.setImageURLPrefix("flags/");
flagField.setImageURLSuffix(".png");
ListGridField textField = new ListGridField("textField", "Meaning");
hotelsGrid.setFields(flagField, textField);
hotelsGrid.setData(getSelectRecords(sParams));
}
It's not clear how your code sample above is related to a clickable checkbox - your code doesn't make any attempt to create a field with checkboxes??
All you need to do to get a clickable checkbox is declare a field of type "boolean" and setCanToggle(true). setCanToggle(true) allows it to be toggled with one click without needing to have editing enabled for any other fields.

GWT ClickableTextCell

I am a newbie to GWT ... need some help in understanding the below class -
What is the use of GWT ClickableTextCell ??
Is there something specific use of it. It uses something called FieldUpdater, why is that used ?
Think of a ClickableTextCell as hot spot. It looks like a regular bit of screen real estate with text in it, but it responds to clicks. What happens when you click it? The click "updates" the field. An update to a field calls the method update(). What does update() do? Whatever you want it to. You provide it by specifying the FieldUpdater. FieldUpdater is an interface, so you can construct one anonymously. Say you have a CellTable, and you have a Column that displays a String inside a ClickableTextCell. You provide your FieldUpdater to the Column:
Column<DataType, String> myIntegerColumn
= new Column<DataType, String>(new ClickableTextCell());
myIntegerColumn.setFieldUpdater(new FieldUpdater<DataType, String>(){
#Override
public void update(int index, DataType object, String value){
// execute code that reacts to a click on this hot spot
}
});
Now whenever the cell gets clicked, that code in update() fires.
A ClickableTextCell is a specific kind of cell. You can see a demo of all the different kinds of cells in this GWT showcase.
This GWT documentation explains what cell widgets are for, goes over all of the different types, and also has examples of how to use them and the ValueUpdater type.

Gwt get Components

I have a Vertiacal panel object and This object contains many radiobuttons
So can i get those radioButton objects through Vertiacal panel object.
Maybe via iteration or ?
private void initCourse() {
coursePopupPanel.clear();
VerticalPanel verticalPanel = new VerticalPanel();
coursePopupPanel.setWidget(verticalPanel);
JsArray<JCourse> jCourseArray = JCourse.getList(stringMainData);
for (int i = 0; i < jCourseArray.length(); i++) {
final RadioButton courseRadioButton = new RadioButton("course");
courseRadioButton.setText(jCourseArray.get(i).getName());
courseRadioButton.getElement().setId(jCourseArray.get(i).getView());
verticalPanel.add(courseRadioButton);
//handler of course radio buttons
courseRadioButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
}
});
}
}
I have a reference to coursePopupPanel. but i have not reference to vertical panel, so can i get elements of vertical panel sonce holding reference to coursePopupPanel.
A GWT VerticalPanel is a subclass of ComplexPanel, an abstract class for Panels that contain more than one child widget. In ComplexPanel (and so inherited by VerticalPanel) are methods for getting the number of child widgets, getting references to them by index, and so on. You could build an iterator something like this:
Iterator<Widget> vPanelWidgets = myVerticalPanel.iterator();
while (vPanelWidgets.hasNext()){
Widget childWidget = vPanelWidgets.next();
if (childWidget instanceof RadioButton) {
...do stuff
}
}
I tend not to query a widget for its members. That ties me to the decisions I made about how to display the RadioButtons, following your example. What if you decide later to display your radio buttons in the cells of a FlexTable in order to control vertical and horizontal arrangement? To make that change means your widget iterator won't work. FlexTable is a Panel but not a ComplexPanel. The code I wrote above won't work if you decide to replace the VerticalPanel with a FlexTable.
If was to take something like this approach, I would keep my lists of related widgets (like a group of RadioButtons) in some sort of Java Collection. I pass that Collection to my presentation class, and inside there I write the code to do the layout. Usually that's a UiBinder class, with "#UiField(provided = true)" for these RadioButtons. The code in the presenter then associates the RadioButton elements of the Collection I passed in to the UiField placeholders for the RadioButtons in the UiBinder layout. So all my layout decisions are actually in the UiBinder xml file. If I decide to rip out my Vertical Panel and replace it with a FlexTable, I might not have to touch a single line of Java code, assuming I separated things out correctly.
[Actually, I would probably keep my decision to use RadioButtons inside the presentation layer, and inside the XML file in particular. That presentation class would fire a message on the EventBus to indicate the user had made a selection via a RadioButton ValueChangeHandler, and I wouldn't care if I used RadioButtons in a VerticalPanel or ToggleButtons in a FlexTable.]
You're not being to specific, add more details and maybe a code example.
I'm gonan try to guesstimate what you're trying to say here: You have a verticalPanel object. To it you add several radioButton objects. Later you want to retrive those radioButton objects (to maybe check if they're selected or not), right? There's several ways to do this. At any rate, why don't you check the code examples at the Gwt Showcase site here:
http://gwt.google.com/samples/Showcase/Showcase.html?locale=en_UM#!CwRadioButton
it has tons of visual examples, each with the attached code and css.
Since PopupPanel implements HasOneWidget interface you can coursePopupPanel.getWidget() to get a reference to your verticalPanel. And iterate widgets in it simply using
for (Widget w : verticalPanel){
//Do Stuff
}