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.
Related
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.
I have a list page where it has button menu. While i select a record and click on that button menu a new page will be open with the corresponding code from the selected record.
From the opened page's doAfterCompose, how can i get the name of the previous page from where we clicked the button and opened the new page?
Please anyone help me with this...
What you should do (although I haven't seen your code) is to generate an event that passes as a value the previous page number when 'that button menu' is clicked. The event will then be picked up by the event queue together with the passed value.
So inside the method that handles the event generated by the click of the button menu you should add the following:
EventQueues.lookup("myqueue", EventQueues.DESKTOP, true)
.publish(new Event("buttonClicked", null, previousPage));
where previousPage is the value passed (an integer for the sake of the example).
Then inside the doAfterCompose() method you extrapolate the data passed:
EventQueues.lookup("myqueue", EventQueues.DESKTOP, true).subscribe(
new EventListener() {
public void onEvent(Event evt) {
if (evt.getName().equalsIgnoreCase("buttonClicked")) {
int thePreviousPage = (int) evt.getData();
.......
I have a question and maybe someone could help me find the best solution. I want a user to be able to add items to a drop down list dynamically in a form. I have a form with text boxes and drop down lists and want the user to be able to add items to the drop down list if they don't find it. I would make the drop down lists text boxes but I want to try and keep the names consistent. An example of a form would be have the user enter a name and then have drop down lists for colors and shapes. If the user does not see the color in the drop down I want them to be able to click a link next to the drop down and enter the name or the color. Another link to add shapes to the drop down list.
I'm trying to do this in an MVC Razor environment. I tried using partial views by having the link open a modal box of a partial view to enter the name, but then I have a form within a form and cannot submit the inner form. If I open a small window to enter the name then how do I add it back to the original parent window form without loosing what they already entered in the text box? I know there has to be a good solution out there.
If you want the users new input to be saved for later use, you could use Ajax to submit the new data into the database, and then have the controller return a partial view with your new dropdown.
So your dropdown would be an action Like this:
public PartialViewResult Dropdown()
{
var model = new DropdownModel()
{
Data = yourdata;
}
return PartialView("Dropdown.cshtml", model)
}
And your action to insert new data would look something like this:
public PartialViewResult AddDataToDropdown(string data)
{
var newDropdown = repository.AddData(data);
var model = new DropdownModel()
{
Data = newDropdown;
}
return PartialView("Dropdown.cshtml", model)
}
So bascially, you can resplace the HTML in the div that contains the dropdown with Ajax like this:
$(".someButton").on("click", function () {
var newData = ("$someTextbox").val();
$.ajax({
url: "/YourController/AddDataToDropdown",
type: "GET",
data: { data: newData}
})
.success(function (partialView) {
$(".someDiv").html(partialView);
});
});
This way you save the data and the dropdown is refreshed without refreshing the entire page
I'm using UploadItem, RadioGroupItem and some other widgets. RadioButton is having onChangeHandler which will decide what all other components need to be displayed. I've uploaded some file using UploadItem. Then I changed the radio button selection. On changing the radio button, required widgets are getting displayed properly but whatever file I'd selected using UploadItem is going away. Fresh UploadItem widget is getting displayed. In other words page is getting refreshed.
My requirement is whenever I change radio button option, required widget should displayed along with that whatever file I had selected using UploadItem should remain same.
My Code is something like this:
UploadItem upload = new UploadItem();
RadioGroupItem radioGroup = new RadioGroupItem();
HashMap map = new HashMap();
map.put("option1","option1");
map.put("option2","option2");
radioGroup.setValueMap(map);
TextItem textbox = new TextItem();
radioGroup.addChangeHandler(new ChangeHandler(){
public void onChanged(ChangedEvent event) {
String radioValue =((String)event.getValue());
if(radioValue.equalsIgnoreCase("option2")){
textbox.show();
}else{
textbox.hide();
}
}
});
Add all created widgets to DynamicForm object using dynamicForm.setFields(all created widgets)
Changing the radio button should hide and show the textBox. But while doing that page is getting refreshed and whatever file we had selected using UploadItem is lost.
As per the documentation for hide() and show() of FormItem class, invocation of any of these methods, will cause the DynamicForm to be redrawn.
So it may cause the problem you're getting.
To overcome this issue, I would suggest you to put UploadItem in a separate DynamicForm.
fire an event on radio Selection change as
radioButton.addListener(Events.Change, new Listener<BaseEvent>() {
#Override
public void handleEvent(BaseEvent be) {
if(radioButton.getValue()){
//fire an event here for ur widget
}
}
});
I'm having a problem using a GWT listbox. I have a case where the user selects a value from a listBox, but it can become invalidated if they change data in a related field. To validate the listBox, the user has to either select a new value, or confirm their old selection by selecting the same value again. I can't figure out how to determine if they have selected the same value so that I can restyle the listBox to look validated.
The valueChanged handler only detects if a new value is selected. The clickHandler and focusHandler fire too often because they fire when the user isn't selecting a value. Any ideas?
You can improve the clickHandler with something like this :
ignoreClick = true;
lastSelection = -1 ;
....
listBox.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
if (!ignoreClick) {
lastSelection = listBox.getSelectedIndex();
}
ignoreClick = !ignoreClick;
}
});
I tried it and the event was only fired if you selected an item. But you should rethink your user interface , like said above.