I see it's a nice idea, but I'm afraid Wicket gets too messy if we'd
support two distinct message models like that. I don't know... maybe
you can open up a feature request for it and we can have it open for
discussion there? I think that the proper class to build something
like this in would be Session btw.
Eelco
On 5/22/07, Harald Gruber <[EMAIL PROTECTED]> wrote:
> hi all,
>
> i was just wondering, if other users might have thought about the usefulness
> of extending FeedbackMessages by a new type ALERT
> (and the according classes (Component.alert("message")...).
>
> The reason for this would be, to provide the user special feedback shown
> through a javascript alert (or popup window)
> and still have feedbackpanels for errorreporting in a page.
>
> a simple component for showing alertmessages using javascript-alert is
> included in this message.
>
> opinions welcome,
>
> harald
>
> --------------- FeedbackAlertPanel.java --------------------------------
> package rd.wicket;
>
> import java.util.Iterator;
> import java.util.List;
>
> import org.apache.wicket.feedback.FeedbackMessage;
> import org.apache.wicket.feedback.FeedbackMessagesModel;
> import org.apache.wicket.feedback.IFeedbackMessageFilter;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.markup.html.panel.Panel;
> import org.apache.wicket.model.AbstractReadOnlyModel;
>
> public class FeedbackAlertPanel extends Panel {
> private static final long serialVersionUID = 1L;
>
> public FeedbackAlertPanel(String id) {
> this(id, new AlertFeedbackMessageFilter());
> }
>
> public FeedbackAlertPanel(String id, final IFeedbackMessageFilter
> feedbackMessageFilter) {
> super(id);
> FeedbackMessagesModel model = new FeedbackMessagesModel(this);
> model.setFilter(feedbackMessageFilter);
> setModel(model);
> Label script = new Label("script", new
> AbstractReadOnlyModel() {
>
> private static final long serialVersionUID = 1L;
>
> @Override
> public Object getObject() {
> return getScriptBody();
> }
>
> });
> script.setEscapeModelStrings(false);
> add(script);
> }
>
> public boolean isVisible() {
> return !((List) getModelObject()).isEmpty();
> }
>
> private String getScriptBody() {
> StringBuffer sb = new StringBuffer();
> sb.append("Wicket.Event.add(window, \"load\", function() {
> showFeedbackAlert(); });\n");
> sb.append("function showFeedbackAlert() { alert('");
> List messages = (List) getModelObject();
> for (Iterator it = messages.iterator(); it.hasNext();) {
> FeedbackMessage message = (FeedbackMessage) it.next();
> message.markRendered();
> sb.append(message.getMessage());
> sb.append("\\n");
> }
> sb.append("');");
> sb.append("};");
> return sb.toString();
> }
>
> }
>
>
> ------------------ FeedbackAlertPanel.html ----------------------------
> <wicket:panel>
> <script type="text/javascript" wicket:id="script"></script>
> </wicket:panel>
>
> ------------------ AlertFeedbackMessageFilter.java --------------------
>
> import org.apache.wicket.feedback.FeedbackMessage;
> import org.apache.wicket.feedback.IFeedbackMessageFilter;
>
> public class AlertFeedbackMessageFilter implements IFeedbackMessageFilter {
>
> private static final long serialVersionUID = 1L;
>
> public boolean accept(FeedbackMessage message) {
> return message.getLevel() == FeedbackMessage.ALERT;
> }
>
> }
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user