473,769 Members | 6,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

to change feild colour on validation(unfi lled feilds change to red).

10 New Member
hello

i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk 1.5..

i have a login form(jsp) in which a user logs in,in case he doesnt enter his username and/or password an error is displayed using the <ul> tag and <html:errors> in the jsp. in the from class a vaidate method creates an actionerrors object adds all the errors to it and finally returns it.
the ids are linked in messageresource s.properties and appropriate message is diaplayed.
now i want to change the colour of the feild thats unfilled.. ie the username change its font to red in case it empty rather then a message.

thanks in advance.

code:

index.jsp
Expand|Select|Wrap|Line Numbers
  1. <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>
  2. <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
  3. <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic"%>
  4.  
  5.  
  6. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  7.     pageEncoding="ISO-8859-1"%>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  9.  
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  13. <meta http-equiv="Pragma" content="no-cache">
  14. <meta http-equiv="Cache-Control" content="no-cache">
  15.  
  16. <title>Welcome Page</title>
  17. <link href="example.css" rel="stylesheet" type="text/css" />
  18. </head>
  19. <body background="nexus.jpg">
  20. <div id="top">
  21. <table border="0">
  22.     <tr>
  23.         <td width="250"><img src="car.jpg" /></td>
  24.         <td width="250">
  25.         <img src="title.jpg" />
  26.         </td>
  27.         <td width="250">
  28.         <h2 align="right">
  29.         <logic:notPresent name="loginForm"    property="result" scope="session">
  30.         Welcome Please Sign In<br>
  31.         </logic:notPresent> 
  32.  
  33.         <logic:present name="loginForm" property="result" scope="session">
  34.         welcome <bean:write name="loginForm" property="uid" />!!
  35.         <html:link action="/logout">LogOut</html:link>
  36.             <html:link action="/viewinfo">Account Info</html:link>
  37.         </logic:present></h2>
  38.         </td>
  39.     </tr>
  40. </table>
  41. <hr width="100%">
  42. </div>
  43.  
  44.  
  45. <div id="leftnavigation">
  46. <h3>FEW LINKS</h3>
  47. <a href="newcar.jsp">New Car</a><br>
  48. <a href="oldcar.jsp">Old Car</a><br>
  49. <a href="Search.jsp">Search</a></div>
  50.  
  51. <div id="content">
  52. <h1>Welcome to the car portal</h1>
  53. <p>This is the place where you can check out all the latest cars. <br>
  54. Not only this,you can also add your old cars for sale.<br>
  55. With our huge member base we are sure to get you a deal you cannot refuse. <br>
  56. <u>Register today to see the available cars at most affordable prices</u>.</p>
  57.  
  58. <h2>New Launches</h2>
  59. <img src="car1.jpg" /></div>
  60.  
  61. <div id="rightnavigation">
  62. <html:errors /> 
  63. <html:form action="/login">
  64.  
  65.     <logic:present name="loginForm" property="flag" scope="session">
  66.     <font size="2" color="red">UserID/Password Does not exist.<br> New Users please register</font>
  67.     </logic:present>
  68.  
  69.     <logic:notPresent name="loginForm" property="result" scope="session">
  70.  
  71.  
  72.         <h2>LOGIN HERE!!</h2>
  73.         <p>Enter your user id and password to log in</p>
  74.     USER NAME<font size="-1" color="red">*</font> <html:text property="uid" />
  75.         <br>
  76.     PASSWORD<font size="-1" color="red">*</font>  <html:password property="psswd" />
  77.         <br>
  78.         <html:submit value="LOG IN" />
  79.         <br>
  80.         <br>
  81.  
  82.  
  83.  
  84.         <html:link forward="nregister">Register Here!!</html:link>
  85.  
  86.     </logic:notPresent>
  87.  
  88. </html:form>
  89. </div>
  90. </body>
  91. </html>
LoginForm.java
Expand|Select|Wrap|Line Numbers
  1. package form;
  2.  
  3. import javax.servlet.http.HttpServletRequest;
  4. import org.apache.struts.action.ActionErrors;
  5. import org.apache.struts.action.ActionForm;
  6. import org.apache.struts.action.ActionMapping;
  7. import org.apache.struts.action.ActionMessage;
  8.  
  9.  
  10. public class LoginForm extends ActionForm
  11. {
  12.  
  13.      String Uid;
  14.      String Psswd;
  15.      String result;
  16.      String flag;
  17.  
  18.  
  19.     public String getFlag() {
  20.         return flag;
  21.     }
  22.     public void setFlag(String flag) {
  23.         this.flag = flag;
  24.     }
  25.  
  26.     public String getResult() {
  27.             return result;
  28.         }
  29.         public void setResult(String result) {
  30.             this.result = result;
  31.         }
  32.  
  33.  
  34.     public String getUid() {
  35.         return Uid;
  36.     }
  37.     public void setUid(String uid) {
  38.         Uid = uid;
  39.     }
  40.     public String getPsswd() {
  41.         return Psswd;
  42.     }
  43.     public void setPsswd(String psswd) {
  44.         Psswd = psswd;
  45.     }
  46.  
  47.     public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
  48.     {
  49.         ActionErrors actionErrors= new ActionErrors();
  50.  
  51.         if(getUid()=="")
  52.         {
  53.             actionErrors.add("Username",new ActionMessage("uid.required"));
  54.         }
  55.  
  56.         if(getPsswd()=="")
  57.         {
  58.             actionErrors.add("Password",new ActionMessage("psswd.required"));
  59.         }
  60.  
  61.         return actionErrors;
  62.     } 
  63.  
  64.  public String test(String result)
  65.  {    String act;
  66.      if((getUid()=="") || (getPsswd()==""))
  67.         {
  68.          act=null;
  69.         }
  70.         else
  71.         {
  72.         act="true";
  73.         }
  74.      return act;}
  75. }
  76.  
MessageResource s.properties
Expand|Select|Wrap|Line Numbers
  1. # -- Standard errors --
  2. errors.header=<UL>
  3. errors.prefix=<LI><B><FONT COLOR="RED">
  4. errors.suffix=</FONT></B></LI>
  5. errors.footer=</UL>
  6.  
  7.  
  8. # -- Custom validation messages --
  9.  
  10. uid.required=Username Required.
  11. uid.short=Username is too short.
  12. psswd.required=Password Required.
  13. psswd.short=Password is too short.
  14. rpsswd.required=Re Enter the password same as password.
  15. fname.required=First Name Required.
  16. lname.required=Last Name Required.
  17. email.required=Email Address Required.
  18. email.invalid=Invalid Email Address.
  19. email.incorrect=Incorrect Format for an Email Id.
  20. value.match=Username and password are same.
  21. value.notmatch=Password and retyped password don't match.
  22. digit.incorrect=Zip,Contact no and Date of birth must have only digits.
Aug 17 '09 #1
6 4520
r035198x
13,262 MVP
So you have a CSS problem rather than a Java problem. Basically you want to change the font-color property based on whether the HTML control is filled or not after a failed submit.
Aug 17 '09 #2
gavy7210
10 New Member
yes but through struts..
using the action errors tag..
i want to use the property of a bean to update the colour..
something like that..
to chnge colour isnt priority using struts to do it is
Aug 17 '09 #3
r035198x
13,262 MVP
So use simple if-else logic to set the style or have two labels with different font and use simple if-else logic to decide which one to display.
Aug 18 '09 #4
gavy7210
10 New Member
taking a que from what u said n using struts i solved the problem as below..

<logic:messages Present>
held the form when errors were there(and the feilds wre red) and a copy was kept in messagesNotPres ent tag.. normal feild display..

thanks r035198x
Aug 19 '09 #5
gavy7210
10 New Member
how do i close this thread!!
Aug 19 '09 #6
JosAH
11,448 Recognized Expert MVP
@gavy7210
You can't, only moderators can do that; I'll close it for you.

kind regards,

Jos
Aug 19 '09 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2426
by: Muffinman | last post by:
Hi, I'm trying to build a script which will fade the colour of my text to another. Now I've got here a litte problem. Whene ever I want to replace one of the numbers in: document.getElementById("main_txt").style.color = "rgb(0,0,0)"; by a var, something I can control, like: rgb(red, green, blue) of which I made shure it were integers by parseInt(); I always get the error in IE that there is an invalid value for the property. I can not...
15
1626
by: marko | last post by:
Hi! A have a problem. I have a table containing ID,Brend,Model,Colour,Price. The Colour field has colours like: YELLOW/BLACK/RED, YELLOW/RED, BLUE, BLUE/NAVY/RED/CHARCOAL. Now i would like to shorten them like this YELLOW->YEL,BLACK->BLK,WHITE->WHT... so that the colour field would look like this YEL/BLK/RED and so on. Please help!
4
2154
by: Lachlan Hunt | last post by:
Hi, I'm looking for an interoperable method of determining the current background colour of an element that is set using an external stylesheet. I've tried: elmt.style.backgroundColor; but that only works if the colour has been set using the style attribute or previously set using script. I've also tried:
2
1646
by: Vinny | last post by:
A customer wants me to convert a VB app I wrote for them into a web app for remote users to do data entry. So, I'm writing a small ASP program which prompts the user for data, much like a VB program. I would like to interactively validate the data as they are entering it, rather than waiting until they submit the form. So, I am doing something like this (this is a very simple example): <head>
0
1087
by: Graham35p | last post by:
I have had a program running which includes progress bars. It worked OK with the settings I had in the properties box and code i.e. colour red and continuous bar. But I recently changed my PCs display settings in (Control Panel >Display) from classic Windows to XP. Now when I run my VB program, the colour of the progress bar ignors the property settings and code. The previously continuous bar is now blocks. I am running Visual Basic.Net 2005.
2
4242
by: sathiyamurthy | last post by:
Hi all I need help regarding button colour change in vc++. tell me the steps to implement. also i want to change the button label text size. is there any function for that. Regards sam
3
1682
by: nehaquick | last post by:
I have a form where the user has to enter values. to make it easy for the user there are some values already present in the feilds but if the user wants he can change it. the problem is i want to have a button which upon clicking should enter the value "null" to the feild. one of the text feild code i m displaying here <input name="departFrom" type="text" id="departFrom" <?php if ($_POST=='Void') { echo "NULL"; exit(); }...
2
1305
by: punitshrivastava | last post by:
hello friends, i m working in php .i wsnt to know about feild validations .As i want to select data from combobox .according to that selected data feilds is to be editable Say for example : In combobox three values r to be filled . first name. last name age Now if we select first name then age & lastname feild should be disable. only firstname feild should be enable. similarly for two feilds. As we enter the value in respective feilds...
4
1932
by: sgxbytes | last post by:
Hi, My html has <Table style="year-button-archive" width="60%" > <tr> <td class="gold" > <a title="year">By Year:</a> <td class="gold"> <a id = "2008" title="2008" href="../announcementList.do?year=2008"> 2008
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.