you're welcome! what i would like is to put it in shape and
eventually share it through wicket stuff.
i admit i got lost in all those ajax behaviours, trying to figure out
if i could avoid forcing the client of the behavior to declare the
decorator:
> @Override
> protected IAjaxCallDecorator getAjaxCallDecorator() {
> return nicEditTextAreaBehavior.NICEDIT_AJAX_BUTTON_DECORATOR;
> }
ie so that just doing textarea.add(new NicEditTextAreaBehavior());
suffices. maybe you've got an idea?
anyway, after all these hacks seem to work!
francisco
On Tue, Jun 17, 2008 at 8:11 PM, Don Hass <[EMAIL PROTECTED]> wrote:
> Here is my version that appears to work with multiple textareas in a
> single form.
>
> Usage context:
>
> final NicEditTextAreaBehavior nicEditTextAreaBehavior = new
> NicEditTextAreaBehavior(true);
>
> final TextArea body1 = new TextArea("body1");
> body1.add(nicEditTextAreaBehavior);
> form.add(body1);
>
> final TextArea body2 = new TextArea("body2");
> body2.add(nicEditTextAreaBehavior);
> form.add(body2);
>
> Form submit button:
>
> @Override
> protected IAjaxCallDecorator getAjaxCallDecorator() {
> return nicEditTextAreaBehavior.NICEDIT_AJAX_BUTTON_DECORATOR;
> }
>
> ================================
>
> public class NicEditTextAreaBehavior extends AbstractBehavior {
> private List<Component> textAreas = new ArrayList<Component>();
> private Boolean fullPanel = Boolean.TRUE;
>
> private static final ResourceReference NICEDIT_JAVASCRIPT = new
> JavascriptResourceReference(NicEditTextAreaBehavior.class,
> "nicEdit.js");
> private static final ResourceReference NICEDIT_ICONS = new
> ResourceReference(NicEditTextAreaBehavior.class,
> "nicEditorIcons.gif");
>
> public final AjaxCallDecorator NICEDIT_AJAX_BUTTON_DECORATOR = new
> AjaxCallDecorator() {
> @Override
> public CharSequence decorateScript(final CharSequence script) {
> StringBuffer js = new StringBuffer();
> for (Component component : textAreas) {
> String editorVarName = "wne" + component.getMarkupId();
> js.append(editorVarName).append(".nicInstances[0].saveContent();");
> }
> js.append(script);
> return js.toString();
> }
> };
>
> public NicEditTextAreaBehavior() {
> }
>
> public NicEditTextAreaBehavior(Boolean fullPanel) {
> this.fullPanel = fullPanel;
> }
>
> @Override
> @SuppressWarnings("unchecked")
> public void bind(Component component) {
> component.setOutputMarkupPlaceholderTag(true);
>
> textAreas.add(component);
> System.out.println("bind: " + component.getMarkupId());
> }
>
> @Override
> public void renderHead(IHeaderResponse response) {
> super.renderHead(response);
> StringBuffer js = new StringBuffer();
> response.renderJavascriptReference(NICEDIT_JAVASCRIPT);
>
> for (Component component : textAreas) {
> String editorVarName = "wne" + component.getMarkupId();
> response.renderJavascript("var " + editorVarName + ";", null);
> js.append(editorVarName).append(" = new nicEditor({iconsPath : '");
> js.append(RequestCycle.get().urlFor(NICEDIT_ICONS));
> js.append("', fullPanel :
> ").append(fullPanel).append("}).panelInstance('").append(component.getMarkupId()).append("');");
> }
>
> if (js.length() > 0) response.renderOnDomReadyJavascript(js.toString());
> }
>
> }
>
> So far it looks like it is working. Not sure if it is "best form",
> but thanks to your feedback and a little hacking I have something that
> works better than the TinyMCE stuff I have been trying to use for the
> past 2 months! Plus this is so much lighter and quick than MCE bloat.
>
> Thanks again for posting to the list since I didn't even know about
> NicEdit before your post!
>
> On Tue, Jun 17, 2008 at 1:49 PM, Don Hass <[EMAIL PROTECTED]> wrote:
>>
>> Yes, that got it working for one textarea in a form. I have been trying to
>> come up with a solution for multiple text areas in a single form now.
>>
>> On Tue, Jun 17, 2008 at 12:12 PM, francisco treacy <[EMAIL PROTECTED]> wrote:
>>>
>>> hey don,
>>>
>>> i'm sorry, i just published it too fast :) i was having some trouble
>>> with my persistence layer so i thought the model was getting updated
>>> cause wasn't hitting the db.
>>>
>>> ajax or not, it wouldn't work either way. before calling the submit
>>> button, contents have to be updated.
>>>
>>> so here i came up with a new version that works (i believe with ajax
>>> only, and with one textarea for the moment). i'm by no means an ajax
>>> expert (hmm, in fact, i dislike javascript :) so this is a call to
>>> wicket ajax gurus: could you help me improve this code?
>>>
>>> usage:
>>>
>>> (...)
>>> final NicEditTextAreaBehavior behavior = new NicEditTextAreaBehavior();
>>> textarea.add(behavior);
>>> (...)
>>>
>>> form.add(new AjaxFallbackButton("submit", form) {
>>>
>>> @Override
>>> protected IAjaxCallDecorator getAjaxCallDecorator() {
>>> return
>>> behavior.NICEDIT_AJAX_BUTTON_DECORATOR;
>>> }
>>>
>>> (...)
>>>
>>> });
>>>
>>> (...)
>>>
>>>
>>>
>>>
>>> public class NicEditTextAreaBehavior extends AbstractAjaxBehavior {
>>>
>>> private Boolean fullPanel = Boolean.TRUE;
>>>
>>> private static final ResourceReference NICEDIT_JAVASCRIPT =
>>> new
>>> JavascriptResourceReference(NicEditTextAreaBehavior.class, "nicEdit.js");
>>>
>>> private static final ResourceReference NICEDIT_ICONS = new
>>> ResourceReference(NicEditTextAreaBehavior.class,
>>> "nicEditorIcons.gif");
>>>
>>> public static final AjaxCallDecorator NICEDIT_AJAX_BUTTON_DECORATOR =
>>> new AjaxCallDecorator() {
>>> @Override
>>> public CharSequence decorateScript(final CharSequence script) {
>>> return
>>> "wicketNicEditor.nicInstances[0].saveContent();" + script;
>>> }
>>> };
>>>
>>> public NicEditTextAreaBehavior() {
>>> }
>>>
>>> public NicEditTextAreaBehavior(Boolean fullPanel) {
>>> this.fullPanel = fullPanel;
>>> }
>>>
>>> @Override
>>> protected void onBind() {
>>> super.onBind();
>>> getComponent().setOutputMarkupId(true);
>>> }
>>>
>>> @Override
>>> public void onRequest() {
>>> }
>>>
>>> @Override
>>> public void renderHead(IHeaderResponse response) {
>>> super.renderHead(response);
>>> response.renderJavascriptReference(NICEDIT_JAVASCRIPT);
>>> response.renderJavascript("var wicketNicEditor; function
>>> wicketNicEditorUpdate() {
>>> wicketNicEditor.nicInstances[0].saveContent(); };", null);
>>> response.renderOnDomReadyJavascript("wicketNicEditor = new
>>> nicEditor({iconsPath : '"+ RequestCycle.get().urlFor(
>>> NICEDIT_ICONS) +"', fullPanel : "+ fullPanel
>>> +"}).panelInstance('"
>>> + getComponent().getMarkupId() + "');");
>>> }
>>>
>>> }
>>>
>>> give it a shot and please keep me updated.
>>>
>>> francisco
>>>
>>>
>>> On Mon, Jun 16, 2008 at 9:17 PM, Don Hass <[EMAIL PROTECTED]> wrote:
>>> >
>>> > Have you tried using this in a ajax based form in Wicket? It seems that
>>> > it
>>> > does not like ajax based submits but the "solutions" in the nicedit forums
>>> > seems to be fail as well.
>>> >
>>> > The problem is that the model for the textarea you add the nic behavior
>>> > to,
>>> > never gets updated when you submit the form. In the scenario I was
>>> > testing,
>>> > it is AjaxButton for submission.
>>> >
>>> >
>>> >
>>> > francisco treacy-2 wrote:
>>> >>
>>> >> hi,
>>> >>
>>> >> i thought i'd like to share a simple behaviour for NicEdit
>>> >> (http://nicedit.com/).
>>> >>
>>> >> to use it, just download nicedit and modify NICEDIT_JAVASCRIPT and
>>> >> NICEDIT_ICONS accordingly. (i chose to put them together in the same
>>> >> package).
>>> >> if you download the basic version (without xhtml/ code view), when
>>> >> adding the behaviour pass 'false' into the constructor, in order not
>>> >> to use the full panel.
>>> >>
>>> >> of course, you can use it with multiple textareas in the same page.
>>> >>
>>> >> let me know if you run into some problem using it. should this belong
>>> >> to the wiki as well?
>>> >>
>>> >> francisco
>>> >>
>>> >>
>>> >> public class NicEditTextAreaBehavior extends AbstractBehavior {
>>> >>
>>> >> private Component<TextArea<String>> textArea;
>>> >> private Boolean fullPanel = Boolean.TRUE;
>>> >>
>>> >> private static final ResourceReference NICEDIT_JAVASCRIPT =
>>> >> new
>>> >> JavascriptResourceReference(NicEditTextAreaBehavior.class,
>>> >> "nicEdit.js");
>>> >>
>>> >> private static final ResourceReference NICEDIT_ICONS = new
>>> >> ResourceReference(NicEditTextAreaBehavior.class,
>>> >> "nicEditorIcons.gif");
>>> >>
>>> >> public NicEditTextAreaBehavior() {
>>> >> }
>>> >>
>>> >> public NicEditTextAreaBehavior(Boolean fullPanel) {
>>> >> this.fullPanel = fullPanel;
>>> >> }
>>> >>
>>> >> @Override @SuppressWarnings("unchecked")
>>> >> public void bind(Component component) {
>>> >> this.textArea = component;
>>> >> component.setOutputMarkupId(true);
>>> >> }
>>> >>
>>> >> @Override
>>> >> public void renderHead(IHeaderResponse response) {
>>> >> super.renderHead(response);
>>> >> response.renderJavascriptReference(NICEDIT_JAVASCRIPT);
>>> >> response.renderOnDomReadyJavascript("new
>>> >> nicEditor({iconsPath : '"+
>>> >> RequestCycle.get().urlFor(
>>> >> NICEDIT_ICONS) +"', fullPanel : "+
>>> >> fullPanel +"}).panelInstance('"
>>> >> + textArea.getMarkupId() + "');");
>>> >> }
>>> >>
>>> >> }
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> >> For additional commands, e-mail: [EMAIL PROTECTED]
>>> >>
>>> >>
>>> >>
>>> >
>>> > --
>>> > View this message in context:
>>> > http://www.nabble.com/NicEditTextAreaBehavior-tp17840648p17871532.html
>>> > Sent from the Wicket - User mailing list archive at Nabble.com.
>>> >
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> > For additional commands, e-mail: [EMAIL PROTECTED]
>>> >
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]