Win a copy of Spark in Action this week in the Open Source Projects forum!

Michele Giunti

Greenhorn
+ Follow
since Jun 02, 2008
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 Michele Giunti

Originally posted by Tom Rispoli:
I ran into something similar to this once a long time back. The problem was that java.beans.Introspector.getBeanInfo() was being called on my form it was determining that my private ArrayList was a propert (not an indexed property). If I remember correctly my solution was to make sure that I had an indexed version of both getter and setter methods. I think I may have also had to play with the order that the methods appeared in my form class.

I was using java 1.4.2 at the time and when I used a debugger on the Introspector class it appeared to me that it was finding a non-indexed getter or setter and from that assuming that the property itself wasn't indexed. I can't be sure that this is your problem but its something you might want to try. I know I wasted a huge amount of time figuring it out.



Thanks for your reply.
Unfortunately, this is not my problem.
11 years ago

Originally posted by Merrill Higginson:
Frankly, I don't see anything wrong with your code. It should work! Just a couple of questions:

Is the result of the System.out.println statements a null pointer exception, or is the value simply null?

Use your browser's "view source" option on this page. The hidden fields should look like this. do they?



Dear Merrill, first of all tahnks for your reply.


About your questions.
1) I modified my Action to check the values returned from jsp. I don't get a NullPointer Exception. I just get null values. For examples, I print the first (index=0) LabelValueBean of the list but I get the following output:
lvb[0].label=null
lvb[0].value=null



2) Yes, I get what you expect.


So, I can't understand where is the problem.
11 years ago
Hi to all.
I'm using Struts 1.3, Tomcat 6.0 and Eclipse.

I have a problem with Indexed Properties.
I have a jsp that should save hidden values and pass it to the linked Action.

I show you my code.

********
JSP PAGE
********

where
- 'listaSport' is a list containing a list of sports. This list is correctly populated by the previous Action through 'select' and 'optionsCollection' tags.
- 'hSportBean' is a LabelValueBean list where I have to save the select options.

***********
ACTION FORM
***********


******
ACTION
******


The problem is that I can't load in Action the hidden values saved in the jsp page.
I tried to print the values received

but I always obtain null values (for all indexes).

So, I don't know how to solve my problem.

I also followed guidelines in:
http://faq.javaranch.com/java/IndexedProperties
http://struts.apache.org/1.x/struts-taglib/indexedprops.html
http://mail-archives.apache.org/mod_mbox/struts-user/200604.mbox/%3C5B7D2ACE8204B748980CEB2DBFAB90B3972E53@mail.delta-informatique.net%3E
but with no success.

Can you help me?

Thanks a lot in advance.
11 years ago
I'm using Eclipse.
I had already tried to debug but with no result.
I think the problem is in my ActionForm class but I can't find a solution.

The genereted html is the following:


I think there is a type mismatch between my ActionForm definition ('sport' is a String) and the generated html ('sport' is a org.apache.struts.util.LabelValueBean[]) but I can't understand how to solve the problem.
11 years ago
Hi to all.
I have a problem with a logic:iterate tag. I'm using Struts 1.3.
I have to populate a select with data read from db (by invoking the first Action). When a select option is selected in the jsp, I have to invoke a second Action (on the same jsp page) which has to perform some operations and remember the previous selected option (in the select).
I show you my source code for semplicity.

Here is my ActionForm.
*******************************
CreazioneProfiloUtenteForm.java
*******************************



First, the ToCreazioneProfiloUtenteAction action is invoked. This action reads data from db and insert them in the ArrayList 'listaSport'; at the end, this ArrayList is setted in the request.
***********************************
ToCreazioneProfiloUtenteAction.java
***********************************


Then creazioneProfiloUtente.jsp is invoked. I have a select 'sport' that reads the collections in the ArrayList 'listaSport'. Then, I have to store in hidden fields the values of the 'listaSport' arraylist in order to avoid, in the second Action, to re-access to db to read the same values. In order to do so, I use logic:iterate but I have problems with it. I confirm that if I delete from source code the tag logic:iterate, all works well.
**************************
creazioneProfiloUtente.jsp
**************************


This is the second Action, which should be invoked when a select option is selected by user. Unfortunately, this Action is never accessed because I got a java NullPointerException before.
*****************************************
CaricamentoRuoliAttributiSportAction.java
*****************************************


*********
EXCEPTION
*********


*****************
STRUTS-CONFIG.XML
*****************


I can't understand where is the problem.
Can you help me?

Thanks to all in advance.

Bye bye.
11 years ago
No-reply?

However, I solved. Now all works well.

**********
SERVER-SIDE
**********
To avoid the deprecated method

I used

in my custom validator java class.
I added "org.apache.commons.validator.Validator" to methodParams of the "twofields" custom validator in validator-rules.xml.

**********
CLIENT-SIDE
**********
I changed

with




That's all.
12 years ago
Now, server-side validation works!I changed ActionErrors class with ActionMessages class into my java validation method and into "validator-rules.xml".
The only problem is that
Resources.getActionMessage(request, va, field)method in my custom validator class is deprecated and I don't know how to replace it.
Can you give me any suggestions?


On the client-side, I have the same problem.I see a javascript warning in browser: "twofields is not defined".
I have also tried to perform some changes to my files:
**************
validator-rules.xml
**************

**********
validation.xml
**********


So, my custom validation ("twofields") doesn't still work on client-side.
Can you help me?
I also tried to change the version of dtd validator...but nothing changed.
I can't understand where is the problem.
12 years ago
I'm using Struts 1.3.
I'm trying to write a custom validator to check that 2 fields are identical.

1) I modified my validator-rules.xml by adding my own validator (called "uguale"):
**************
validator-rules.xml
**************
[CODE<validator name="uguale"
classname="it.sfidiamoci.validator.ValidatorPersonalizzati"
method="validateUguale"
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.uguale">

<javascript><![CDATA[
function validateUguale(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oTwoFields = new twofields();
for (x in oTwoFields) {
var field = form[oTwoFields[x][0]];
var secondField = form[oTwoFields[x][2]("secondProperty")];

if (field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'select-one' ||
field.type == 'radio' ||
field.type == 'password') {

var value;
var secondValue;
// get field's value
if (field.type == "select-one") {
var si = field.selectedIndex;
value = field.options[si].value;
secondValue = secondField.options[si].value;
} else {
value = field.value;
secondValue = secondField.value;
}

if (value != secondValue) {

if (i == 0) {
focusField = field;
}
fields[i++] = oTwoFields[x][1];
bValid = false;
}
}
}

if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}

return bValid;
}]]></javascript>

</validator>[/CODE]

2) I modified my validation.xml by adding the new validator (called "uguale"):
**************
validator-rules.xml
**************
[CODE<field property="password" depends="required,minlength,mask,uguale">
<arg position="0" key="errors.password" />
<arg position="1" name="minlength" key="${var:minlength}" resource="false" />
<msg name="mask" key="errors.mask.password" />
<msg name="uguale" key="errors.password.uguale" />
<var>
<var-name>minlength</var-name>
<var-value>8</var-value>
</var>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z0-9_.]*$</var-value>
</var>
<var>
<var-name>secondProperty</var-name>
<var-value>password2</var-value>
</var>
</field>[/CODE]

3) I added the key "errors.password.uguale" in ApplicationResources.properties
***********************
ApplicationResources.properties
***********************


4) I created the class "ValidatorPersonalizzati" to handle the custom validator "validateUguale":
********************
ValidatorPersonalizzati.java
********************


5) I have two fields ("password", "password2") to check in my jsp:
******
test.jsp
******
[CODE<tr>
<td class="col1"><bean:message key='registrazioneUtente.password.label'/></td>
<td><html :-P assword property="password" styleId="password" maxlength="<%= passwordMaxLength %>" /></td>
<td><bean:message key='registrazioneUtente.password2.label'/></td>
<td><html :-P assword property="password2" styleId="password2" maxlength="<%= passwordMaxLength %>" /></td>
</tr>[/CODE]


When I submit the form in my jsp, standard validations (e.g. required, minlength, ...) of other fields are performed in the correct way.
Instead, my own validation called "uguale" ("password==password2") doesn't work!
On the client-side, I see a javascript warning in browser: "twofields is not defined" but no javascript alert.
On the server-side, I get the following exception:



In the log I have left 2 System.out.println to be sure that "value" and "value2" variables had the correct value submitted through the form.

Moreover, I'm not sure that
<i>Resources.getActionMessage(request, va, field)</i>
method in my custom validator class is correct. This method is deprecated and I don't know how to replace it.

I can't understand where is the problem.

Can you help me?

Thanks in advance.
12 years ago
I tried your suggestion with:

but the result is the same. The form is submitted but I can't see any javascript alerts.

I can't understand where is the problem.

Suggestions?
12 years ago
Hi, I'm using Struts Validator Framework (Struts 1.3).
Server-side validation works well.
The problem is in client-side validation.

The form name I have to validate is: RegistrazioneUtenteForm.

In my jsp page I have 2 buttons:
1)
2)
and the following form declaration:

Moreover I have enabled javascript validation:


The javascript function submitRegistrazioneUtenteForm is the following:


If I click on the second button (html:submit), all works well (I get javascript alerts).
If I click on the first button (html:link), the form is submitted but I can't see any javascript alerts.

I can't understand where is the problem.

Can you help me?

Thanks in advance.

PS: I have underscored the javascript e_v_a_l function only to be allowed to post in this forum. In my code, it's not underscored.
12 years ago
Hi, i'm using jcaptcha with Struts 1.3.
I already configured my web application following the suggestions present at the JCAPTCHA homepage and all works.

Now, I'd like to customize the captcha: I'd like to use another engine than the default one and try to change other options (size, colour, ...).

I tried to follow the suggestion present at the JCAPTCHA homepage:



but I got some errors/warnings:
- The type MyOwnManageableImageCaptchaService must implement the inherited abstract method ManageableCaptchaService.setCaptchaEngine(CaptchaEngine)
- The type EhcacheManageableImageCaptchaService is deprecated
- The constructor EhcacheManageableImageCaptchaService(CaptchaEngine, int, int) is deprecated

How can I solve this problem?

Can you help me?

Thanks a lot in advance.
12 years ago