participate


JavaServer Faces - Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null
This question is answered. Correct Answer available

<<   Back to Forum  |   Give us Feedback
4 Duke Stars available
This topic has 13 replies on 1 page.
Javaaaaaa
Posts:132
Registered: 9/11/03
Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 8, 2009 6:47 AM
 
 
Hi,

First, I tried to search for this but, I can't figure out how to limit the search to this forum only. Would you know how?


Here's my question:

We are migrating from JSF 1.1 to 1.2. The InputText tag use to return Null for an empty Integer value but returns a zero in JSF 1.2.
In our code we always check only for Null. Is there a work around that would not involve changing all or validation?

Thanks

Edited by: Javaaaaaa on Jan 8, 2009 2:47 PM
 
styx2000
Posts:11
Registered: 1/8/09
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 8, 2009 6:56 AM (reply 1 of 13)  (In reply to original post )
 
 
Hi

i have a similar problem. I am using JSF 1.2_08

I created a <h:selectOneMenu> with several selectItems. The IDs are the database IDs which can be 0.
If nothing is selected i need a null-value returned but for some reason i get a 0.

I tried to create a custom converter where i convert the empty string (this is the html-value of the empty option) to "null" but somewhere after that it gets converted to zero. I also tried to use "-" instead of the empty string, same result.

Can anyone point me to a workaround solution? Is this a bug or intended behaviour?

thanks
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 8, 2009 8:15 AM (reply 2 of 13)  (In reply to original post )
Correct
 
Since JSF 1.2, the unified EL implementation as provided by the application server will be used to evaluate EL expressions. So this issue is in fact also application server dependent. For instance all Tomcat versions up to 6.0.14 would work as expected, but since some bugfix which was released since Tomcat 6.0.16 this unwanted side effect occurred.

Also see this bug/feature report and the links in it: https://jsp-spec-public.dev.java.net/issues/show_bug.cgi?id=183.

In case of Tomcat, you can fix it using the following VM argument:
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
 
Javaaaaaa
Posts:132
Registered: 9/11/03
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 8, 2009 8:57 AM (reply 3 of 13)  (In reply to #2 )
 
 
What would we do without you BalusC ;)

Thanks
 
styx2000
Posts:11
Registered: 1/8/09
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 8, 2009 9:27 AM (reply 4 of 13)  (In reply to #2 )
 
 
thanks a lot, this solved my problem!

btw: i had the problem with tomcat 6.0.16 where the VM argument
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
has no effect.
i upgraded to 6.0.18, it works in this version (since 6.0.17 i believe).

i do run into other problems though, for example the following expression language term does not work anymore:
<rich:toolTip rendered="#{!empty(texts['test2'])}" value="#{texts['test2']}"/>

this is used to show tooltips only when they are not null. i will look into this some more tomorrow.

thanks again
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 8, 2009 9:43 AM (reply 5 of 13)  (In reply to #4 )
 
 
styx2000 wrote:
btw: i had the problem with tomcat 6.0.16 where the VM argument
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
has no effect.
i upgraded to 6.0.18, it works in this version (since 6.0.17 i believe).
That setting was available as per 6.0.17 indeed. Also see http://tomcat.apache.org/tomcat-6.0-doc/changelog.html.
 
styx2000
Posts:11
Registered: 1/8/09
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 1:32 AM (reply 6 of 13)  (In reply to #4 )
 
 
in case somebody has the same problem:

this code doesnt work anymore after update
<rich:toolTip rendered="#{!empty(texts['test2'])}" value="#{texts['test2']}"/>

the exception was:
javax.el.ELException: Function ':empty' not found

after removing the parentheses it works:
<rich:toolTip rendered="#{!empty texts['test2'] }" value="#{texts['test2']}"/>



does anybody know why this is? everytime i make an upgrade of some part of the framework i run into problems like that, they cost me a lot of time.
i looked at the EL specification, there are no parentheses in the example there, but parentheses should be at least allowed in this spot shouldnt they?
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 3:58 AM (reply 7 of 13)  (In reply to #6 )
 
 
I´ve never used parentheses for this kind of constructions. If the EL spec also doesn´t state anything about it, I wouldn´t mark it as a bug. You may want to report it at the Tomcat mailinglist/issuetracker to see what they have to say about it.
 
styx2000
Posts:11
Registered: 1/8/09
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 4:06 AM (reply 8 of 13)  (In reply to #7 )
 
 
i didnt think it was, it is just annoying to me that i have to change my code so often.
im sure it's my own fault in a way because i write code that isn't 100% correct (because i dont know better), but i would appreciate it if code that works keeps working after an update.

this happened to me twice already while im working on the current project and we had to do the upgrades because we wanted to use some new features.

this project is kind of a prototype in our department, as we havent used this technology yet. if we have a lot of troubles we will go back to previous technologies and im wondering if i was just especially unlucky or if this is an issue that will arise a lot. i like the java platform a lot, but so far we are a lot slower than before (we use oracle forms a lot, which is hard to compare to a j2ee web application, but still).
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 4:23 AM (reply 9 of 13)  (In reply to #8 )
 
 
This may sound harsh, but it is the truth: it wouldn't have occurred if you wrote correct code.
 
styx2000
Posts:11
Registered: 1/8/09
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 4:30 AM (reply 10 of 13)  (In reply to #9 )
 
 
i understand, i just wish that i get an error when i write incorrect code. then this wouldnt have happened either (assuming this really is wrong syntax, just because there are no parentheses in the example in the spec doesnt mean theyre illegal).
 
Javaaaaaa
Posts:132
Registered: 9/11/03
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 10:58 AM (reply 11 of 13)  (In reply to #2 )
 
 
BalusC, do you know of any settings (Tomcat or JVM) that could affect a For Loop behavior?


I have code that contains an outer and inner loop. The exact same code (cut & paste) works fine under Tomcat 5.5.15/JSF 1.1 and Java 1.5.0.11 but,
not under Tomcat 6.0.18/JSF 1.2 and Java 1.6.0_01.

When the inner loop Breaks, the outer loop value doesn't increase. I've turned this upside down, I'm 99% sure I'm not missing anything. I even re-copied the code from one environment to the other. Still have the problem. Any ideas what I could do next?

for (int i = 0; i < dataRowListSize; i++) {
          for (int j = 0; j < supportList.size(); j++) {
          ...
          break;
          }
      } // end of the top loop


Thanks
 
Javaaaaaa
Posts:132
Registered: 9/11/03
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 11:41 AM (reply 12 of 13)  (In reply to #11 )
 
 
I just downloaded and installed JRE 1.6 update 11 and it made no difference. :(
 
BalusC
Posts:29,957
Registered: 26/04/06
Re: Migr. to JSF 1.2 - InputText of Integer value returns 0 instead of Null   
Jan 9, 2009 12:31 PM (reply 13 of 13)  (In reply to #11 )
 
 
How about this testcase? Run it as a Java application.

package test;
 
public class Test {
 
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (j == 2) {
                    break;
                }
                System.out.println(i + "," + j);
            }
        }
    }
 
}

It should print
0,0
0,1
1,0
1,1
2,0
2,1

and not
0,0
0,1

as you seem to stuggle with.
 
This topic has 13 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 25
  • Guests : 132

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums