Save This Page
Home » struts-2.1.8.1-src » org.apache.struts2.dojo » components » [javadoc | source]
    1   /*
    2    * $Id: TextArea.java 651946 2008-04-27 13:41:38Z apetrelli $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.struts2.dojo.components;
   23   
   24   import java.util.Random;
   25   
   26   import javax.servlet.http.HttpServletRequest;
   27   import javax.servlet.http.HttpServletResponse;
   28   
   29   import org.apache.struts2.views.annotations.StrutsTag;
   30   
   31   import com.opensymphony.xwork2.util.ValueStack;
   32   
   33   /**
   34    * <!-- START SNIPPET: javadoc -->
   35    * Render Dojo Editor2 widget
   36    * <!-- END SNIPPET: javadoc -->
   37    *
   38    */
   39   @StrutsTag(name="textarea", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TextareaTag", description="Renders Dojo Editor2 widget")
   40   public class TextArea extends org.apache.struts2.components.TextArea {
   41       private final static transient Random RANDOM = new Random();
   42   
   43       public TextArea(ValueStack stack, HttpServletRequest request,
   44           HttpServletResponse response) {
   45           super(stack, request, response);
   46       }
   47       
   48       public void evaluateExtraParams() {
   49           super.evaluateExtraParams();
   50   
   51           // generate a random ID if not explicitly set and not parsing the content
   52           Boolean parseContent = (Boolean)stack.getContext().get(Head.PARSE_CONTENT);
   53           boolean generateId = (parseContent != null ? !parseContent : true);
   54           
   55           addParameter("pushId", generateId);
   56           if ((this.id == null || this.id.length() == 0) && generateId) {
   57               // resolves Math.abs(Integer.MIN_VALUE) issue reported by FindBugs 
   58               // http://findbugs.sourceforge.net/bugDescriptions.html#RV_ABSOLUTE_VALUE_OF_RANDOM_INT
   59               int nextInt = RANDOM.nextInt();
   60               nextInt = nextInt == Integer.MIN_VALUE ? Integer.MAX_VALUE : Math.abs(nextInt);  
   61               this.id = "widget_" + String.valueOf(nextInt);
   62               addParameter("id", this.id);
   63           }
   64       }
   65   
   66       @Override
   67       public String getTheme() {
   68           return "ajax";
   69       }
   70   }

Save This Page
Home » struts-2.1.8.1-src » org.apache.struts2.dojo » components » [javadoc | source]