comp.lang.java.programmer
http://groups-beta.google.com/group/comp.lang.java.programmer
[EMAIL PROTECTED]

Today's topics:

* How secure is Java? - 5 messages, 4 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/38d2eda5f6def0e3
* Attributes always empty when parsing XML documents - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f93920023b216158
* Environment variable - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e10a85f420f52962
* Stacktrace overflow - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/939c6348470bf4a4
* PreparedStatement can't handle "IN" in "WHERE" clause - 3 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2210b34eda18992b
* program arguments - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/44d9b350ac879ea0
* Java on Linux - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b359a0d20324fdbe
* log4j & crontab - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/986ef0214f885d87
* Character Encoding of a DOM object - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/989f73fe61ccf13b
* jvm wont start - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e7908b9ab87f83ff
* How do you cast to array? - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/884dee2def4bbb47
* What is package cache in a jar file - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dec0c6e21c7d3f0b
* ide sugestions for j2me dev - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/95ffdcc28f2b1a33
* How to create a excute file - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/453049a84ae975c2
* .exe Launched Java App -- How's It Working? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5fd9b8a5d2a9b437
* static vs. non-static method - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/67ffb5659c18541b
* Struts validator won't work - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fdad5b51303e2519
  
==========================================================================
TOPIC: How secure is Java?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/38d2eda5f6def0e3
==========================================================================

== 1 of 5 ==
Date:   Wed,   Nov 17 2004 2:29 am
From: [EMAIL PROTECTED] (hiwa) 

Do you happen know, what would happen if we, with root privilege,  run
an rm -fr / or equivalent by using Runtime#exec() or java.io.File
methods?



== 2 of 5 ==
Date:   Wed,   Nov 17 2004 2:34 am
From: Michael Borgwardt <[EMAIL PROTECTED]> 

hiwa wrote:
> Do you happen know, what would happen if we, with root privilege,  run
> an rm -fr / or equivalent by using Runtime#exec() or java.io.File
> methods?

Same as would happen in any other language - bye bye, files.

I fail to see what this has to do with security, though. Security lies in
preventing unauthorized people from *gaining* root privileges, not in
preventing people with root privileges from doing harmful things.



== 3 of 5 ==
Date:   Wed,   Nov 17 2004 2:48 am
From: "Brusque" <[EMAIL PROTECTED]> 


"Michael Borgwardt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> hiwa wrote:
> > Do you happen know, what would happen if we, with root privilege,  run
> > an rm -fr / or equivalent by using Runtime#exec() or java.io.File
> > methods?
>
> Same as would happen in any other language - bye bye, files.

Unless it's an applet, or the security policy doesn't allow calls to
Runtime#exec()





== 4 of 5 ==
Date:   Wed,   Nov 17 2004 3:43 am
From: Andrew Thompson <[EMAIL PROTECTED]> 

On Wed, 17 Nov 2004 20:48:55 +1000, Brusque wrote:

> "Michael Borgwardt" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> hiwa wrote:
>>> Do you happen know, what would happen if we, with root privilege,  run
>>> an rm -fr / or equivalent by using Runtime#exec() or java.io.File
>>> methods?
>>
>> Same as would happen in any other language - bye bye, files.
> 
> Unless it's an applet, or the security policy doesn't allow calls to
> Runtime#exec()

..or no Java is installed, or no files are on the drive, or the
drive is read only (EG CD), or somebody unplugs the drive, or the 
power fails (etcetera) 

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



== 5 of 5 ==
Date:   Wed,   Nov 17 2004 4:03 am
From: "Brusque" <[EMAIL PROTECTED]> 


"Andrew Thompson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Wed, 17 Nov 2004 20:48:55 +1000, Brusque wrote:
>
> > "Michael Borgwardt" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >> hiwa wrote:
> >>> Do you happen know, what would happen if we, with root privilege,  run
> >>> an rm -fr / or equivalent by using Runtime#exec() or java.io.File
> >>> methods?
> >>
> >> Same as would happen in any other language - bye bye, files.
> >
> > Unless it's an applet, or the security policy doesn't allow calls to
> > Runtime#exec()
>
> ..or no Java is installed, or no files are on the drive, or the
> drive is read only (EG CD), or somebody unplugs the drive, or the
> power fails (etcetera)

Indeed.






Were you taking the piss? :-P






==========================================================================
TOPIC: Attributes always empty when parsing XML documents
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f93920023b216158
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 2:41 am
From: TechBookReport <[EMAIL PROTECTED]> 

Andy Carson wrote:
> Thanks for the code sample!
> 
> Are there more effective parsers? The code sample you provided suggests that
> the reading of the values is a bit messy ...
> 
> (I'm very found of the way you handle XML in the .Net-environment. In
> C#/.Net you just define a schema (sort of a data set) and then the parser
> just load that schema with the correct values automatically. )
> 
> 
Personally I much prefer JDOM (http://www.jdom.org). It's cleaner and 
much more intuitive IMHO.

Pan
================================================
TechBookReport http://www.techbookreport.com




==========================================================================
TOPIC: Environment variable
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e10a85f420f52962
==========================================================================

== 1 of 2 ==
Date:   Wed,   Nov 17 2004 2:44 am
From: "Stefan Poehn" <[EMAIL PROTECTED]> 

"Thomas Weidenfeller" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
>
> System.getenv()
>
> Was AFAIR deprecated in some Java versions, but has been "un-deprecated" 
> for some time.
>

Thanks. It works. Is there a replacement for this method that is not 
deprecated, or is it "forbidden" to use environment vars in java?

> /Thomas 





== 2 of 2 ==
Date:   Wed,   Nov 17 2004 2:57 am
From: Michael Borgwardt <[EMAIL PROTECTED]> 

Stefan Poehn wrote:
>>System.getenv()
>>
>>Was AFAIR deprecated in some Java versions, but has been "un-deprecated" 
>>for some time.
>>
> 
> 
> Thanks. It works. Is there a replacement for this method that is not 
> deprecated,

No.

> or is it "forbidden" to use environment vars in java?

It is stringly discouraged, since it's not portable. Some systems don't
have environment variables at all (such as pre-X MacOS), and they don't
behave the same on all systems that do.




==========================================================================
TOPIC: Stacktrace overflow
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/939c6348470bf4a4
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 2:58 am
From: [EMAIL PROTECTED] (Oliver Brausch) 

Hello, 
I get a stacktrace overflow for an exception. So the exception
is cut and I do not find where it is thrown.
Is there a possibiliy to enlarge the size of the stack or
another workaround to see the complete exception?

-Oliver


java.lang.Exception: STACKTRACE
        at 
org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:319)
        at 
org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:477)
....




==========================================================================
TOPIC: PreparedStatement can't handle "IN" in "WHERE" clause
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2210b34eda18992b
==========================================================================

== 1 of 3 ==
Date:   Wed,   Nov 17 2004 4:11 am
From: [EMAIL PROTECTED] (salaryman) 

I have a simple SQL statement:

 SELECT DISTINCT id FROM TheTable WHERE id in ('1', '2', '3', '4');

If I run this in my SQL query window it correctly returns the set [1,
2, 3, 4].

If I execute the SQL directly using Statement.executeQuery, I get the
correct results.  However, if I try and substitute the IN clause using
a PreparedStatement:

  PreparedStatement statement = connection.prepareStatement("SELECT
DISTINCT id from TheTable WHERE id IN (?)");
  statement.setString(1, "'1', '2', '3', '4'");

The result set is empty.   I also tried:

  statement.setString(1, "1, 2, 3, 4");

And this returns the set [1].

I am using MySQL and if I step into the code for
PreparedStatement.setString(), I can see that single quotes are added
to the front and end of the string, which explains why I am seeing the
behaviour.  But it doesn't seem right!

Please can someone tell me whether or not this is expected behaviour,
or is MySQL doing something strange.  As far as I can tell, there is
no solution for this problem, other than using a different query.

Cheers.



== 2 of 3 ==
Date:   Wed,   Nov 17 2004 4:09 am
From: "salaryman" <[EMAIL PROTECTED]> 

I have a simple SQL statement:

SELECT DISTINCT id FROM TheTable WHERE id in ('1', '2', '3', '4');

If I run this in my SQL query window it correctly returns the set [1,
2, 3, 4].

If I execute the SQL directly using Statement.executeQuery, I get the
correct results.  However, if I try and substitute the IN clause using
a PreparedStatement:

PreparedStatement statement = connection.prepareStatement("SELECT
DISTINCT id from TheTable WHERE id IN (?)");
statement.setString(1, "'1', '2', '3', '4'");

The result set is empty.   I also tried:

statement.setString(1, "1, 2, 3, 4");

And this returns the set [1].

I am using MySQL and if I step into the code for
PreparedStatement.setString(), I can see that single quotes are added
to the front and end of the string, which explains why I am seeing the
behaviour.  But it doesn't seem right!

Please can someone tell me whether or not this is expected behaviour,
or is MySQL doing something strange.  As far as I can tell, there is no
solution for this problem, other than using a different query.

Cheers.




== 3 of 3 ==
Date:   Wed,   Nov 17 2004 4:18 am
From: Michael Borgwardt <[EMAIL PROTECTED]> 

salaryman wrote:
>   PreparedStatement statement = connection.prepareStatement("SELECT
> DISTINCT id from TheTable WHERE id IN (?)");
>   statement.setString(1, "'1', '2', '3', '4'");
> 
> The result set is empty.   I also tried:
> 
>   statement.setString(1, "1, 2, 3, 4");
> 
> And this returns the set [1].
> 
> I am using MySQL and if I step into the code for
> PreparedStatement.setString(), I can see that single quotes are added
> to the front and end of the string, which explains why I am seeing the
> behaviour.  But it doesn't seem right!

It *is* right, though. You have declared your PreparedStatement to have *one*
parameter, so whatever you add will be inserted as one parameter. The whole
point of PreparedStatement is that parameters are NOT interpreted as part of
the SQL string. That's what makes precompilation possible and SQL insertion
attacks impossible.




==========================================================================
TOPIC: program arguments
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/44d9b350ac879ea0
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 4:11 am
From: Jeff Kish <[EMAIL PROTECTED]> 

On Tue, 16 Nov 2004 19:21:34 -0500, Jeff Kish <[EMAIL PROTECTED]> wrote:

>On Tue, 16 Nov 2004 18:26:38 +0100, Thomas Weidenfeller <[EMAIL PROTECTED]> 
>wrote:
>
>>Jeff Kish wrote:
>>> mmm I have a feeling you are a unix sort of user, so you have a more mature 
>>> OS/environment that I
>>> do.
>>
>>I use Solaris. I bet my newsgroup headers give it away.
>>
>>> Now I need to figure out a way to expand programmatically the 
>>> file-spec-wildcard passed in as a
>>> parameter.
>>
>>Google for "file globbing" or "wildcard" source code (almost any 
>>programming language should do, the code should be easily portable to Java).
>>
>>/Thomas
>I can't believe it. I think I've actually found it... It seems this may be a 
>part of Java, and you
>do turn it off with quotes.
>Here is what I found from a report at:
>http://www.mail-archive.com/[email protected]/msg00009.html
>
<snip>
mm. I guess that is not really a "report", just some other user experiencing 
the same symptoms.
But it sounds like it is really java doing this? I mean, if Unix always expands 
non quoted files
globbing, then for java to "work" the same everywhere, I guess it would, on a 
Windows platform, have
to expand the file wildcard so that the args would "look" the same to all 
applications.

Sound logical?
Thanks




==========================================================================
TOPIC: Java on Linux
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b359a0d20324fdbe
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 4:51 am
From: Morten Alver <[EMAIL PROTECTED]> 


> 2. I don't know what the relationship between Blackdown and the Sun
> Java is.  I want to avoid conflicts in example programs.

I've used the Sun, Blackdown and IBM Java distributions on linux, and 
not had any compatibility problems between them.

I believe as good as all Linux distributions provide an easy way to 
install Java through their standard package management systems. You'd 
have to say which distribution you are using to get more specific info 
on this.


--
Morten




==========================================================================
TOPIC: log4j & crontab
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/986ef0214f885d87
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 5:03 am
From: "Vuk" <[EMAIL PROTECTED]> 

when i implement crontab in my application his log4jjcrontab.properties
overrides my log4j.properties






==========================================================================
TOPIC: Character Encoding of a DOM object
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/989f73fe61ccf13b
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 5:34 am
From: Martin Honnen <[EMAIL PROTECTED]> 



Rakesh Pandit wrote:


>     How can one find out the character encoding of
> a DOM Document after an XML file has been
> converted to the DOM object.

Well the DOM document itself doesn't have any character encoding, it 
just operates on Java strings (which are Unicode strings). As for the 
encoding of the input XML with DOM Level 3 Core as implemented in JDK 
1.5 there is a property
  http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-inputEncoding
With DOM Level 2 Core as implemented in JDK 1.4 there is no property 
telling you the encoding.

-- 

        Martin Honnen
        http://JavaScript.FAQTs.com/




==========================================================================
TOPIC: jvm wont start
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e7908b9ab87f83ff
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 5:35 am
From: jmt <[EMAIL PROTECTED]> 

Hi guys
We had a power failure yesterday and that seem to have stuffed up my 
vm.Typing "java"   from the command prompt , I get the following error 
message :

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

Jeff

Registered Linux user number 366042




==========================================================================
TOPIC: How do you cast to array?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/884dee2def4bbb47
==========================================================================

== 1 of 2 ==
Date:   Wed,   Nov 17 2004 5:21 am
From: NOBODY <[EMAIL PROTECTED]> 

Boiled down, you finally make sense.
Thanks for the exhaustive explaination.

But whatever words I use, if avoiding 'new' give me a magnitude of 
throughput increase, I won't forget the trick soon.


> ([*] after all, if there are programmers who don't see anything wrong
> with storing several million java.lang.Floats in an ArrayList.....)

Can you imagine the upcoming nightmare with 1.5 autoboxing?!
This is the worst feature of 1.5. It is a serious mistake from a language 
perspective. There is a limit to laziness in order to be a good programmer.

Juniors are gonna start using autoboxing like they know nothing better. 
Same for the new 'for' loop, trashing iterators.

Damn it, we will have to develop another language again...
;)




== 2 of 2 ==
Date:   Wed,   Nov 17 2004 5:54 am
From: Michael Borgwardt <[EMAIL PROTECTED]> 

NOBODY wrote:
> But whatever words I use, if avoiding 'new' give me a magnitude of 
> throughput increase, I won't forget the trick soon.

It may have given you that increase in *one particular program*.
It's still a really bad idea to start prematurely optimizing it
everywhere.

There are certainly a lot of operations that are quicker than a 'new',
but far, far more that are orders of magnitude slower. It's just not
very likely that 'new' really turns out to be what slows down a program.

That's what profilers are for.

> Can you imagine the upcoming nightmare with 1.5 autoboxing?!
> This is the worst feature of 1.5. It is a serious mistake from a language 
> perspective.

I don't think so at all.

> There is a limit to laziness in order to be a good programmer.
> Juniors are gonna start using autoboxing like they know nothing better. 

And most of the time it will be not problem at all, see above.


> Same for the new 'for' loop, trashing iterators.

I really, *really* don't see how this could *ever* turn into a problem.
What circumstances do you imagine where the for(type object:iterable)
loop would now be used where what would have been used before
(*is* there anything beside while(iterator.hasNext())??) was in any
way faster?




==========================================================================
TOPIC: What is package cache in a jar file
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dec0c6e21c7d3f0b
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 5:39 am
From: [EMAIL PROTECTED] (Gerbrand van Dieijen) 

On Wed, 17 Nov 2004 20:46:39 +1300, HS1 wrote:
>Hello all
>I know that a jar file is considered as zip file. I see a Jar file that has
>a package cache. Could you please tell me the purpose of this "package" or
>locate a tutorial about content of a jar file...

JBuilder (Maker/compiler) creates a folder 'package cache' when building 
source files, I think it originates from there.
I don't know if other make utilities do that, but it's probably from 
JBuilder.

-- 
Gerbrand van Dieijen





==========================================================================
TOPIC: ide sugestions for j2me dev
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/95ffdcc28f2b1a33
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 5:41 am
From: [EMAIL PROTECTED] (Gerbrand van Dieijen) 

On 16 Nov 2004 21:21:14 -0800, Mike Crabs wrote:
>can anyone recommend an ide that does not require some kind of super
>computer to be able to use it.

Are you frustated because your mum wouldn't buy you a new computer?

-- 
Gerbrand van Dieijen





==========================================================================
TOPIC: How to create a excute file
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/453049a84ae975c2
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 5:44 am
From: [EMAIL PROTECTED] (Gerbrand van Dieijen) 

On Mon, 15 Nov 2004 17:53:44 +1300, HS1 wrote:
>Hello all
>
>
>
>I want to create an execute file (only one .exe file for Windows) for my
>project. This project uses some available component such as JFree for
>creating report or mysql-connector to connect to a mySQL database)... . So
>when I want to create the file, do I have to add all of those libraries into
>this file?
>

I use Exe4j for that, which works very fine. You still need an JVM, but 
you can simple include the folder JRE as subfolder in your applications 
directory (which can be packed/installed with it).

-- 
Gerbrand van Dieijen





==========================================================================
TOPIC: .exe Launched Java App -- How's It Working?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5fd9b8a5d2a9b437
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 5:46 am
From: [EMAIL PROTECTED] (Gerbrand van Dieijen) 

On Sat, 13 Nov 2004 07:00:34 GMT, cppaddict wrote:
>I have program (made with exe4j) that uses an .exe file to launch a

>I would like to know exactly which command the .exe file is issuing to
>start the application.  That is, what the command line args or other
>options are.

You should ask the creator of exe4j, but I think it doesn't use the 
command line but calls the JVM.dll directly. 

-- 
Gerbrand van Dieijen





==========================================================================
TOPIC: static vs. non-static method
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/67ffb5659c18541b
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 6:23 am
From: "dingo" <[EMAIL PROTECTED]> 

static works for the class.
non static works for the instances of that class.


"Ryan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> What is the difference?
>
>






==========================================================================
TOPIC: Struts validator won't work
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fdad5b51303e2519
==========================================================================

== 1 of 1 ==
Date:   Wed,   Nov 17 2004 7:01 am
From: [EMAIL PROTECTED] (Edwinek) 

Hi,

I've made a validator for comparing one form field with another and
return true for equality. However, when I test the code, I get this
stack trace:

[17/11/04 14:43:31:203 CET] 5f57da12 ValidatorForm E
org.apache.struts.validator.ValidatorForm  TRAS0014I: The following
exception was logged org.apache.commons.validator.ValidatorException:
validateEqualToField
 at org.apache.commons.validator.Field.validateForRule(Field.java:811)
 at org.apache.commons.validator.Field.validate(Field.java:901)
 at org.apache.commons.validator.Form.validate(Form.java:178)
 at org.apache.commons.validator.Validator.validate(Validator.java:373)
 at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:117)
      ... etc ... 

The actual validator method is never reached (I put a breakpoint there
to make sure). Any ideas? This is the code:

<form name="formbeaninterhelpupdatemembersecurity">
  <field property="pinCode" depends="regexp, comparewithotherfield">
    <msg name="regexp"
key="interhelp.error.field.number.length.fixed"/>
    <arg0 name="regexp" key="interhelp.updatemembersecurity.pincode"/>
    <arg1 name="regexp" key="${var:maxlength}" resource="false"/>
    <msg name="comparewithotherfield"
key="interhelp.error.field.compare"/>
    <arg0 name="comparewithotherfield"
          key="interhelp.updatemembersecurity.pincode"/>
    <var>
      <var-name>regexp</var-name>
      <var-value>[0-9][0-9][0-9]</var-value>
    </var>
    <var>
      <var-name>maxlength</var-name>
      <var-value>3</var-value>
    </var>
    <var>
      <var-name>comparewithotherfield</var-name>
      <var-value>pinCodeCheck</var-value>
    </var>
  </field>
  <field property="answer" depends="required, maxlength">
    <msg name="required" key="interhelp.error.field.required"/>
    <arg0 name="required"
key="interhelp.updatemembersecurity.answer"/>
    <msg name="maxlength" key="interhelp.error.field.length"/>
    <arg0 name="maxlength"
key="interhelp.updatemembersecurity.answer"/>
    <arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
    <var>
      <var-name>maxlength</var-name>
      <var-value>16</var-value>
    </var>
  </field>
  <field property="question" depends="required, maxlength">
    <msg name="required" key="interhelp.error.field.required"/>
    <arg0 name="required"
key="interhelp.updatemembersecurity.question"/>
    <msg name="maxlength" key="interhelp.error.field.length"/>
    <arg0 name="maxlength"
key="interhelp.updatemembersecurity.question"/>
    <arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
    <var>
      <var-name>maxlength</var-name>
      <var-value>40</var-value>
    </var>
  </field>
</form>         

<validator name="comparewithotherfield"
      classname="nl.xxxx.pd.appl.form.validator.FormFieldValidator"
         method="validateEqualToField"
   methodParams="java.lang.Object,
                 org.apache.commons.validator.ValidatorAction,
                 org.apache.commons.validator.Field,
                 org.apache.struts.action.ActionMessages,
                 javax.servlet.http.HttpServletRequest"
                        msg="interhelp.error.field.compare"/>

public static boolean validateEqualToField(
      Object bean,
      ValidatorAction va,
      Field field,
      ActionErrors errors,
      HttpServletRequest request) {

  String value = ValidatorUtil.getValueAsString(bean,
field.getProperty());
  String sProperty2 = field.getVarValue("comparewithotherfield");
  String value2 = ValidatorUtil.getValueAsString(bean, sProperty2);

  if (!GenericValidator.isBlankOrNull(value)) {
    try {
      if (!value.equals(value2)) {
        errors.add(
           field.getKey(),
           Resources.getActionMessage(request, va, field));

        return false;
      }
    } catch (Exception e) {
      errors.add(
         field.getKey(),
         Resources.getActionMessage(request, va, field));
      return false;
    }
  }

  return true;
}

By the way, the ServletContext parameter (as seen in the example on
http://struts.apache.org/userGuide/dev_validator.html) isn't present
on any of the validators (the ones that do work) in our application.
Adding it anyway (I tried) doesn't make any difference.

Thanks,
Edwin



=======================================================================

You received this message because you are subscribed to the
Google Groups "comp.lang.java.programmer".  

comp.lang.java.programmer
[EMAIL PROTECTED]

Change your subscription type & other preferences:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

Report abuse:
* send email explaining the problem to [EMAIL PROTECTED]

Unsubscribe:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe


=======================================================================
Google Groups: http://groups-beta.google.com 

Reply via email to