cancel
Showing results for 
Search instead for 
Did you mean: 

Validating user input in bean

Former Member
0 Kudos

Hi All,

I created a  new xhtml page with input fields of datatype alpha-numeric, email etc in a panel grid and also created a managed bean.

In order to validate the user input, in xhtml page i registered  PostValidateEvent system event in the panel grid which contains all the input fields

     <f:event listener="#{beanName.validateFields}" type="postValidate" />

and  a “listener” method with signature public void method-name(ComponentSystemEvent event) in the bean.

       public void validateFields((ComponentSystemEvent  event){

         // field validations

      }

I didnot get any build or deploy error related to the event registered. But the postvalidate event is not triggered and validation is not done.

Please help me to validate the user inputs in the bean.

Thanks,

Nithya

Accepted Solutions (0)

Answers (3)

Answers (3)

ralf_detzler
Explorer
0 Kudos

Hi Nithya,

I have just tried your event listener coding in an example Web Channel Application and it works perfect.

I assume, that something with your DC setup is not correct. To ensure, that JSF 2 is working correct, the following preconditions have to be fulfilled:

  1. The developemnt component wec/frw/tc/jsf/libsrv has to be deployed.
    This contains the JSF 2 implementation for the Java EE.
  2. A hard reference
    <reference reference-type="hard" prepend="true">
      <reference-target provider-name="sap.com"
       target-type="library">wec~frw~tc~jsf~lib</reference-target>
    </reference>
    has to be included in the application-j2ee-engine.xml file of the
    application and into the application-j2ee-engine.xml file of the
    modules, that are using JSF functionality. This ensures, that the
    deployment units can access the JSF 2 implementation on the server.
  3. A DC dependency to engine.jee5.facade with public part
    "apiwithoutjsf" has to be included into the modules ui part. The public
    part "api" must not be included. This ensures, that the code is not
    linked against the JSF 1.2 api of the engine.
  4. A DC dependency to wec/frw/tc/jsf/lib with public part "api" has to
    be included into the modules ui part. This makes the JSF 2 api available
    for the module.

Please check, if all these preconditions are fulfilled. I  assume, that 3. and/or 4. are not fulfilled.

Please keep me informed, if this solves the problem.

Ralf

Former Member
0 Kudos

Hi Nithya

Can you check the below link, hope it will help you?

http://www.mkyong.com/jsf2/multi-components-validator-in-jsf-2-0/

daniel_ruiz2
Active Contributor
0 Kudos

Hi,

There is different ways on see why this is an issue. IMO, issue lies in Eclipse WebChannel Builder plugin. But then again, this is my personal opinion..

To use the <f:event listener..> you need to be running JSF 2 - but the NW AS has a 1.2 deployed which is loaded 'by default' - and the WCEM has a DC called "wec/frw/tc/jsf/lib" which contains the JSF 2 library.

As far I'm concerned, as soon we create a 'new module' using the plugin we should get a reference to the JSF 2 library in the dpu file "application-j2ee-engine.xml" - but this would probably lead SAP to maintain two versions of the plugin, to keep WCEM 1 and WCEM 2 working.

All you have to do to use JSF 2 library you need to open your custom DC dpu (related to the UI part in question) and add into the "application-j2ee-engine.xml" the following:

<reference reference-type="hard" prepend="true">

          <reference-target provider-name="sap.com"

          target-type="library">wec~frw~tc~jsf~lib</reference-target>

</reference>

This way your DPU will be using JSF2 and your code should work just fine.

Hope it helps,

D.

Former Member
0 Kudos

Hi Daniel,

Thanks for your elaborate information.

I can find JSF 2 library is already included in "application-j2ee-engine.xml". But still the event is not triggered.

Kindly let me know how to proceed with validating user input.

Regards,

Nithya

daniel_ruiz2
Active Contributor
0 Kudos

Hi,

I dont have NWDS open to check - could it be due the fact you have JSF 2.0 and the "type" was introduced in 2.1?

I'm not too sure if I have ever used it before in WCEM - I would suggest you override the impl. supplied by SAP with your own DC/SDA containing the latest impl. plus latest el-api/impl too.

Please let me know once you have tried.

D.

former_member223302
Active Participant
0 Kudos

Hi Nithya,

where did you place the <f:event> tag?

Did you debug or how did you make sure that your method is getting called?

Are you using WCEM 2.0?

Regards,

Elena

Former Member
0 Kudos

Hi Elena,

Thanks for your interest in helping me.

I am using WCEM 2.0. I placed <f:event> tag within <wec:panelGrid> which contains all the components i need to validate. when i debug, the control is not breaking in validateField(

ComponentSystemEvent event) method, which means postValidateevent is not getting triggered.

Please let me know is there any alternative way to validate input data?

Regards,

Nithya