Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ramprasad
Textarea
1 Answer(s)      6 years and 11 months ago
Posted in : Struts


Textarea
Hi, this is ramprasad and i am using latest version of sturts2.0 can u help me to count the characters that are given in the textarea while typing a message and the message should be limited to 250 characters.
Can any one?


Advertisement
View Answers

February 22, 2008 at 7:10 PM


Given examples of struts 2 will show how to validate a text area that must not be null and take values between 1 to 250 characters.

Here we have created five different files including three .jsp, one .java and one.xml files.
Please create all the required files and past the given code, once you done run your application and it will validate your text area, which will not take the value more then 250 characters and cant left blank.

Index.jsp

<ul><li><a href="roseindia/characterLimit.action">Characters and limiting Example</a></li></ul>

- - - - - - - - - - - - - - - - - - - - - - - -

Struts.xml

<action name="characterLimit"> <result>/pages/chatQuestion/limitedCharacter.jsp</result> </action> <action name="characterLimit1" class="net.roseindia.limitedCharacterAction"> <result name="error">/pages/chatQuestion/limitedCharacter.jsp</result> <result name="success">/pages/chatQuestion/limitedCharacterSuccess.jsp</result> </action>

- - - - - - - - - - - - - - - - - - - - - - - -

limitedCharacter.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>Limited Characters in Text Area</title><s:head theme="ajax" /></head>

<body>
<s:form action="characterLimit1" method="POST" validate="true"> <s:textarea name="summary1" label="Brief Summary" rows="6" cols="40"/> <s:submit value="Save" align="center" /> </s:form>

</body></html>

- - - - - - - - - - - - - - - - - - - - - - - -

LimitedCharacterAction.java

package net.roseindia;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.io.PrintStream;
import java.util.List;
import java.util.*;

public class limitedCharacterAction extends ActionSupport{
private String summary1;
public String getSummary1() {
return summary1;
}
public void setSummary1(String summary1) {
this.summary1 = summary1;
}
public String execute() throws Exception{
String summaryText = getSummary1();
long countSummaryText = summaryTextcount(summaryText);
System.out.println("countSummaryText:"+countSummaryText);
if (countSummaryText >0 && countSummaryText < 250){
return SUCCESS;
}
else{
if(getSummary1().equals(""))
addFieldError("summary1","Brief Summary is required.");
if((countSummaryText > 250))
addFieldError("summary1","Brief Summary must be 1 to 250 Charaters");
return ERROR;

- - - - - - - - - - - - - - - - - - - - - - - -

limitedCharacterSuccess.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Limited Characters in Text Area</title>
<link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/>
</head>

<body>
<b>Brief Summary: </b><s:property value="summary1" /><br>
</body></html>

Thats it!!!!!
Now run the program
Good Luck



Related Tutorials/Questions & Answers:
Textarea - Struts
Textarea  Textarea Hi, this is ramprasad and i am using latest... in the textarea while typing a message and the message should be limited to 250...;characterLimit1" method="POST" validate="true"> <s:textarea
HTML - textarea tag example.
HTML - textarea tag example. Description : It is a input tag. You can enter multiple line of text in this in it. You can specifies the size of textarea...;/head> <body> <h1>HTML -- textarea tag Example. </h1>
Advertisements
Textarea Tag<html:textarea>:
Textarea Tag<html:textarea>: Information on Textarea Tag       html:textarea Tag -is use to create  a textarea element. This tag is only valid when nested inside a form tag body
The textarea tag
In this section, you will learn about the textarea tag of Spring form tag library
flexible textarea in HTML
flexible textarea in HTML  I have a textfield in my HTML form which... anyone tell me about how can i make a flexible textarea in HTML. Many Thanks!!   <textarea id="grow-me"> Start typing here to see the Text
selection box linked with textarea
selection box linked with textarea    function get_val(tot_val1...;td align= left><textarea id... database in textarea line by line onclick selected text: eg:select: anand
javascript clear textarea
javascript clear textarea...; <body> <form name="textform"> <textarea name="textarea"> This text will be removed if you click on 'Clear TextArea' button
Dynamic tree using textarea data
Dynamic tree using textarea data  I need to create a dynamic tree by using text area data(words) as child nodes in struts. Any body please help me. "very urgent". thanks in advance
TextArea in Flex4
TextArea Control in Flex4: The TextArea control is a component of both the MX... TextArea control is a multilinear, editable text field with a border. The scroll bars in MX TextArea is optional. It supports to HTML and rich text rendering
how to apply tool bar with textarea in jsp
how to apply tool bar with textarea in jsp  how to apply tool bar with textarea in jsp
TextArea Frame in Java
TextArea Frame in Java       Introduction In this section, you will learn how to create TextArea on the frame. This program uses the TextArea class of  java.awt package. Here
Textarea Tag (Form Tag) Example
Textarea Tag (Form Tag) Example       In this section, we are going to describe the textarea tag. The textarea tag is a UI tag that is used to render an HTML textarea.  Add the following code
How to capture output from console into textarea in java?
How to capture output from console into textarea in java?  Hi, I would like to know how can we display the result of a program in java into a textarea instead of displaying it on console. Thanks
Display Sorted data in TextArea
Display Sorted data in TextArea By sorting, you can arrange the data into meaningful order so that you can analyze it more effectively. Here we have one file student.txt that contains the record of several students i.e id, name, marks
Save Java Textarea Content in Html Format using FileMenu
Save Java Textarea Content in Html Format using FileMenu  Hi.. How to save the textarea content to html format...Using FileMenu Option
How to get Scrollbar value of textarea in html? - Design concepts & design patterns
How to get Scrollbar value of textarea in html?  Hi All, I have one registration page with terms & policy in read only textarea (Html input tag type). Requirement: Till user didn't scroll down textarea at the last line
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java   Hi, i m interested to send the content of my jtextarea which i have developed in netbeans IDE to the webpage's textarea. how can i do
How to get the focus from a particular textarea for some action?
How to get the focus from a particular textarea for some action?  Hi All, I have created one small swing applications with two textarea. I want to implement a search such a way that if there is a focus on the textarea-1 and i
facing problem while retrive value from Post textarea
script.I use struts framework and this is my code for post textarea. <tr>...;html:textarea property="dealPost" styleClass="inputtext" tabindex="7" styleId...://www.roseindia.net/struts/struts1/html-textarea-Tag.shtml
How can I output text typed in textarea by user on the same page?
How can I output text typed in textarea by user on the same page?  I have a basic HTML page where I have created a textarea for users comments. I...; } </script> </head> <body> Post Comment: <br><textarea
How to get the text from textarea in HTML and store it in database using javascript and jsp
How to get the text from textarea in HTML and store it in database using javascript and jsp  How to get the text from textarea in HTML and store it in database using javascript and jsp <script> function str() { <
How to make a ajax application which take data from textarea and that page is not refreshing.
How to make a ajax application which take data from textarea and that page is not refreshing.  I am doing a application in that i am using Spring Framework.I am having a text area and a submit button. On pressing submit Button
Hey guys, I'm new to this forum..select onclick show all fieds in textarea in line by line(name,address,state,country,mobile)
Hey guys, I'm new to this forum..select onclick show all fieds in textarea...;</tr> <tr> <td align= left><textarea id="TextBox1" rows="5...= left><textarea id="TextBox1" rows="5" cols="25"></textarea>
Validate TextArea
Validate TextArea      ..."> <s:textarea name="summary1" label="Brief Summary" rows="6" cols="40... the inputted text in the textarea: Here is the code to be added
HTML5 textarea tag, Example of &lt;textarea&gt; tag in html5
HTML5 textarea tag, Example of <textarea> tag in html5 Here, We...;empty string" Name of the textarea used to submit the value... to the textarea input. rows "number" It specify
No Max-height Fixed
of a Textarea with minimum fixed height but no max height fixed. Steps to develop the Auto...;body> TextArea Min-Height 100Px <textarea style="width... works auto generate the textarea of id "expandText"  and having
With Fixed Max-Height
of a Textarea with fixed Max-Height. Step 1:       Create a new file...; No Min-Height and max-height 100Px <textarea style="width... generate the textarea of id "expandText"  and having
WYSIWYG html editor in JSP
;head> <title>Toolbar with TextArea </title> <meta... with TextArea </h1> <div> <textarea name="wysiwyg"
JTextArea to Word Document
see in the given code, we have allowed the user to enter data in textarea
 

 

 

DMCA.com