New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modal compatible with wicket ModalWindow interface #228
Comments
I am not sure this is a good idea.
Wicket Bootstrap Modal is a Panel that you should extend. Whatever you add to it will be its body. |
Thanks Martin, that makes sense. I'm curious, for my own education, why don't you like ModalWindow's dual use with pages and panels? Is it that to compensate for using both panels and pages, the interface gets bloated, or is it something else? |
My reasons are:
|
I have actually extended Modal class and added setContent method to it (it was useful because content was constructed only on action) so maybe this could be useful addition to component. Also to add a save button was a bit complicated, i solved it by providing ajax submit button content panel (one added to modal) in constructor, and then getting all fields from its form in onSubmit method, but maybe there could be easier way? |
To add a panel in a Modal I've done something like that (in a ModalWindow way) : /**
* A modal that display a panel load with ajax.
*/
public class PanelContentModal extends Modal {
/** serialVersionUID. */
private static final long serialVersionUID = -5002663900158560343L;
/** content ID. */
private static final String CONTENT_ID = "content";
/**
* @param varMarkupId modal markup Id
*/
public PanelContentModal(final String varMarkupId) {
super(varMarkupId);
setContent(new EmptyPanel(getContentId()));
}
/**
* @param varMarkupId modal markup Id
* @param varPanel panel to set in the modal
*/
public PanelContentModal(final String varMarkupId, final Panel varPanel) {
super(varMarkupId);
setContent(varPanel);
}
/**
* @return the contentId
*/
public static final String getContentId() {
return CONTENT_ID;
}
/**
* Sets the panel of the modal.
*
* @param component component to set
* @return this;
*/
public Modal setContent(final Panel component) {
if (!component.getId().equals(getContentId())) {
throw new WicketRuntimeException("Modal content id is wrong. Component ID:" + component.getId()
+ "; content ID: " + getContentId());
}
component.setOutputMarkupId(true);
addOrReplace(component);
return this;
}
/**
* Shows the modal window.
*
* @param target
* Request target associated with current ajax request.
*/
public void show(final AjaxRequestTarget target) {
target.add(this);
appendShowDialogJavaScript(target);
}
} <html xmlns:wicket="http://wicket.apache.org">
<head>
<title>PanelContentModal</title>
</head>
<body>
<wicket:extend>
<div wicket:id="content"></div>
</wicket:extend>
</body>
</html> Using it that way : PanelContentModal modal = new PanelContentModal("modal");
modal.header(Model.of("My Modal title"));
add(modal);
...
add(new AjaxLink<Void>("editLink") {
@Override
public void onClick(final AjaxRequestTarget varTarget) {
modal.setContent(new MyPanel(PanelContentModal.getContentId(), myModel));
modal.show(varTarget);
}
}); @martin-g I can add it to the project if you think it can be useful and improved by other |
Yes. Maybe it is OK to add it. I just want to avoid having a new monster like Wicket's ModalWindow. |
Any chance for a Bootstrap Modal that implements most of the methods of a Wicket modal window so it can be easily swapped in? Is it possible to add a panel as the body for Bootstrap Modals? Thanks
The text was updated successfully, but these errors were encountered: