Ankit Pradhan

Greenhorn
+ Follow
since Jan 05, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ankit Pradhan

I have tested the SimpleDateFormat class but none of the format supported for parsing will go with +5:30 part of the date string.

Please give me the format which could be used for parsing the string.

Thanks
14 years ago
I dont know how to convert from following String to Java.util.Date:

"15-SEP-06 10.27.31.436332 AM +05:30"

The above result is obtained when i get the System Time Stamp from Oracle database of mine.

Plesee help ASAP.
14 years ago
Hi
I need to write a Java logic which would tell whether two dates are equal or not. The problem is that the two dates which i am getting is in the String format from somewhere.
e.g.
These dates are equal (that is known)
"15-SEP-06 10.27.31.436332 AM +05:30"
"14-SEP-06 10.57.31.436213 PM -06:00"

But what Java logic i should write which compare these type of dates and let me know in terms of interger(-1, 0, 1) if they are equal or not.

Please respond ASAP.
I have tried the solution like compare(..) but somehow the timezone trick is missing.

Thanks in advance.
14 years ago
it was not as tough as it is sometimes mentioned by some of the ranchers here ...
but in all a good experience ...

Thanks for the SCJP Forum.
14 years ago
Since class B is an abstrat class itself so it is not even necessary for it to implement any of the abstract methods of the super class.
Moreover since m2 is not an abstract method in class A, so any class which extends class A(whether it may be itself abstract or not) doesnt need to implement or declare this method.So option B is not right.

Answer C is perfectly all right because there will be no harm if you override the m2 method of class A in class B. Even if you declare the method m2() as abstract in class B then also it will work.(Remember class B is an abstract class & only abstract classes can have abtract methods).

Basically an abstract class is a sort of Contract between the implementing class and itself. It says that the implementing class will always implement the abstract methods of the abstract class.
If you take the example of "interfaces", it will be clear that interfaces are 100% abstract classes in other sense. All of the method declaration given inside the Interface will internally be treaten by the compiler like
"public abstract".

Hope that clarifies.
You can refer any Standard Java reference guide for these concepts.

Regards,
Ankit Pradhan
abstract class A
{
abstract short m1();
short m2() { return (short) 420; }
}

abstract class B extends A
{
// missing the code ??
short m1() { return (short) 42; }
}

which of the following statements are true?
A. Thc code will compile with no changes.

B. Class B must either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.

C.It is legal, but not required, for Class B to either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.


I didn�t understand the B and C options. A and C are the correct Answer. Why C is the correct answer?
Can any one tell about abstract class and method? If any abstract method extends another abstract class then what we have does in the base abstract method? Where I can get good java study material?
Hi
The shrinking of text field happens bcoz the layout resizes the shape of each and every component placed on it, whenever there is any change in the size of the window.
One way to resolve this problem is to use : JToolBar
Try the following code:

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.*;

public final class Temp3{

JToolBar toolBar = new JToolBar();
JTextField textField = new JTextField();
JPanel panel = null;
GridBagConstraints c = null;
public static void main(String[] args)
{
JFrame f = new JFrame("test");
f.setLayout(new GridBagLayout());
panel = new JPanel();
panel.setLayout(new GridBagLayout());
c = new GridBagConstraints();
panel.add(new JTextField(24),c);

toolBar.add(panel);
toolBar.setFloatable(false);

f.getContentPane().add(toolBar);
f.pack();
f.setVisible(true);

}
}
15 years ago
The problem is resolved now...
the path of application.properties was not mentioned correctly in strust-config.xml.... by changing it, the application started working fine...
15 years ago
Try to use this in the starting of ur "web.xml"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

use the string as it is with no syntactical differences....
remove any other doctype u are using in web.xml...
15 years ago
Hi
I am using Struts validator framework checking for the integer type input for a particular field on the JSP.
All is working fine, except the message which the validator framework pops when we give a wrong input....although validator stops the flow to the same page but the message which it pops up is coming blank....

the excerpt of Validation.xml is:
...
...
<form-validation>
<formset>
<form name="/AddUpdateEmployee">

// "AddUpdateEmployee" is the action-mapping in Struts-config.xml

<field property="empId" depends="integer">
<arg0 key="errors.empId" resource="true"/>

</field>
...
...

and the code for "integer" function in "Validator-rules.xml" is:

<validator name="integer"
classname="org.apache.struts.util.StrutsValidator"
method="validateInteger"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="required"
msg="errors.integer"
jsFunctionName="IntegerValidations">
<javascript>
<![CDATA[
function validateInteger(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oInteger = new employeeActionForm_IntegerValidations();
for (x in oInteger) {
if (form[oInteger[x][0]] != undefined) {
if ((form[oInteger[x][0]].type == 'text' ||
form[oInteger[x][0]].type == 'textarea' ||
form[oInteger[x][0]].type == 'select-one' ||
form[oInteger[x][0]].type == 'radio') &&
(form[oInteger[x][0]].value.length > 0)) {
var iValue = parseInt(form[oInteger[x][0]].value);
if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
if (i == 0) {
focusField = form[oInteger[x][0]];
}
fields[i++] = oInteger[x][1];
bValid = false;
}
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return bValid;
}
]]>
</javascript>
</validator>

......
......
vlaues in "application.properties"
....
errors.integer={0} must be an integer.
errors.empId=Employee ID
....
when i give a wrong input although the control remains on the same page but a blank popup occurs.... but what exactly shud happen is the popup shud contain the message specified in the "key" of application.properties which is in this case "errors.integer"

Please help....
15 years ago
hey i got the error....
actually there was a mismatch of "datePattern" and "datePatternStrict" in validation.xml and validator-rules.xml...
in validation.xml i used "datePattern" and in validator-rules.xml i used "datePatternStrict"...
now it is prompting for the correct pattern of date...
thx guys
15 years ago
you need to have the latest version of the struts jar file from the apache site (struts.jar)... you can download it and rename it according to ur need...
but in the build.xml u have to make a refrence of it so that on deployement time in shud go into in the /WEB-INF/lib folder.
Now depending upon the usage,apart from this u shud also have:
commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-fileupload.jar
commons-logging.jar
commons-validator.jar
servlet-api.jar
j2ee.jar

as far as ".tld" and ".dtd" files are concerned it all depends upon ur code whether u r using these predefined tag libs in ur JSP code or not...
15 years ago
Hi
I am using Struts validator framework checking for the integer type input for a particular field on the JSP.
All is working fine, except the message which the validator framework pops when we give a wrong input....
the excerpt of Validation.xml is:
...
...
<form-validation>
<formset>
<form name="/AddUpdateEmployee">
// "AddUpdateEmployee" is the action-mapping in Struts-config.xml
<field
property="empId"
depends="integer">
<arg0
key="errors.empField.integer" resource="true"/>

</field>
...
...

and the code for "integer" function in Validator-rules.xml is:
<validator name="integer"
classname="org.apache.struts.util.StrutsValidator"
method="validateInteger"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="required"
msg="errors.integer"
jsFunctionName="IntegerValidations">
<javascript>
<![CDATA[
function validateInteger(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oInteger = new employeeActionForm_IntegerValidations();
for (x in oInteger) {
if (form[oInteger[x][0]] != undefined) {
if ((form[oInteger[x][0]].type == 'text' ||
form[oInteger[x][0]].type == 'textarea' ||
form[oInteger[x][0]].type == 'select-one' ||
form[oInteger[x][0]].type == 'radio') &&
(form[oInteger[x][0]].value.length > 0)) {
var iValue = parseInt(form[oInteger[x][0]].value);
if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
if (i == 0) {
focusField = form[oInteger[x][0]];
}
fields[i++] = oInteger[x][1];
bValid = false;
}
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return bValid;
}
]]>
</javascript>
</validator>

when i give a wrong input although the control remains on the same page but a blank popup occurs.... but what exactly shud happen is the popup shud contain the message specified in the "key" of application.properties which is in this case "errors.empField.integer"

Please help....
15 years ago
Hi
I have to make a check for the Date in a certain format(dd/MM/yyyy) on the JSP form. I am using struts framework for validation.
The problem is although i have used the validation function "date" for the date field of the form bean but still on submitt the validator is not checking for right input i.e. in the format in which i want: dd/MM/yyyy

the code for "Validation.xml" is:
<form-validation>
<formset>
<form name="/AddUpdateEmployee">
// "AddUpdateEmployee" is the name of the action mapping in Struts-config.xml
...
...
<field
property="empJoinDate"
depends="required,date">
<arg0
key="errors.date" resource="true"/>
<var>
<var-name>datePattern</var-name>
<var-value>dd/MM/yyyy</var-value>
</var>

</field>

and the code for validator-rules.xml is:
<validator name="date"
classname="org.apache.struts.util.StrutsValidator"
method="validateDate"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="required"
msg="errors.date"
jsFunctionName="DateValidations">
<javascript>
<![CDATA[
function validateDate(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oDate = new employeeActionForm_DateValidations();
for (x in oDate) {
if (form[oDate[x][0]] != undefined) {
var value = form[oDate[x][0]].value;
var datePattern = oDate[x][2]("datePatternStrict");

if ((form[oDate[x][0]].type == 'text' ||
form[oDate[x][0]].type == 'textarea') &&
(value.length > 0) &&
(datePattern.length > 0)) {
var MONTH = "MM";
var DAY = "dd";
var YEAR = "yyyy";
var orderMonth = datePattern.indexOf(MONTH);
var orderDay = datePattern.indexOf(DAY);
var orderYear = datePattern.indexOf(YEAR);
if ((orderDay < orderYear && orderDay > orderMonth)) {
var iDelim1 = orderMonth + MONTH.length;
var iDelim2 = orderDay + DAY.length;
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
if (iDelim1 == orderDay && iDelim2 == orderYear) {
dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
} else if (iDelim1 == orderDay) {
dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
} else if (iDelim2 == orderYear) {
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
} else {
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
}
var matched = dateRegexp.exec(value);
if(matched != null) {
if (!isValidDate(matched[2], matched[1], matched[3])) {
if (i == 0) {
focusField = form[oDate[x][0]];
}
fields[i++] = oDate[x][1];
bValid = false;
}
} else {
if (i == 0) {
focusField = form[oDate[x][0]];
}
fields[i++] = oDate[x][1];
bValid = false;
}
} else if ((orderMonth < orderYear && orderMonth > orderDay)) {
var iDelim1 = orderDay + DAY.length;
var iDelim2 = orderMonth + MONTH.length;
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
if (iDelim1 == orderMonth && iDelim2 == orderYear) {
dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
} else if (iDelim1 == orderMonth) {
dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
} else if (iDelim2 == orderYear) {
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
} else {
dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
}
var matched = dateRegexp.exec(value);
if(matched != null) {
if (!isValidDate(matched[1], matched[2], matched[3])) {
if (i == 0) {
focusField = form[oDate[x][0]];
}
fields[i++] = oDate[x][1];
bValid = false;
}
} else {
if (i == 0) {
focusField = form[oDate[x][0]];
}
fields[i++] = oDate[x][1];
bValid = false;
}
} else if ((orderMonth > orderYear && orderMonth < orderDay)) {
var iDelim1 = orderYear + YEAR.length;
var iDelim2 = orderMonth + MONTH.length;
var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
if (iDelim1 == orderMonth && iDelim2 == orderDay) {
dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
} else if (iDelim1 == orderMonth) {
dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
} else if (iDelim2 == orderDay) {
dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
} else {
dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
}
var matched = dateRegexp.exec(value);
if(matched != null) {
if (!isValidDate(matched[3], matched[2], matched[1])) {
if (i == 0) {
focusField = form[oDate[x][0]];
}
fields[i++] = oDate[x][1];
bValid = false;
}
} else {
if (i == 0) {
focusField = form[oDate[x][0]];
}
fields[i++] = oDate[x][1];
bValid = false;
}
} else {
if (i == 0) {
focusField = form[oDate[x][0]];
}
fields[i++] = oDate[x][1];
bValid = false;
}
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return bValid;
}

function isValidDate(day, month, year) {
if (month < 1 || month > 12) {
return false;
}
if (day < 1 || day > 31) {
return false;
}
if ((month == 4 || month == 6 || month == 9 || month == 11) &&
(day == 31)) {
return false;
}
if (month == 2) {
var leap = (year % 4 == 0 &&
(year % 100 != 0 || year % 400 == 0));
if (day>29 || (day == 29 && !leap)) {
return false;
}
}
return true;
}
]]>
</javascript>
</validator>
15 years ago
Hi
I have to forward the control on the click of a html:button but i do not want to populate the ActionFormBean defined in the action-mapping.
One solution which i tried is to call a Java script on the click of button which will set the "action" value of form to "/ some other action-mapping "...
to be more precise i used the following code for the solution

html:form action="/Employee" focus="empName" method="POST"
input type="hidden" name="hiddenField"/
input type="hidden" name="counterValue"/
TABLE border="0" width="100%"
TR
TH align="right" Name: /TH
TD align="left" html:text property="empName"/ /TD
/TR
TR
TH align="right" Date Of Joining: /TH
TD align="left" html:text property="empJoinDate"/ (dd/MM/yyyy) (e.g. 21/03/1954) /TD
/TR
TR
TD align="right" html:button value="Submitt Button" property="SubmittButton" onKlick="onClickSubmit()"/ /TD

TD align="left" html:button value="Add" property="" onKlick="OnKlickAdd()"/
/TD /TR

on click of "add" button in calls the Java script

function OnKlickAdd()
{
document.forms[0].hiddenField.value = "add";
document.forms[0].action.value = "/AddAction";
document.forms[0].submit();
}

but the problem is that... on click of add button it doesnt go into /AddAction mapping but instead go into the /Employee mapping which is defined with html: form action="/Employee ....

i will give u guys the code which i placed in the Struts-config.xml
action
path="/AddAction"
type="org.apache.struts.actions.ForwardAction"
parameter="/EmployeeAddModify.jsp"
/action

action
path="/Employee"
type="com.employee.action.EmployeeAction"
name="employeeActionForm"
scope="request"
validate="false"
input="/EmployeeSearch.jsp"
forward
name="ADD"
path="/EmployeeAddModify.jsp"/
forward
name="success"
path="/EmployeeSearch.jsp"/
/action

I want that on click of "add" the /AddAction mapping should be used... but it is not happening...

Please help....
15 years ago

Originally posted by :


Hope this helps<hr></blockquote>[/QB]




hi i tried the above code to call the "action-mapping" which i have specified in the struts-config... but it is giving an error at the line(document.forms[0].submit() ... it is saying that "Object doesn't support this property or method" .... can somebody help me in knowing what does that mean...
the codes stucks at submitt and doesnt take it to the JSP which is mentioned in <action-mapping>
Please help!!!
15 years ago