Erik van Oosten ha scritto:
Hi Daniele,

Probably the best action is to look at the source of MultiLineLable, copy it to your own sources and adapt it at will. This approach has 2 advantages: 1) it keeps the wicket library small and focused, 2) you can code it exactly the way you want.

Regards,
   Erik.



Ok extend the class, and all works now. This is my class, if someone need it:


import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.string.AppendingStringBuffer;

/**
* estende MultiLineLabel di wicket per utilizzare solamente <br> come sostituzione degli a-capo
* @author daniele sala
* @date 04-06-2009
*/
public class MultiLineLabel extends org.apache.wicket.markup.html.basic.MultiLineLabel {
   public MultiLineLabel(String id) {
       super(id);
   }

   public MultiLineLabel(String id, String label) {
       super(id, label);
   }

   public MultiLineLabel(String id, IModel<?> model) {
       super(id, model);
   }

   /**
* @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
    */
   @Override
protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
   {
final CharSequence body = this.toMultilineMarkup(getDefaultModelObjectAsString());
       replaceComponentTagBody(markupStream, openTag, body);
   }
/** * Converts a String to multiline HTML markup by replacing newlines with line break entities
    * (&lt;br/&gt;).
    *
    * @param s
    *            String to transform
* @return String with all single occurrences of newline replaced with &lt;br/&gt;.
    */
   private CharSequence toMultilineMarkup(final CharSequence s) {
       if (s == null) {
           return null;
       }

       final AppendingStringBuffer buffer = new AppendingStringBuffer();

       for (int i = 0; i < s.length(); i++) {
           final char c = s.charAt(i);

           switch (c) {
               case '\n':
                   buffer.append("<br/>");
                   break;
case '\r':
                   break;
default:
                   buffer.append(c);
                   break;
           }
       }
       return buffer;
   }
}




Daniele

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to