I have a ModalWindow which has a form, which has a TabbedPanel, which has two AbstractTabs which, on which there is a DataTable on each of them, with input elements.
So: ModalWindow > Form > TabbedPanel --> Tab1 (Panel) > DataTable (there are two tabs)
Within the ModalWindow, I added to the form 3 buttons, like the following:
// save button
final GbAjaxButton save = new GbAjaxButton("save") {
private static final long serialVersionUID = 1L;
#Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
System.out.println("Saving something... ");
}
};
I can see the data being sent via POST to the backend, but I can't seem to be able to access any of the fields in the DataTables.
Some parts for the code are:
tabA = new AbstractTab("Tab Name") {
public Panel getPanel() {
return new SomeNewPanel(panelId,<somedata>); // <-- this has the DataTable with inputs
}
}
Form form = new Form("formNameInHtml");
form.add(new TabbedPanel("htmlName", tabs);
I would really appreciate some insight on this problem.
Thanks.
From ModalWindow javadoc, "If you want to use form in modal window component make sure that you put the modal window itself in another form (nesting forms is legal in Wicket) and that the form on modal window is submitted before the window get closed."
Wicket automatically adds a form outside the modal window, so if you want to use a second form inside you should override org.apache.wicket.markup.html.form.Form#isRootForm() and have it return true.
Related
Im populating a table using ListView component in wicket.The last column of my table is button. So for each row I'll have a button in the last column.What I'm trying to implement is onlick of the button I need to delete the appropriate row. So for this I need to get the current index of the list on click of button. How to achieve/get this ?
I would extend Ajax button and pass the row reference (item) in the constructor...then you can do anything you want..by overriding the onSubmit method
Example:
private class SpecialButton extends AjaxButton {
final Item<Object> rowItem;
public SpecialButton(final String id, final Item<Object> rowItem) {
super(id);
this.rowItem = rowItem;
}
#Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
// here you cand do everything you want with the item and the model object of the item.(row)
Object object = rowItem.getModelObject();
}
}
You should replace Object from Item<Object> with your reapeater model. After creating this private class you can reuse it for every row in your repeater.
If you want to delete that row you just have to remove the model from the list used to generate the repeater and refresh the repeater container(Wicket does not allow you to refresh the repeater by adding it to the target...instead you have to add the repeater continer.)
Have a look at the repeaters Wicket Examples page to understand how to use ListView and other repeaters:
http://www.wicket-library.com/wicket-examples/repeater/
You can get the current index of the list from item.getIndex()
protected void populateItem(final ListItem<T> item) {
int index = item.getIndex();
...
Look here for inspirations on how to do it properly (without index):
Wicket ListView not refreshing
I am using GWT 2.4. I have a Suggestbox and I have a requirement to hide the suggestion list under certain cases. The context is as below.
After user selects a suggestion from suggestion list, I am populating two other text box fields, with values corresponding to the selection. For example, suppose the suggestbox contains user-names, and user selects a user-name from suggestions, then other two fields, say user address and email are populated in two other text boxes. These two fields are read only now. Then user clicks on an 'Edit' button. Now the user can edit either user- name ( ie edit in suggestion box), user address and email. It doesn't make sense to show the suggestions again when the user is editing the user-name, since the user has already selected the user and decided to edit it. In a nutshell my SuggesBox should behave as a normal text box. I tried following code, (I know hideSuggestionList() is deprecated) but its not working.
display.getSuggestBox().hideSuggestionList();
Reading the javadoc for hideSuggestionList() it is said that, "Deprecated. use DefaultSuggestionDisplay.hideSuggestions() instead". I don't know how to use DefaultSuggestionDisplay, and I'm using SuggestBox with 'MultiWordSuggestOracle'.
Thanks for helping me out!!
What you can do is simply swap the SuggestionBox with a normal TextBox when the user clicks edit and back when edit is closed. Also because if you would hide the suggestions list, it still queried from the server. By swapping the widget you don't have to care about side effects. SuggestionBox itself uses also a TextBox and thus for the user it's not visible the widget has changed.
If you don't use your own SuggestionDisplay, then this should Just Workâ˘:
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
Here is the Solution
My Entry Point Class
public class SuggestionEntryPoint implements EntryPoint {
#Override
public void onModuleLoad() {
SuggestBoxWidget suggestBoxWidget = new SuggestBoxWidget();
RootPanel rootPanel = RootPanel.get();
suggestBoxWidget.createOracle();
suggestBoxWidget.createWidgetAndShow(rootPanel);
rootPanel.add(suggestBoxWidget);
DOM.getElementById("loader").removeFromParent();
}
}
And here is my Widget
public class SuggestBoxWidget extends Composite {
private TextBox textSuggestBox = new TextBox();
private SuggestBox suggestBox = null;
DefaultSuggestionDisplay suggestionDisplay = new DefaultSuggestionDisplay();
MultiWordSuggestOracle suggestOracle = new MultiWordSuggestOracle();
private static SuggestBoxWidgetUiBinder uiBinder = GWT
.create(SuggestBoxWidgetUiBinder.class);
interface SuggestBoxWidgetUiBinder extends
UiBinder<Widget, SuggestBoxWidget> {
}
public SuggestBoxWidget() {
initWidget(uiBinder.createAndBindUi(this));
}
public void registerEvents(){
suggestBox.addKeyUpHandler(new KeyUpHandler() {
#Override
public void onKeyUp(KeyUpEvent event) {
if(suggestBox.getText().equalsIgnoreCase("1")){
suggestionDisplay.hideSuggestions();
}
}
});
}
public void createWidgetAndShow(HasWidgets container){
suggestBox = new SuggestBox(suggestOracle,textSuggestBox,suggestionDisplay);
container.clear();
container.add(suggestBox);
registerEvents();
}
public void createOracle(){
for(int i=1;i<=100;i++){
suggestOracle.add(i+"");
}
}
}
Actually you have to create a SuggestBox with 3 Parameters to the Constructor.
I want to upload file in my application and want to set path where the files should be saved after uploading in my local system.I am using the following code but on the submit button getting no response while clicking.Please tell me the code which works fine for the file upload in gwt.
[code]
public class FormPanelExample implements EntryPoint {
public void onModuleLoad() {
// Create a FormPanel and point it at a service.
final FormPanel form = new FormPanel();
form.setAction("/myFormHandler");
// Because we're going to add a FileUpload widget, we'll need to set the
// form to use the POST method, and multipart MIME encoding.
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
// Create a panel to hold all of the form widgets.
VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);
// Create a TextBox, giving it a name so that it will be submitted.
final TextBox tb = new TextBox();
tb.setName("textBoxFormElement");
panel.add(tb);
// Create a ListBox, giving it a name and some values to be associated with
// its options.
ListBox lb = new ListBox();
lb.setName("listBoxFormElement");
lb.addItem("foo", "fooValue");
lb.addItem("bar", "barValue");
lb.addItem("baz", "bazValue");
panel.add(lb);
// Create a FileUpload widget.
FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
panel.add(upload);
// Add a 'submit' button.
panel.add(new Button("Submit", new ClickListener() {
public void onClick(Widget sender) {
form.submit();
}
}));
// Add an event handler to the form.
form.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) {
// This event is fired just before the form is submitted. We can take
// this opportunity to perform validation.
if (tb.getText().length() == 0) {
Window.alert("The text box must not be empty");
event.setCancelled(true);
}
}
public void onSubmitComplete(FormSubmitCompleteEvent event) {
// When the form submission is successfully completed, this event is
// fired. Assuming the service returned a response of type text/html,
// we can get the result text here (see the FormPanel documentation for
// further explanation).
Window.alert(event.getResults());
}
});
RootPanel.get().add(form);
}
}
Thanks
Amandeep
Now, I remember.. There's a bug in the FormPanel code that causes form.submit() not to work, when the type of the form is changed from the default (don't know if it's fixed yet in any release of GWT). If you create a "native" submit button like this:
HTML nativeSubmitButton new HTML("<input class='gwt-Button' type='submit' value='" + buttonText + "' />")
It will submit the form.
The disadvantage is that you cannot use any Button methods on this object, since it's a simple HTML wrapper. So disabling the button on submit (to avoid accidental double submit, and to give feedback that the form is actually submitting) won't work .
I've created a utility class for this purpose myself called DisableableSubmitButton that is essentially a FlowPanel with one HTML button like the above, and one gwt Button that is disabled, and some logic to toggle each of them visible. Since it cannot modify the actual enabled status of the HTML button all submit handlers must ask this class if it's "enabled" or not and cancel the event if it is. If you're interested in this implementation, i could share it with you (I don't want to flood stackoverflow with code unless you are interested).
I am trying to create a ListBox using GWT. I am using UiBinder to create the field.
I would like to set a default text on the list box and when a user clicks on the box, it should show me the list items. Once again, if user has not selected any option, it should show me the default text again.
Any way to do this either using Uibinder or some ListBox methods?
If I understand correctly you want a value to show but when the user clicks on the list it disappears and shows you the list items?
As far as I know there is no option to that natively.
What you can do is add the first item to hold your default value.
You can do this grammatically by using addItem in code or using:
<g:Listbox>
<g:item value="-1">Default text</g:item>
</g:Listbox>
works with gwt 2.1+
The value can still be selected.
You can choose to ignore it or add an attribute "disabled" with value "disabled" to the option element:
listbox.getElement().getFirstChildElement().setAttribute("disabled" ,"disabled" )
hope it helps a bit :)
You can also use a renderer to control what is shown if 'Null' is selected.
(Inspired by: How do I add items to GWT ListBox in Uibinder .ui.xml template ?)
private class SimpleRenderer implements Renderer<T>{
private String emptyValue = "Select a value";
#Override
public String render(T val) {
if(val == null) {
return emptyValue;
}
return val.toString();
}
#Override
public void render(T val, Appendable appendable) throws IOException {
appendable.append(render(val));
}
public void setEmptyValue(String emptyValue) {
this.emptyValue = emptyValue;
}
}
I am new to Wicket. I have a search page with two fields, startDate and endDate, inside a form that is inside a panel. The panel contains a DefaultDataTable. When the user submits the form, I use the startDate and endDate in the onSubmit() to get the results. However, my table remains empty. How do I tell the DefaultDataTable to refresh?
I have added a form and a submit button to this example. If I want to change the contents of the list, where do I do it?
Button submitButton = new Button("submitButton"){
#Override
public void onSubmit(){
System.out.println("submit button was clicked");
}
};
Form myForm = new Form("myForm");
myForm.add(submitButton);
add(myForm);
Ok, here is my comment as proper answer: make the DataProvider.iterator() dependend on the 2 Dates.