Add a bunch of handlers (lazy to enumerate them)
git-svn-id: https://svn.apache.org/repos/asf/struts/sandbox/trunk@727101 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java
index 06e4e2e..e5a479e 100644
--- a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java
+++ b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/DefaultTagHandlerFactory.java
@@ -20,8 +20,12 @@
*/
package org.apache.struts2.views.java;
-public class DefaultTagHandlerFactory implements TagHandlerFactory {
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+public class DefaultTagHandlerFactory implements TagHandlerFactory {
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultTagHandlerFactory.class);
+
private Class tagHandlerClass;
public DefaultTagHandlerFactory(Class tagHandlerClass) {
@@ -34,14 +38,14 @@
th.setNext(next);
return th;
} catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if (LOG.isErrorEnabled())
+ LOG.error("Failed to instantiate tag handler class [#0]", e, tagHandlerClass.getName());
} catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if (LOG.isErrorEnabled())
+ LOG.error("Failed to instantiate tag handler class [#0]", e, tagHandlerClass.getName());
} catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if (LOG.isErrorEnabled())
+ LOG.error("Failed to instantiate tag handler class [#0]", e, tagHandlerClass.getName());
}
return null;
}
diff --git a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java
new file mode 100644
index 0000000..0a6e0fe
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.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.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+import com.opensymphony.xwork2.util.TextUtils;
+
+public class ResetHandler extends AbstractTagHandler implements TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String, Object> params = context.getParameters();
+ Attributes attrs = new Attributes();
+
+ boolean isButton = "button".equals(params.get("type"));
+
+ attrs.addDefaultToEmpty("name", params.get("name"))
+ .add("type", "reset")
+ .addIfExists("value", params.get("nameValue"), false)
+ .addIfExists("tabindex", params.get("tabindex"))
+ .addIfExists("id", params.get("id"))
+ .addIfExists("class", params.get("cssClass"))
+ .addIfExists("style", params.get("cssStyle"));
+
+ if (!isButton)
+ attrs.addIfExists("title", params.get("title"));
+
+ super.start("input", attrs);
+ if (isButton) {
+ String label = (String) params.get("label");
+ if (TextUtils.stringSet(label))
+ characters(label);
+ }
+
+ super.end("input");
+ }
+}
+
diff --git a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
index a949730..1cb5eff 100644
--- a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
+++ b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SimpleTheme.java
@@ -42,7 +42,11 @@
put("file", new FactoryList(FileHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
put("password", new FactoryList(PasswordHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
put("label", new FactoryList(LabelHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
+ put("reset", new FactoryList(ResetHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
+ put("submit", new FactoryList(SubmitHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
+ put("textarea", new FactoryList(TextAreaHandler.class, ScriptingEventsHandler.class, CommonAttributesHandler.class));
put("actionerror", new FactoryList(ActionErrorHandler.class));
+ put("token", new FactoryList(TokenHandler.class));
put("actionmessage", new FactoryList(ActionMessageHandler.class));
put("head", new FactoryList(HeadHandler.class));
put("hidden", new FactoryList(HiddenHandler.class));
diff --git a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java
new file mode 100644
index 0000000..30e705a
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/SubmitHandler.java
@@ -0,0 +1,86 @@
+/*
+ * $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.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+import com.opensymphony.xwork2.util.TextUtils;
+
+public class SubmitHandler extends AbstractTagHandler implements TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String, Object> params = context.getParameters();
+ Attributes attrs = new Attributes();
+
+ String type = TextUtils.noNull((String) params.get("type"), "input");
+ String body = (String) params.get("body");
+
+ if ("button".equals(type)) {
+ attrs.addIfExists("name", params.get("name"))
+ .add("type", "submit")
+ .addIfExists("value", params.get("nameValue"), false)
+ .addIfTrue("disabled", params.get("disabled"))
+ .addIfExists("tabindex", params.get("tabindex"))
+ .addIfExists("id", params.get("id"))
+ .addIfExists("class", params.get("cssClass"))
+ .addIfExists("style", params.get("cssStyle"));
+
+ start("button", attrs);
+
+ //button body
+ if (TextUtils.stringSet(body))
+ characters(body, false);
+ else if (params.containsKey("label")) {
+ String label = (String) params.get("label");
+ if (TextUtils.stringSet(label))
+ characters(label, false);
+ }
+
+ end("button");
+ } else if ("image".equals(type)) {
+ if (TextUtils.stringSet(body))
+ characters(body, false);
+ attrs.addIfExists("src", params.get("src"), false)
+ .add("type", "image")
+ .addIfExists("alt", params.get("label"));
+
+ start("input", attrs);
+ end("input");
+ } else {
+ attrs.addIfExists("name", params.get("name"))
+ .addIfExists("value", params.get("nameValue"), false)
+ .addIfTrue("disabled", params.get("disabled"))
+ .addIfExists("tabindex", params.get("tabindex"))
+ .addIfExists("id", params.get("id"))
+ .addIfExists("class", params.get("cssClass"))
+ .addIfExists("style", params.get("cssStyle"));
+
+ start("submit", attrs);
+ end("submit");
+ }
+ }
+}
+
+
diff --git a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java
new file mode 100644
index 0000000..35f5f8e
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextAreaHandler.java
@@ -0,0 +1,54 @@
+/*
+ * $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.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+import com.opensymphony.xwork2.util.TextUtils;
+
+public class TextAreaHandler extends AbstractTagHandler implements TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String, Object> params = context.getParameters();
+ Attributes attrs = new Attributes();
+
+ attrs.addDefaultToEmpty("name", params.get("name"))
+ .addDefaultToEmpty("cols", params.get("cols"))
+ .addDefaultToEmpty("rows", params.get("rows"))
+ .addIfExists("wrap", params.get("wrap"))
+ .addIfTrue("disabled", params.get("disabled"))
+ .addIfTrue("readonly", params.get("readonly"))
+ .addIfExists("tabindex", params.get("tabindex"))
+ .addIfExists("id", params.get("id"))
+ .addIfExists("class", params.get("cssClass"))
+ .addIfExists("style", params.get("cssStyle"))
+ .addIfExists("title", params.get("title"));
+ super.start("textarea", attrs);
+ String value = (String) params.get("nameValue");
+ if (TextUtils.stringSet(value))
+ characters(value);
+ super.end("textarea");
+ }
+}
\ No newline at end of file
diff --git a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java
index 5847b11..a43aa34 100644
--- a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java
+++ b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TextFieldHandler.java
@@ -31,7 +31,6 @@
public void generate() throws IOException {
Map<String, Object> params = context.getParameters();
Attributes a = new Attributes();
- a.put("type", "text");
a.addDefaultToEmpty("name", params.get("name"))
.addIfExists("size", params.get("size"))
diff --git a/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java
new file mode 100644
index 0000000..8b65ce4
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/main/java/org/apache/struts2/views/java/simple/TokenHandler.java
@@ -0,0 +1,53 @@
+/*
+ * $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.views.java.simple;
+
+import org.apache.struts2.views.java.TagGenerator;
+import org.apache.struts2.views.java.Attributes;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class TokenHandler extends AbstractTagHandler implements TagGenerator {
+
+ public void generate() throws IOException {
+ Map<String, Object> params = context.getParameters();
+ Attributes attrs = new Attributes();
+
+ //first input
+ attrs.add("type", "hidden")
+ .addDefaultToEmpty("name", params.get("tokenNameField"), false)
+ .addDefaultToEmpty("value", params.get("name"));
+
+ start("input", attrs);
+ end("input");
+
+ //second input
+ attrs = new Attributes();
+ attrs.add("type", "hidden")
+ .addDefaultToEmpty("name", params.get("name"), false)
+ .addDefaultToEmpty("value", params.get("token"));
+
+ start("input", attrs);
+ end("input");
+ }
+}
+
diff --git a/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java
new file mode 100644
index 0000000..a218744
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/ResetTest.java
@@ -0,0 +1,86 @@
+/*
+ * $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.views.java.simple;
+
+import org.apache.struts2.components.File;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.Reset;
+
+public class ResetTest extends AbstractCommonAttributesTest {
+ private Reset tag;
+
+ public void testRenderResetButton() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setType("button");
+ tag.setLabel("some label");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<input name='name' type='reset' value='val1' tabindex='1' id='id1' class='class1' style='style1'>some label</input>");
+ assertEquals(expected, output);
+ }
+
+ public void testRenderResetNoType() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setLabel("some label");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<input name='name' type='reset' value='val1' tabindex='1' id='id1' class='class1' style='style1' title='title'></input>");
+ assertEquals(expected, output);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.tag = new Reset(stack, request, response);
+ }
+
+ @Override
+ protected UIBean getUIBean() {
+ return tag;
+ }
+
+ @Override
+ protected String getTagName() {
+ return "reset";
+ }
+}
+
+
diff --git a/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java
new file mode 100644
index 0000000..fff89a8
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java
@@ -0,0 +1,143 @@
+/*
+ * $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.views.java.simple;
+
+import org.apache.struts2.components.File;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.Submit;
+
+public class SubmitTest extends AbstractCommonAttributesTest {
+ private Submit tag;
+
+ public void testRenderButtonWithBody() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setDisabled("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setLabel("some label");
+ tag.setType("button");
+ tag.addParameter("body", "<span>hey hey hey, here I go now</span>");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<button name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'><span>hey hey hey, here I go now</span></button>");
+ assertEquals(expected, output);
+ }
+
+ public void testRenderButtonWithLabel() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setDisabled("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setLabel("Just as soon as I belong, than it's time I disappear");
+ tag.setType("button");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<button name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'>Just as soon as I belong, than it's time I disappear</button>");
+ assertEquals(expected, output);
+ }
+
+ public void testRenderButtonSubmit() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setDisabled("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setLabel("label");
+ tag.setType("input");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<submit name='name' value='val1' tabindex='1' id='id1' class='class1' style='style1'></submit>");
+ assertEquals(expected, output);
+ }
+
+ public void testRenderButtonWithoutType() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setDisabled("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setLabel("label");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<submit name='name' value='val1' tabindex='1' id='id1' class='class1' style='style1'></submit>");
+ assertEquals(expected, output);
+ }
+
+ public void testRenderButtonImage() {
+ tag.setSrc("http://somesource/image.gif");
+ tag.setLabel("alt text");
+ tag.setType("image");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<button name='name' type='submit' value='val1' tabindex='1' id='id1' class='class1' style='style1'><span>hey hey hey, here I go now</span></button>");
+ assertEquals(expected, output);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.tag = new Submit(stack, request, response);
+ }
+
+ @Override
+ protected UIBean getUIBean() {
+ return tag;
+ }
+
+ @Override
+ protected String getTagName() {
+ return "submit";
+ }
+}
diff --git a/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java
new file mode 100644
index 0000000..aa4e226
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java
@@ -0,0 +1,86 @@
+/*
+ * $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.views.java.simple;
+
+import org.apache.struts2.components.TextField;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.TextArea;
+
+public class TextAreaTest extends AbstractCommonAttributesTest {
+ private TextArea tag;
+
+ public void testRenderTextArea() {
+ tag.setName("name");
+ tag.setValue("val1");
+ tag.setDisabled("true");
+ tag.setReadonly("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+ tag.setRows("1");
+ tag.setCols("2");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<textarea name='name' cols='2' rows='1' tabindex='1' id='id1' class='class1' style='style1' title='title'>val1</textarea>");
+ assertEquals(expected, output);
+ }
+
+ public void testRenderTextAreaDefaults() {
+ tag.setValue("val1");
+ tag.setDisabled("true");
+ tag.setReadonly("true");
+ tag.setTabindex("1");
+ tag.setId("id1");
+ tag.setCssClass("class1");
+ tag.setCssStyle("style1");
+ tag.setTitle("title");
+
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+ String expected = s("<textarea name='' cols='' rows='' tabindex='1' id='id1' class='class1' style='style1' title='title'>val1</textarea>");
+ assertEquals(expected, output);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.tag = new TextArea(stack, request, response);
+ }
+
+ @Override
+ protected UIBean getUIBean() {
+ return tag;
+ }
+
+ @Override
+ protected String getTagName() {
+ return "textarea";
+ }
+}
diff --git a/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java
new file mode 100644
index 0000000..3de0c59
--- /dev/null
+++ b/struts2-javatemplates-plugin/src/test/java/org/apache/struts2/views/java/simple/TokenTest.java
@@ -0,0 +1,69 @@
+/*
+ * $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.views.java.simple;
+
+import org.apache.struts2.components.TextField;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.components.Token;
+import com.opensymphony.xwork2.ActionContext;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+public class TokenTest extends AbstractTest {
+ private Token tag;
+
+ public void testRenderTokenTag() {
+ tag.setName("name");
+ tag.setValue("val1");
+
+ tag.evaluateParams();
+ map.putAll(tag.getParameters());
+ theme.renderTag(getTagName(), context);
+ String output = writer.getBuffer().toString();
+
+
+ //token id is random
+ String pattern = s("<input type='hidden' name='struts.token.name' value='name'></input><input type='hidden' name='name' value='.*?'></input>");
+ assertTrue(Pattern.matches(pattern, output));
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.tag = new Token(stack, request, response);
+
+ Map map = new HashMap();
+ map.put(ActionContext.SESSION, new HashMap());
+ ActionContext.setContext(new ActionContext(map));
+ }
+
+ @Override
+ protected UIBean getUIBean() {
+ return tag;
+ }
+
+ @Override
+ protected String getTagName() {
+ return "token";
+ }
+}