Author: tmjee Date: Fri Jul 21 22:33:27 2006 New Revision: 424526 URL: http://svn.apache.org/viewvc?rev=424526&view=rev Log: WW-1389 - Add If, Else and ElseIf to freemarker model
Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseIfModel.java (with props) struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseModel.java (with props) struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/IfModel.java (with props) Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ElseIf.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/If.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/StrutsModels.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ElseIf.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ElseIf.java?rev=424526&r1=424525&r2=424526&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ElseIf.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ElseIf.java Fri Jul 21 22:33:27 2006 @@ -75,17 +75,16 @@ //make the comparision answer = (Boolean) findValue(test, Boolean.class); - return answer != null && answer.booleanValue(); - } - - public boolean end(Writer writer, String body) { if (answer == null) { answer = Boolean.FALSE; } - if (answer.booleanValue()) { stack.getContext().put(If.ANSWER, answer); } + return answer != null && answer.booleanValue(); + } + + public boolean end(Writer writer, String body) { return super.end(writer, ""); } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/If.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/If.java?rev=424526&r1=424525&r2=424526&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/If.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/If.java Fri Jul 21 22:33:27 2006 @@ -84,12 +84,12 @@ if (answer == null) { answer = Boolean.FALSE; } - + + stack.getContext().put(ANSWER, answer); return answer.booleanValue(); } public boolean end(Writer writer, String body) { - stack.getContext().put(ANSWER, answer); return super.end(writer, body); } Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseIfModel.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseIfModel.java?rev=424526&view=auto ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseIfModel.java (added) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseIfModel.java Fri Jul 21 22:33:27 2006 @@ -0,0 +1,41 @@ +/* + * $Id: I18nModel.java 420385 2006-07-10 00:57:05Z tmjee $ + * + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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.freemarker.tags; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.components.Component; +import org.apache.struts2.components.ElseIf; + +import com.opensymphony.xwork2.util.OgnlValueStack; + +/** + * @version $Date$ $Id$ + */ +public class ElseIfModel extends TagModel { + + public ElseIfModel(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { + super(stack, req, res); + } + + protected Component getBean() { + return new ElseIf(stack); + } + +} Propchange: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseIfModel.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseModel.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseModel.java?rev=424526&view=auto ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseModel.java (added) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseModel.java Fri Jul 21 22:33:27 2006 @@ -0,0 +1,42 @@ +/* + * $Id: I18nModel.java 420385 2006-07-10 00:57:05Z tmjee $ + * + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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.freemarker.tags; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.components.Component; +import org.apache.struts2.components.Else; + +import com.opensymphony.xwork2.util.OgnlValueStack; + +/** + * + * @version $Date$ $Id$ + */ +public class ElseModel extends TagModel { + + public ElseModel(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { + super(stack, req, res); + } + + protected Component getBean() { + return new Else(stack); + } + +} Propchange: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/ElseModel.java ------------------------------------------------------------------------------ svn:eol-style = native Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/IfModel.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/IfModel.java?rev=424526&view=auto ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/IfModel.java (added) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/IfModel.java Fri Jul 21 22:33:27 2006 @@ -0,0 +1,41 @@ +/* + * $Id: I18nModel.java 420385 2006-07-10 00:57:05Z tmjee $ + * + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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.freemarker.tags; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.components.Component; +import org.apache.struts2.components.If; + +import com.opensymphony.xwork2.util.OgnlValueStack; + +/** + * @version $Date$ $Id$ + */ +public class IfModel extends TagModel { + + + public IfModel(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { + super(stack, req, res); + } + + protected Component getBean() { + return new If(stack); + } +} Propchange: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/IfModel.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/StrutsModels.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/StrutsModels.java?rev=424526&r1=424525&r2=424526&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/StrutsModels.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/tags/StrutsModels.java Fri Jul 21 22:33:27 2006 @@ -74,6 +74,9 @@ protected TreeModel treeModel; protected UpDownSelectModel updownselect; protected OptGroupModel optGroupModel; + protected IfModel ifModel; + protected ElseModel elseModel; + protected ElseIfModel elseIfModel; public StrutsModels(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { @@ -427,5 +430,26 @@ optGroupModel = new OptGroupModel(stack, req, res); } return optGroupModel; + } + + public IfModel getIf() { + if (ifModel == null) { + ifModel = new IfModel(stack, req, res); + } + return ifModel; + } + + public ElseModel getElse() { + if (elseModel == null) { + elseModel = new ElseModel(stack, req, res); + } + return elseModel; + } + + public ElseIfModel getElseif() { + if (elseIfModel == null) { + elseIfModel = new ElseIfModel(stack, req, res); + } + return elseIfModel; } }