diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TextArea.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TextArea.java new file mode 100644 index 000000000..357cfc5be --- /dev/null +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TextArea.java @@ -0,0 +1,60 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.dojo.components; + +import java.util.Random; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.views.annotations.StrutsTag; + +import com.opensymphony.xwork2.util.ValueStack; + +/** + * Render Dojo Editor2 widget + * + */ +@StrutsTag(name="textarea", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TextareaTag", description="Renders Dojo Editor2 widget") +public class TextArea extends org.apache.struts2.components.TextArea { + + public TextArea(ValueStack stack, HttpServletRequest request, + HttpServletResponse response) { + super(stack, request, response); + } + + public void evaluateExtraParams() { + super.evaluateExtraParams(); + + boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT); + addParameter("pushId", generateId); + if ((this.id == null || this.id.length() == 0) && generateId) { + Random random = new Random(); + this.id = "widget_" + Math.abs(random.nextInt()); + addParameter("id", this.id); + } + } + + @Override + public String getTheme() { + return "ajax"; + } +} diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java index 1c568abcf..b34181b35 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/DojoTagLibrary.java @@ -35,6 +35,7 @@ import org.apache.struts2.dojo.views.velocity.components.DivDirective; import org.apache.struts2.dojo.views.velocity.components.HeadDirective; import org.apache.struts2.dojo.views.velocity.components.SubmitDirective; import org.apache.struts2.dojo.views.velocity.components.TabbedPanelDirective; +import org.apache.struts2.dojo.views.velocity.components.TextAreaDirective; import org.apache.struts2.dojo.views.velocity.components.TreeDirective; import org.apache.struts2.dojo.views.velocity.components.TreeNodeDirective; import org.apache.struts2.views.TagLibrary; @@ -60,7 +61,8 @@ public class DojoTagLibrary implements TagLibrary { TreeDirective.class, TreeNodeDirective.class, HeadDirective.class, - BindDirective.class + BindDirective.class, + TextAreaDirective.class }; return Arrays.asList(directives); } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java index 78746d05c..457f08674 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/DojoModels.java @@ -33,6 +33,7 @@ public class DojoModels { protected SubmitModel submit; protected BindModel bind; protected HeadModel head; + protected TextAreaModel textarea; private ValueStack stack; private HttpServletRequest req; @@ -52,6 +53,14 @@ public class DojoModels { return bind; } + public TextAreaModel getTextarea() { + if (textarea == null) { + textarea = new TextAreaModel(stack, req, res); + } + + return textarea; + } + public HeadModel getHead() { if (head == null) { head = new HeadModel(stack, req, res); diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/TextAreaModel.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/TextAreaModel.java new file mode 100644 index 000000000..de5ed5cd9 --- /dev/null +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/freemarker/tags/TextAreaModel.java @@ -0,0 +1,43 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.dojo.views.freemarker.tags; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.components.Component; +import org.apache.struts2.dojo.components.TextArea; +import org.apache.struts2.views.freemarker.tags.TagModel; + +import com.opensymphony.xwork2.util.ValueStack; + +/** + * @see TextArea + */ +public class TextAreaModel extends TagModel { + public TextAreaModel(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { + super(stack, req, res); + } + + protected Component getBean() { + return new TextArea(stack, req, res); + } +} diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TextareaTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TextareaTag.java new file mode 100644 index 000000000..120b10214 --- /dev/null +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TextareaTag.java @@ -0,0 +1,51 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.dojo.views.jsp.ui; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.components.Component; +import org.apache.struts2.dojo.components.TextArea; + +import com.opensymphony.xwork2.util.ValueStack; + + +/** + * @see TextArea + * + */ +public class TextareaTag extends org.apache.struts2.views.jsp.ui.TextareaTag{ + public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { + return new TextArea(stack, req, res); + } + + protected void populateParams() { + super.populateParams(); + + TextArea textArea = ((TextArea) component); + textArea.setCols(cols); + textArea.setReadonly(readonly); + textArea.setRows(rows); + textArea.setWrap(wrap); + } + +} diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/TextAreaDirective.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/TextAreaDirective.java new file mode 100644 index 000000000..e70d1d6b7 --- /dev/null +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/velocity/components/TextAreaDirective.java @@ -0,0 +1,27 @@ +package org.apache.struts2.dojo.views.velocity.components; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.components.Component; +import org.apache.struts2.dojo.components.TextArea; + +import com.opensymphony.xwork2.util.ValueStack; + +/** + * @see TextArea + */ +public class TextAreaDirective extends DojoAbstractDirective { + public String getBeanName() { + return "textarea"; + } + + protected Component getBean(ValueStack stack, HttpServletRequest req, + HttpServletResponse res) { + return new TextArea(stack, req, res); + } + + public int getType() { + return BLOCK; + } +} diff --git a/plugins/dojo/src/main/resources/template/ajax/textarea.ftl b/plugins/dojo/src/main/resources/template/ajax/textarea.ftl index 7dc57ee31..5f2f8ef01 100644 --- a/plugins/dojo/src/main/resources/template/ajax/textarea.ftl +++ b/plugins/dojo/src/main/resources/template/ajax/textarea.ftl @@ -59,4 +59,7 @@ <#if parameters.nameValue?exists> <@s.property value="parameters.nameValue"/><#t/> - \ No newline at end of file + +<#if parameters.pushId> + + \ No newline at end of file