wicket 6.0.0-beta2 Updating content of DataTable when submitting a form with AjaxButton - ajax

I want to change the content of a DataTable depending on the content of a form (think of it as a searchbar functionality). I used to do that in wicket 1.5.x but I can not seem to make it work in wicket 6.0.0-beta2. It does not seem to enter in the onSubmit method of the AjaxButton. Everything else works just fine, every components render correctly and the dataTable is filled with the correct data when the page load, but when I click the button, nothing happens.
Any help would be greatly appreciated. Here is what my code look like :
The dataTable :
public SubscriberPage(PageParameters parameters) {
super(parameters);
add(new SearchForm("searchForm"));
List<IColumn<Subscriber, String>> columns = new ArrayList<IColumn<Subscriber, String>>();
columns.add(new PropertyColumn<Subscriber, String>(new Model<String>("Telephone Number"),
"tn",
"tn"));
[...]
columns.add(new PropertyColumn<Subscriber, String>(new Model<String>("Initialized MB"),
"initializedMB"));
table = new AjaxFallbackDefaultDataTable<Subscriber, String>("table",
columns,
subscriberDataProvider,
40);
table.setOutputMarkupId(true);
add(table);
}
and here is the form with the AjaxButton:
private class SearchForm extends Form<String> {
private static final long serialVersionUID = 1L;
private String tnModel;
private Label tnLabel = new Label("tnLabel", "Telephone Number :");
private TextField<String> tn;
public SearchForm(String id) {
super(id);
tn = new TextField<String>("tnTextField", new PropertyModel<String>(this, "tnModel"));
tn.setOutputMarkupId(true);
add(tnLabel);
add(tn);
AjaxButton lSearchButton = new AjaxButton("searchButton") {
private static final long serialVersionUID = 1L;
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
SubscriberFilter filter = new SubscriberFilter();
target.add(table);
if (!(tn.getValue() == null) && !tn.getValue().isEmpty()) {
filter.setTn(tn.getValue());
}
// giving the new filter to the dataProvider
subscriberDataProvider.setFilterState(filter);
}
#Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
// TODO Implement onError(..)
throw new UnsupportedOperationException("Not yet implemented.");
}
};
lSearchButton.setOutputMarkupId(true);
this.setDefaultButton(lSearchButton);
add(lSearchButton);
}
}

The components that you want to refresh need to be added in a container. When you submit, the container needs to be added to target. This way your components will be refreshed. Something like:
WebMarkupContainer outputContainer = new WebMarkupContainer("searchResult");
outputContainer.setOutputMarkupId(true);
outputContainer.add(table);
add(outputContainer);
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
//change table ..... stuff ..... ...
//refresh container
target.add(outputContainer);
}
<div wicket:id="searchResult"></div>

Related

Wicket FeedbackPanel has empty message when used with AjaxFallBackButton

I am using BeanValidation for Form inputs with AjaxFallbackButton to submit the Form. And FeedbackPanel for showing errors. When I give invalid input the form does not submit but feedbackpanel is not showing.
onError, form.getFeedbackMessages() returns empty array.
Wicket version 6.18.0.
Here is the code:
Form<Address> form = getForm();
add(form);
FeedbackPanel feedbackPanel = new FeedbackPanel("feedbackMessage");
feedbackPanel.setOutputMarkupId(true);
add(feedbackPanel);
public Form<Address> getForm() {
CompoundPropertyModel<Address> model = new CompoundPropertyModel<Address>(address);
final Form<Address> form = new Form<Address>("addressForm", model);
form.add(new Label("fNameLabel", new ResourceModel("fNameLabel")));
form.add(new Label("lNameLabel", new ResourceModel("lNameLabel")));
form.add(new Label("workLabel", new ResourceModel("workLabel")));
form.add(new Label("homeLabel", new ResourceModel("homeLabel")));
form.add(new TextField<String>("firstName").add(new PropertyValidator<String>()));
form.add(new TextField<String>("lastName").add(new PropertyValidator<String>()));
form.add(new TextField<String>("homeLocation").add(new PropertyValidator<String>()));
form.add(new TextField<String>("workLocation").add(new PropertyValidator<String>()));
form.add(new AjaxFallbackButton("submit", form) {
/**
*
*/
private static final long serialVersionUID = 6672729206839722437L;
#Override
protected void onError(final AjaxRequestTarget target, final Form form) {
Page page = target.getPage();
for (Component component : page.visitChildren()) {
String markupId = component.getMarkupId();
if (markupId.contains("feedbackMessage")) {
if (form.hasFeedbackMessage()) {
System.out.println(form.getFeedbackMessages());
}
}
}
}
#Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
if (address.getFirstName() != null) {
AddressGenerator.getInstance().add(address);
modalWindow.closeCurrent(target);
}
}
});
return form;
}
Form is in ModalWindow.
Component#getFeedbackMessages() returns the messages only for this component instance. It doesn't visit the children!
Update your onError() method with:
#Override
protected void onError(final AjaxRequestTarget target, final Form form) {
target.add(feedbackPanel);
}
You can use if (form.hasError()) but since you are in AjaxFallbackButton#onError() it means there is an error.

Dynamically replace ListView table cell with textField wicket

I have a listView which has a single column which needs to be editable only in certain cases. If the user needs to change the column, I want them to click a edit button for the row, then replace the label in the cell with a textField. When I call replace I can see the TextField is now in the place of the label, although it is never rendered. I have a AjaxLink to handle the event. I am using a container to repaint the listView. Here is my listview:
parent = new WebMarkupContainer("emp-table-parent");
parent.add(new AjaxLink<Object>(FIRST_NAME_HEADER_LINK) {
/**
*
*/
private static final long serialVersionUID = -1937727929649333407L;
#Override
public void onClick(AjaxRequestTarget target) {
changeGlyphUpdateList(target, parent.get(FIRST_NAME_HEADER_LINK).get(FIRST_NAME_HEADER_ICON),
parent.get(LAST_NAME_HEADER_LINK).get(LAST_NAME_HEADER_ICON),
parent.get(EMAIL_HEADER_LINK).get(EMAIL_HEADER_ICON), parent.get(ELIGIBILITY_CLASS_HEADER_LINK).get(ELIGIBILITY_CLASS_HEADER_ICON),
parent.get(EMPLOYER_HEADER_LINK).get(EMPLOYER_HEADER_ICON));
}
}.add(new Label("first-name-header-label", Model.of("First Name")), new WebComponent(FIRST_NAME_HEADER_ICON)),
new AjaxLink<Object>(LAST_NAME_HEADER_LINK) {
/**
*
*/
private static final long serialVersionUID = -3438649095509412910L;
#Override
public void onClick(AjaxRequestTarget target) {
changeGlyphUpdateList(target, parent.get(LAST_NAME_HEADER_LINK).get(LAST_NAME_HEADER_ICON),
parent.get(FIRST_NAME_HEADER_LINK).get(FIRST_NAME_HEADER_ICON),
parent.get(EMAIL_HEADER_LINK).get(EMAIL_HEADER_ICON),
parent.get(ELIGIBILITY_CLASS_HEADER_LINK).get(ELIGIBILITY_CLASS_HEADER_ICON),
parent.get(EMPLOYER_HEADER_LINK).get(EMPLOYER_HEADER_ICON));
}
}.add(new Label("last-name-header-label", Model.of("Last Name")), new WebComponent(LAST_NAME_HEADER_ICON)),
new AjaxLink<Object>(EMAIL_HEADER_LINK) {
/**
*
*/
private static final long serialVersionUID = 2890934302751793454L;
#Override
public void onClick(AjaxRequestTarget target) {
changeGlyphUpdateList(target, parent.get(EMAIL_HEADER_LINK).get(EMAIL_HEADER_ICON),
parent.get(LAST_NAME_HEADER_LINK).get(LAST_NAME_HEADER_ICON),
parent.get(FIRST_NAME_HEADER_LINK).get(FIRST_NAME_HEADER_ICON),
parent.get(ELIGIBILITY_CLASS_HEADER_LINK).get(ELIGIBILITY_CLASS_HEADER_ICON),
parent.get(EMPLOYER_HEADER_LINK).get(EMPLOYER_HEADER_ICON));
}
}.add(new Label("email-header-label", Model.of("Email")), new WebComponent(EMAIL_HEADER_ICON)),
new AjaxLink<Object>(ELIGIBILITY_CLASS_HEADER_LINK) {
/**
*
*/
private static final long serialVersionUID = -4022209586109961448L;
#Override
public void onClick(AjaxRequestTarget target) {
changeGlyphUpdateList(target, parent.get(ELIGIBILITY_CLASS_HEADER_LINK).get(ELIGIBILITY_CLASS_HEADER_ICON),
parent.get(EMAIL_HEADER_LINK).get(EMAIL_HEADER_ICON),
parent.get(LAST_NAME_HEADER_LINK).get(LAST_NAME_HEADER_ICON),
parent.get(FIRST_NAME_HEADER_LINK).get(FIRST_NAME_HEADER_ICON),
parent.get(EMPLOYER_HEADER_LINK).get(EMPLOYER_HEADER_ICON));
}
}.add(new Label("eligibility-class-header-label", Model.of("Elig. Class")), new WebComponent(ELIGIBILITY_CLASS_HEADER_ICON)),
new AjaxLink<Object>(EMPLOYER_HEADER_LINK) {
/**
*
*/
private static final long serialVersionUID = -738777257301408437L;
#Override
public void onClick(AjaxRequestTarget target) {
changeGlyphUpdateList(target, parent.get(EMPLOYER_HEADER_LINK).get(EMPLOYER_HEADER_ICON),
parent.get(ELIGIBILITY_CLASS_HEADER_LINK).get(ELIGIBILITY_CLASS_HEADER_ICON),
parent.get(EMAIL_HEADER_LINK).get(EMAIL_HEADER_ICON),
parent.get(LAST_NAME_HEADER_LINK).get(LAST_NAME_HEADER_ICON),
parent.get(FIRST_NAME_HEADER_LINK).get(FIRST_NAME_HEADER_ICON));
}
}.add(new Label("employer-header-label", Model.of("Employer")), new WebComponent(EMPLOYER_HEADER_ICON)),
new PageableListView<EmployeeSummaryPkt>("data", employeeSummaryModel.getObject(), 25) {
/**
*
*/
private static final long serialVersionUID = -1697070076764699904L;
#Override
protected void populateItem(final ListItem<EmployeeSummaryPkt> item) {
item.setDefaultModel(new CompoundPropertyModel<EmployeeSummaryPkt>(item.getModelObject()));
item.add(new Label("firstName"),
new Label("lastName"),
new Label("employeeEmail"),
new Link<Object>("eligibility-class-data-link") {
/**
*
*/
private static final long serialVersionUID = -3842291392813313171L;
#Override
public void onClick() {
//LINK TO ELIGIBILITY CLASS OR MAYBE THE SECTION WITHIN THE EMP?
}
}.add(new Label("employeeEligibilityClassSummaryPkt.name")),
new Link<Object>("employer-data-link") {
/**
*
*/
private static final long serialVersionUID = 6809571267919974106L;
#Override
public void onClick() {
getIndex().getHomePanel().setNewContent(new EmployerDetailPanel("panel-content", item.getModelObject().getEmployerSummaryPkt().getId()));
}
}.add(new Label("employerSummaryPkt.name")),
new Label("employeeDateOfBirth"),
new Label("employee-code", Model.of(item.getModelObject().getEmployeeName())).setOutputMarkupId(true),
new AjaxLink<Object>("edit-employee-link") {
/**
*
*/
private static final long serialVersionUID = 6061544430700059358L;
#Override
public void onClick(AjaxRequestTarget target) {
logr.log(Level.FINER, "onClick for edit employee");
logr.log(Level.FINER, "employee code pre: " + item.get("employee-code").getClass().getSimpleName());
item.get("employee-code").replaceWith(new TextField<String>("employee-code", new Model<String>(item.getModelObject().getEmployeeName())).setOutputMarkupId(true));
logr.log(Level.FINER, "employee code post: " + item.get("employee-code").getClass().getSimpleName());
target.addChildren(parent, TextField.class);
target.add(parent);
}
});
}
As you can see, the label with the id "employee-code" is the label I wish to replace. Inside the AjaxLink onClick, you can see where I am getting the label and replacing it. Nothing is changing. Any direction or help is greatly appreciated.
A ListView recreates each if its items on each render, thus the altered listItem is thrown away immediately.
ListView#setReuseItems(true) should help.
An alternative to svenmeier's answer could also be to add only the specific item that has been changed to the AjaxRequestTarget. That is, replace
target.addChildren(parent, TextField.class);
target.add(parent);
With
target.add(item.get("employee-code"))
Which would cause only the piece of markup that concerns the change to be re-rendered, as opposed to the entire table. If your table is big and contains a lot of elements, whose models involve complicated retrieval mechanisms rendering the entire table would be a much more laborious process, and hence re-rendering only the item would be a better solution.
Having said that, in your particular case svenmeier's solution is better, as otherwise if you implement my solution and later on re-render the entire table, the changes would be lost.

How to synchronize an Ajax onClick and onUpdate Event

I have a table to display the rights of the selected user. In the columns I have the role and in the rows the function. In each cell within the table I have a Wicket AjaxCheckBox, which uses an onUpdate Event to trigger an action. But in addition to that the admin should also be able to click on the row to select the Checkbox. Each cell has therefore an onClick event attached.
If I click the CheckBox, it won't select, but if I double-click it does. Since I trigger with one click the onClick of the cell and the onUpdate of the CheckBox simultaneously it neutralizes itself.
I'm running Wicket 6.20
Right now I'm runnig it like this:
final WebMarkupContainer cell = new WebMarkupContainer("cont");
cell.setOutputMarkupId(true);
cell.setOutputMarkupPlaceholderTag(true);
cell.setVisibilityAllowed(true);
cell.add(AttributeModifier.append("class", checkState));
cell.add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 1L;
#Override
protected void onEvent(AjaxRequestTarget target) {
eventHandler(checked, checkState);
target.add(cell);
}
});
item.add(cell);
cell.add(new AjaxCheckBox("checkbox", checked) {
private static final long serialVersionUID = 1L;
#Override
protected void onUpdate(AjaxRequestTarget target) {
eventHandler(checked, checkState);
target.add(cell);
}});
public void eventHandler(IModel<Boolean> checked, IModel<String> checkState) {
boolean isChecked = checked.getObject();
if (isChecked == false) {
checked.setObject(true);
checkState.setObject("checked");
//Do sth
} else if (isChecked == true) {
checked.setObject(false);
checkState.setObject("unchecked");
//Do sth
}
}
Is this Wicket 7? Then you should prevent event bubbling on your AjaxCheckBox:
#Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
super.updateAjaxAttributes(attributes);
attributes.setEventPropagation(EventPropagation.STOP);
}

Wicket why page expires when opening link in new tab?

I'm building a wicket bootsrap web application with the following specs (from pom.xml):
wicket version: 6.15.0
wicket-bootstrap-core.version: 0.9.3-SNAPSHOT
I have a base page which is the father of my other pages and adds to mark up a horizontal navigation bar on top, with key component:
BootstrapBookmarkablePageLink extends BookmarkablePageLink
This is part of my BasePage.java
public abstract class BasePage extends GenericWebPage<Void> {
private static final long serialVersionUID = 1L;
String username;
public WicketApplication getApp() {
return WicketApplication.class.cast(getApplication());
}
public BasePage(final PageParameters parameters) {
super(parameters);
// Read session data
cachedUsername = (String)
BasicAuthenticationSession.get().getAttribute("username");
// create navbar
add(newNavbar("navbar"));
}
/**
* #return application properties
*/
public Properties getProperties() {
return WicketApplication.get().getProperties();
}
/**
* creates a new {#link Navbar} instance
*
* #param markupId
* The components markup id.
* #return a new {#link Navbar} instance
*/
protected Navbar newNavbar(String markupId) {
Navbar navbar = new Navbar(markupId) {
private static final long serialVersionUID = 1L;
#Override
protected TransparentWebMarkupContainer newCollapseContainer(String
componentId) {
TransparentWebMarkupContainer container =
super.newCollapseContainer(componentId);
container.add(new CssClassNameAppender("bs-navbar-collapse"));
return container;
}
};
navbar.setPosition(Navbar.Position.TOP);
// navbar.setInverted(true);
NavbarButton<Void> myTab = new NavbarButton<Void>(MyPage.class, new
PageParameters().add("name", "")
.add("status", "All").add("date", ""), Model.of("My page"));
NavbarButton<Void> myOtherTab = new NavbarButton<Void>
(MyOtherPage.class, new PageParameters().add("status", "initial")
.add("date", ""), Model.of("My other page"));
navbar.addComponents(NavbarComponents.transform(
Navbar.ComponentPosition.LEFT,
myTab, myOtherTab));
return navbar;
}
}
Then, MyPage renders a filter form, an html table, ajaxbuttons and some links, Some of my components are ajax components:
public class MyPage extends BasePage {
private static final long serialVersionUID = 5772520351966806522L;
#SuppressWarnings("unused")
private static final Logger LOG = LoggerFactory.getLogger(MyPage.class);
private static final Integer DAYS = 270;
private DashboardFilteringPageForm filteringForm;
private CityInitialForm ncForm;
private String CityName;
private String startDate;
private CitysTablePanel citysTable;
private WebMarkupContainer numberOfNodes;
public MyPage(PageParameters parameters) throws ParseException {
super(parameters);
// get Citys list from repo
final List<City> repoCitys = (List<City>) methodToGetCities();
// select number of nodes
numberOfNodes = new WebMarkupContainer("numberOfNodes") {
private static final long serialVersionUID = 5772520351966806522L;
};
numberOfNodes.setOutputMarkupId(true);
ncForm = new CityInitialForm("ncForm");
// validation
add(new FeedbackPanel("feedbackPanel")).setOutputMarkupId(true);
ncForm.getNumberField().setRequired(true);
ncForm.add(new AjaxButton("ncButton") {
private static final long serialVersionUID = -6846211690328190809L;
#Override
protected void onInitialize() {
super.onInitialize();
add(newAjaxFormSubmitBehavior("change"));
}
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
// redirect to other page
}
#Override
protected void updateAjaxAttributes(AjaxRequestAttributes
attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new
DisableComponentListener(citysTable));
}
});
numberOfNodes.add(ncForm);
// filters
CityName = parameters.get("name").toString() == null ? "" :
parameters.get("name").toString();
startDate = parameters.get("date").toString();
filteringForm = new DashboardFilteringPageForm("filteringForm") {
private static final long serialVersionUID = -1702151172272765464L;
};
// initialize form inputs
filteringForm.setCityName(CityName);
try {
filteringForm.setStartDate(new SimpleDateFormat("EE MMM dd HH:mm:ss
z yyyy", Locale.ENGLISH)
.parse(getStartDate().equals("") ?
CortexWebUtil.subtractDays(new Date(), DAYS).toString() : getStartDate()));
} catch (Exception e) {
setResponsePage(SignInPage.class, new PageParameters());
}
filteringForm.add(new AjaxButton("button") {
private static final long serialVersionUID = -6846211690328190809L;
#Override
protected void onInitialize() {
super.onInitialize();
add(newAjaxFormSubmitBehavior("change"));
}
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> paForm) {
// retrieve Citys
filterCitysAjax(target, "All");
}
#Override
protected void updateAjaxAttributes(AjaxRequestAttributes
attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new
DisableComponentListener(citysTable));
}
});
filteringForm.getCityNameTextField().add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1468056167693038096L;
#Override
protected void onUpdate(AjaxRequestTarget target) {
try {
filterCitysAjax(target, "All");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
#Override
protected void updateAjaxAttributes(AjaxRequestAttributes
attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new
DisableComponentListener(citysTable));
}
});
// new City link
AjaxLink<Void> newCityLink = newCityLink("newCity", repoCitys);
// Citys table
citysTable = new CitysTablePanel("CitysTable", repoCitys);
citysTable.setOutputMarkupId(true);
// add components
add(filteringForm, newCityLink, numberOfNodes, citysTable);
}
private void filterCitysAjax(AjaxRequestTarget target, String status) {
methodToFilterResults();
// re-render table component
CitysTablePanel cityTableNew = new CitysTablePanel("CitysTable", citys);
cityTableNew.setOutputMarkupId(true);
cityTableNew.setVisibilityAllowed(true);
cityTableNew.setVisible(true);
citysTable.replaceWith(cityTableNew);
target.add(cityTableNew);
citysTable = cityTableNew;
target.appendJavaScript(CortexWebUtil.TABLE_ODD_EVEN_ROWS);
}
private AjaxLink<Void> newCityLink(String string, final List<City> Citys) {
final AjaxLink<Void> newCityLink = new AjaxLink<Void>(string) {
private static final long serialVersionUID = -5420108740617806989L;
#Override
public void onClick(final AjaxRequestTarget target) {
numberOfNodes.add(new AttributeModifier("style",
"display:block"));
target.add(numberOfNodes);
}
};
// new City image
Image newCityImage = new Image("newCityIcon", new
ContextRelativeResource("/img/new_City_icon.png"));
add(newCityLink);
newCityLink.add(newCityImage);
return newCityLink;
}
}
So MyPage works but when I open MyOtherPage Link in an a new tab and trigger an ajax component in MyPage (e.g the AjaxButton) then I get the page expirtaion error.
Why is that happening?
Do I need to use stateless pages? ( stateless link )
Why would it be so ard in wicket to open links in new tabs and use ajax components? I must be missing sometthing..
Here are few possible reasons:
MyPage fails to serialize
Wicket stores stateful pages in page storage (in the disk, by default). Later when you click a stateful link Wicket tries to load the page. First it looks in the http session where the page is kept in its live form (i.e. not serialized). If it is not found there then Wicket looks in the disk.
Wicket keeps only the page(s) used in the last user request in the Http Session (to keep memory footprint small). By clicking on MyOtherPage link you put an instance of MyOtherPage in the Http session and the old instance (of MyPage) is only in the disk. But: if MyPage fails to serialize to byte[] then it cannot be stored in the disk and thus later requests will fail with PageExpiredException.
Todo: Check your logs for NotSerializableException with nice debug message of the reason.
MyOtherPage is too big
By default Wicket writes up to 10M per user session in the disk. If MyPage is let's say 2M and MyOtherPage is 9M (both sizes are quite big, but I don't know what happens in your app...) then saving MyOtherPage will remove MyPage from the disk. Later attempts to load MyPage will fail with PageExpiredException.
Todo: Review your usage of Wicket Models.

Wicket 6 AjaxFormComponentUpdatingBehavior event working on first row of ListView but not for subsequent ones

I'm trying to handle a DropDownChoice onchange event in a listView that can display a modal window. It seems working fine for first element but not for subsequent added elements.
final ModalWindow modal = new ModalWindow("modal");
modal.setOutputMarkupId(true);
form.add(modal);
final ListView<CommandeFournisseurDetails> myView = new ListView<CommandeFournisseurDetails>(
"rowsList",
new PropertyModel<List<CommandeFournisseurDetails>>(this,
"rows")) {
#Override
protected void populateItem(
final ListItem<CommandeFournisseurDetails> item) {
final CommandeCollectionJDBC myCollection = new CommandeCollectionJDBC();
CommandeFournisseurDetails row = item.getModelObject();
item.add(new Label("index",
new AbstractReadOnlyModel<Integer>() {
#Override
public Integer getObject() {
return item.getIndex() + 1;
}
}));
final DropDownChoice<String> ID_PRODUIT = new DropDownChoice(
"ID_PRODUIT", new PropertyModel<String>(row,
"ID_PRODUIT"), myCollection.getProduit());
ID_PRODUIT.setOutputMarkupId(true);
ID_PRODUIT.setMarkupId("ID_PRODUIT");
ID_PRODUIT.setLabel(Model.of("Produit"));
ID_PRODUIT.setRequired(true);
AjaxFormComponentUpdatingBehavior behavior = new AjaxFormComponentUpdatingBehavior(
"onChange") {
protected void onUpdate(AjaxRequestTarget target) {
if (!ID_PRODUIT.getDefaultModelObjectAsString()
.isEmpty()) {
final PageParameters params = new PageParameters();
params.set("message",
ID_PRODUIT.getDefaultModelObjectAsString());
params.set("type", "Produit");
modal.setPageCreator(new ModalWindow.PageCreator() {
public Page createPage() {
// Use this constructor to pass a reference
// of this page.
return new ModalContentPage(modal, params);
}
});
modal.show(target);
target.add(modal);
target.add(ID_PRODUIT);
}
}
protected void onError(AjaxRequestTarget target,
RuntimeException e) {
System.out.println(e.toString());
}
};
ID_PRODUIT.add(behavior);
AbstractSubmitLink remove = new SubmitLink("removeRowLink") {
#Override
public void onSubmit() {
getList().remove(item.getModelObject());
getParent().getParent().removeAll();
};
}.setDefaultFormProcessing(false);
item.add(remove);
}
}.setReuseItems(true);
form.add(new SubmitLink("addRowLink") {
#Override
public void onSubmit() {
rows.add(new CommandeFournisseurDetails());
}
}.setDefaultFormProcessing(false));
myView.setOutputMarkupId(true);
form.add(myView);
Any idea why the other elements do not inherit the same event?
Thanks for your help.
All ID-PRODUIT dropdownchoices (the first, but also the rest) have the same markupId, thanks to:
ID_PRODUIT.setMarkupId("ID_PRODUIT");
Try giving them a unique MarkupId. Perhaps by adding the index of the listitem:
ID_PRODUIT.setMarkupId("ID_PRODUIT" + item.getIndex());
or remove that line of code altogether.

Resources