2 Replies Latest reply on May 9, 2012 12:55 PM by 936112

    Unknown Script errors in IE7 - urgent help required

    Jeffry13
      Hi,

      I am using Jdev 11.1.1.5.0 version for development.

      Recently I had a requirement to show hide a text area based on two radio buttons.

      *********************

      <af:selectBooleanRadio text="Yes, change required"
      id="sbr1" group="rad1" autoSubmit="true" valueChangeListener="#{pageFlowScope.amendreqbeaninit.selectYes}"/>
      <af:selectBooleanRadio text="No"
      id="sbr2" group="rad1" autoSubmit="true" valueChangeListener="#{pageFlowScope.amendreqbeaninit.selectNo}"/>

      ***********************

      I added valuchange listners to both radio buttons to invoke two valuechangeevent methods.

      ******************

      public void selectYes(ValueChangeEvent valueChangeEvent) {
      AmendRequestBean amendReqBean =
      (AmendRequestBean)RequestContext.getCurrentInstance().getPageFlowScope().get("amendreqbean");

      if (valueChangeEvent.getNewValue().toString() == "true") {
      amendReqBean.setInputBlock(true);
      }

      RequestContext.getCurrentInstance().getPageFlowScope().put("amendreqbean",
      amendReqBean);
      }




      public void selectNo(ValueChangeEvent valueChangeEvent) {

      AmendRequestBean amendReqBean =
      (AmendRequestBean)RequestContext.getCurrentInstance().getPageFlowScope().get("amendreqbean");

      if (valueChangeEvent.getNewValue().toString() == "true") {
      amendReqBean.setInputBlock(false);
      }

      RequestContext.getCurrentInstance().getPageFlowScope().put("amendreqbean",
      amendReqBean);
      }
      *****************************
      But while running the code, when I click on radio buttons, the functionality is not working because of some unknown errors as below

      Message: 'elements' is null or not an object
      Line: 204
      Char: 2
      Code: 0
      URI: http://127.0.0.1:7101/SampleApp-ViewController-context-root/afr/partition/ie/default/opt/select-11.1.1.5.0-1095.js

      Please help me on this

      Jeffry
        • 1. Re: Unknown Script errors in IE7 - urgent help required
          Frank Nimphius-Oracle
          Hi,

          I assume your radio buttons work perfect if you don't hide/show the dependent component so that indeed the problem can be pointed to this switching component state. There are two problem areas I can see

          1. You don't give us much information about the text area configuration and the AmendRequestBean. If the text area component has a JSF component binding to the AmendRequestBean and if this bean is in page flow scope then you are facing a problem with serialization of JSF components. JSF components are not designed for being referenced in backing beans with a scope larger than request. In this case you need to change AmendRequestBean to either be in request scope or move the component binding out of it

          2. If AmendRequestBean is a managed bean in page flow scope, then this code is a recipe for disaster
          AmendRequestBean amendReqBean = (AmendRequestBean)RequestContext.getCurrentInstance().getPageFlowScope().get("amendreqbean");
          
            if (valueChangeEvent.getNewValue().toString() == "true") {
              amendReqBean.setInputBlock(false);
            }
          If the managed bean hasn't been instantiated before, then the bean is not existing which means you risk a NPE. Instead you should a ValueExpression in Java to properly resolve the bean so JSF can instantiate it if the instance doesn't exist. If my assumption 1) is correct then you've been lucky in that one mistake backs the other and the text area component binding always ensure an instance of page flow scope to exist

          Frank
          • 2. Re: Unknown Script errors in IE7 - urgent help required
            936112
            While possibly not the source of your pain, I can't help but comment on the following code:

            if (valueChangeEvent.getNewValue().toString() == "true") {
            amendReqBean.setInputBlock(true);
            }

            It is rare that you want to compare strings using ==. == compares memory addresses and not the character values

            String s ="Hello";
            if(s=="Hello") will produce true because s is referencing the same literal string as the reference "Hello".

            String s = new String("Hello");
            if(s == "Hello") will produce false
            if(s.equals("Hello")) will produce true

            Use .equals for string comparisons

            if (valueChangeEvent.getNewValue().toString().equals("true")) {
            amendReqBean.setInputBlock(true);
            }


            Since you are expecting the new value of the event to be a Boolean object, even better....

            if (Boolean.parseBoolean(valueChangeEvent.getNewValue().toString()) == true) {
            amendReqBean.setInputBlock(true);
            }