I have strings in a databse that are raw html text and it is being displayed on a blog page. Users are able to edit the text using the TinyMCE component and therefore add formatting to their blog entries. I am using the setEscapeModelStrings(false) to correctly display the html formatting. However I would like to limit the text length.
I have created a component called LimitedTextPanel that almost works. However, when I check the length of the text to test whether or not it is over the limit, the html formatting text is included in the length. This poses a problem because text with a great deal of formatting html, which is invisible to the user, actually gets cut off way before it should be. My code for my current incorrect implementation is at the bottom. Can someone help? abstract public class LimitedTextPanel extends Panel { abstract protected AbstractLink makeMoreLink(final String id); private static final long serialVersionUID = 1L; private static final int DEFAULT_TRUNC_LEN = 150; private TruncatingTextModel truncModel; public LimitedTextPanel(final String id, final IModel model) { this(id, model, DEFAULT_TRUNC_LEN); } public LimitedTextPanel(final String id, final IModel model, final int truncLen) { super(id, model); truncModel = new TruncatingTextModel(model, truncLen); Label textLabel = new Label("text", truncModel); textLabel.setEscapeModelStrings(false); add(textLabel); AbstractLink more = makeMoreLink("more"); more.setVisible(truncModel.isTruncated()); add(more); } private class TruncatingTextModel implements IModel { private static final long serialVersionUID = 1L; private int truncLen; private IModel model; public TruncatingTextModel(final IModel model, final int truncLen) { this.truncLen = truncLen; this.model = model; } public void detach(){} public void setObject(Object arg0){} private String getText() { return (String)model.getObject(); } public Object getObject() { if(isTruncated()) { return getText().substring(0, Math.min(getText().length(), truncLen)) + "..."; } return getText(); } public boolean isTruncated() { return getText().length() > truncLen; } } } -- View this message in context: http://www.nabble.com/Limited-length-html-label-tp21243862p21243862.html Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org