Created
February 7, 2012 10:32
-
-
Save topriddy/1759026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns:wicket> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | |
<title>AlertPanel</title> | |
</head> | |
<body> | |
<wicket:panel> | |
<div wicket:id="wrapper" class="alert"> | |
<a class="close" href="#" wicket:id="closeLink">×</a> | |
<p><span wicket:id="alertMessage"></span></p> | |
</div> | |
</wicket:panel> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.wicket.AttributeModifier; | |
import org.apache.wicket.ajax.AjaxRequestTarget; | |
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink; | |
import org.apache.wicket.markup.html.WebMarkupContainer; | |
import org.apache.wicket.markup.html.basic.Label; | |
import org.apache.wicket.markup.html.panel.Panel; | |
import org.apache.wicket.model.PropertyModel; | |
/** | |
* | |
* @author topriddy | |
*/ | |
public final class AlertPanel extends Panel { | |
public enum AlertType { | |
WARNING(""), ERROR("alert-error"), SUCCESS("alert-success"), INFO("alert-info"); | |
private final String css; | |
AlertType(String css) { | |
this.css = css; | |
} | |
}; | |
private String alertMessage; | |
AlertType alertType; | |
WebMarkupContainer wrapper; | |
public AlertPanel(String id, String alertMessage, AlertType alertType, final boolean closeable) { | |
super(id); | |
wrapper = new WebMarkupContainer("wrapper"); | |
setOutputMarkupId(true); | |
setOutputMarkupPlaceholderTag(true); | |
add(wrapper); | |
this.alertMessage = alertMessage; | |
Label alertLabel = new Label("alertMessage", new PropertyModel<String>(this, "alertMessage")); | |
alertLabel.setEscapeModelStrings(false); | |
alertLabel.setOutputMarkupId(true); | |
alertLabel.setOutputMarkupPlaceholderTag(true); | |
AjaxFallbackLink closeLink = new AjaxFallbackLink("closeLink") { | |
@Override | |
public void onClick(AjaxRequestTarget target) { | |
if (target != null) { | |
AlertPanel.this.setVisible(closeable); | |
target.add(AlertPanel.this); | |
} | |
} | |
}; | |
closeLink.setVisible(closeable); | |
setAlertType(alertType); | |
wrapper.add(alertLabel); | |
wrapper.add(closeLink); | |
} | |
public AlertType getAlertType() { | |
return alertType; | |
} | |
public void setAlertType(AlertType alertType) { | |
this.alertType = alertType; | |
wrapper.add(AttributeModifier.replace("class", "alert " + alertType.css)); | |
} | |
public String getAlertMessage() { | |
return alertMessage; | |
} | |
public void setAlertMessage(String alertMessage) { | |
this.alertMessage = alertMessage; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
</head> | |
<body> | |
<wicket:panel> | |
<div wicket:id="feedbackul" class="feedbackPanel"> | |
<div wicket:id="messages" class="errorlevel"> | |
<div wicket:id="message"></div> | |
</div> | |
</div> | |
</wicket:panel> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.wicket.Component; | |
import org.apache.wicket.feedback.FeedbackMessage; | |
import org.apache.wicket.markup.html.panel.FeedbackPanel; | |
/** | |
* | |
* @author topriddy | |
*/ | |
public class MyFeedbackPanel extends FeedbackPanel { | |
public MyFeedbackPanel(String id) { | |
super(id); | |
} | |
@Override | |
protected Component newMessageDisplayComponent(String id, FeedbackMessage message) { | |
AlertPanel alertPanel = new AlertPanel("message", message.getMessage().toString(), AlertPanel.AlertType.ERROR, false); | |
alertPanel.setVisible(true); | |
switch (message.getLevel()) { | |
case FeedbackMessage.INFO: | |
alertPanel.setAlertType(AlertPanel.AlertType.INFO); | |
break; | |
case FeedbackMessage.WARNING: | |
alertPanel.setAlertType(AlertPanel.AlertType.WARNING); | |
break; | |
case FeedbackMessage.SUCCESS: | |
alertPanel.setAlertType(AlertPanel.AlertType.SUCCESS); | |
break; | |
} | |
return alertPanel; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment