You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas Thomas <de...@gmail.com> on 2006/11/29 22:52:11 UTC

validate question ...

Hi,

My web-application allows a user to authenticate to the website.

I check for login and password with the Validator Framework (correct length,
correct carachters, ...)
Then display with <html:errors property="login"/> and <html:errors
property="password"/> in my jsp.
This work ok.

If he the fields are valid, I need to check in my DB if the user is really
subscribed.

1) Where should I do the DB validation ?
2) How do I return the errors to JSP, how do I display the errors in my jsp
?
can I have something similar like : <html:errors property="dberror"/> or
something like that ?
what's best ?


I have for this a "DynaValidatorForm" and an Action "LoginAction" if fields
are correct for the validator :

    <form-beans>
        <form-bean name="loginForm" type="
org.apache.struts.validator.DynaValidatorForm">
                 <form-property name="login" type="java.lang.String" />
                 <form-property name="password" type="java.lang.String" />
        </form-bean>
        [...]
        <action
            path="/Login"
            type="controllers.submits.LoginAction"
            name="loginForm"
            input="/Error.do"
            validate="true"
            scope="request">
                <forward name="index" path="/index.jsp"/>
                <forward name="chat" path="/chat_form.jsp"/>
        </action>

And my JSP :

                    login :
                <br/>
                <html:text property="login" size="10"/>
                <!--  <span id="txtUsernameMsg">
                    Le login spécifié est invalide !
                </span>-->

                <html:errors property="login"/>     <--- DISPLAY error if
login is empty

<!--
                I WANT TO DISPLAY A MESSAGE HERE IF USER DOESNT EXIST IN
DATABASE, how ?
-->

                <br/>
                    mot de passe :
                <br/>
                <html:password property="password" size="10"/>
                <!-- <span id="txtPasswordMsg">
                    Le mot de passe spécifié est invalide !
                </span>
                 -->
                <html:errors property="password"/>     <--- DISPLAY error if
password is empty

                <br/>

Re: validate question ...

Posted by Martin Gainty <mg...@hotmail.com>.
+1
Here is One example complete with configuration for <data-source>
http://www.roseindia.net/struts/strutsdatasourcemanagerontomcat5.shtml

Anyone else?
M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: <pa...@axa.com.au>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Wednesday, November 29, 2006 5:01 PM
Subject: Re: validate question ...


Do the DB validation in:
controllers.submits.LoginAction (execute) method.

The error handling should be:

If DB validation fails, create Action Error or Message and then pass it 
back to the JSP as a failure.

The Error tags should be able to display it. If you use <html:errors/> you 
dont have to manage individual <html:error> tags.

Thanks and regards,
Pazhanikanthan. P (Paz)

Consultant for AXA,
Senior Software Engineer,
HCL Australia Services Pty. Ltd.
Off   : +61-3-9618-4085
Mob : +61-0411-354-838




"Thomas Thomas" <de...@gmail.com>
30/11/2006 08:52 AM
Please respond to "Struts Users Mailing List"
 
        To:     "Struts Users Mailing List" <us...@struts.apache.org>
        cc: 
        Subject:        validate question ...


Hi,

My web-application allows a user to authenticate to the website.

I check for login and password with the Validator Framework (correct 
length,
correct carachters, ...)
Then display with <html:errors property="login"/> and <html:errors
property="password"/> in my jsp.
This work ok.

If he the fields are valid, I need to check in my DB if the user is really
subscribed.

1) Where should I do the DB validation ?
2) How do I return the errors to JSP, how do I display the errors in my 
jsp
?
can I have something similar like : <html:errors property="dberror"/> or
something like that ?
what's best ?


I have for this a "DynaValidatorForm" and an Action "LoginAction" if 
fields
are correct for the validator :

    <form-beans>
        <form-bean name="loginForm" type="
org.apache.struts.validator.DynaValidatorForm">
                 <form-property name="login" type="java.lang.String" />
                 <form-property name="password" type="java.lang.String" />
        </form-bean>
        [...]
        <action
            path="/Login"
            type="controllers.submits.LoginAction"
            name="loginForm"
            input="/Error.do"
            validate="true"
            scope="request">
                <forward name="index" path="/index.jsp"/>
                <forward name="chat" path="/chat_form.jsp"/>
        </action>

And my JSP :

                    login :
                <br/>
                <html:text property="login" size="10"/>
                <!--  <span id="txtUsernameMsg">
                    Le login spécifié est invalide !
                </span>-->

                <html:errors property="login"/>     <--- DISPLAY error if
login is empty

<!--
                I WANT TO DISPLAY A MESSAGE HERE IF USER DOESNT EXIST IN
DATABASE, how ?
-->

                <br/>
                    mot de passe :
                <br/>
                <html:password property="password" size="10"/>
                <!-- <span id="txtPasswordMsg">
                    Le mot de passe spécifié est invalide !
                </span>
                 -->
                <html:errors property="password"/>     <--- DISPLAY error 
if
password is empty

                <br/>

_____________________________________________________________________ 
This e-mail has been scanned for viruses by MCI's Internet Managed 
Scanning Services - powered by MessageLabs. For further information 
visit http://www.mci.com

*********************************************************************************
Important Note
This email (including any attachments) contains information which is 
confidential and may be subject to legal privilege.  If you are not 
the intended recipient you must not use, distribute or copy this 
email.  If you have received this email in error please notify the 
sender immediately and delete this email. Any views expressed in this 
email are not necessarily the views of AXA.   Thank you.
**********************************************************************************

Re: validate question ...

Posted by pa...@axa.com.au.
Do the DB validation in:
controllers.submits.LoginAction (execute) method.

The error handling should be:

If DB validation fails, create Action Error or Message and then pass it 
back to the JSP as a failure.

The Error tags should be able to display it. If you use <html:errors/> you 
dont have to manage individual <html:error> tags.

Thanks and regards,
Pazhanikanthan. P (Paz)

Consultant for AXA,
Senior Software Engineer,
HCL Australia Services Pty. Ltd.
Off   : +61-3-9618-4085
Mob : +61-0411-354-838




"Thomas Thomas" <de...@gmail.com>
30/11/2006 08:52 AM
Please respond to "Struts Users Mailing List"
 
        To:     "Struts Users Mailing List" <us...@struts.apache.org>
        cc: 
        Subject:        validate question ...


Hi,

My web-application allows a user to authenticate to the website.

I check for login and password with the Validator Framework (correct 
length,
correct carachters, ...)
Then display with <html:errors property="login"/> and <html:errors
property="password"/> in my jsp.
This work ok.

If he the fields are valid, I need to check in my DB if the user is really
subscribed.

1) Where should I do the DB validation ?
2) How do I return the errors to JSP, how do I display the errors in my 
jsp
?
can I have something similar like : <html:errors property="dberror"/> or
something like that ?
what's best ?


I have for this a "DynaValidatorForm" and an Action "LoginAction" if 
fields
are correct for the validator :

    <form-beans>
        <form-bean name="loginForm" type="
org.apache.struts.validator.DynaValidatorForm">
                 <form-property name="login" type="java.lang.String" />
                 <form-property name="password" type="java.lang.String" />
        </form-bean>
        [...]
        <action
            path="/Login"
            type="controllers.submits.LoginAction"
            name="loginForm"
            input="/Error.do"
            validate="true"
            scope="request">
                <forward name="index" path="/index.jsp"/>
                <forward name="chat" path="/chat_form.jsp"/>
        </action>

And my JSP :

                    login :
                <br/>
                <html:text property="login" size="10"/>
                <!--  <span id="txtUsernameMsg">
                    Le login spécifié est invalide !
                </span>-->

                <html:errors property="login"/>     <--- DISPLAY error if
login is empty

<!--
                I WANT TO DISPLAY A MESSAGE HERE IF USER DOESNT EXIST IN
DATABASE, how ?
-->

                <br/>
                    mot de passe :
                <br/>
                <html:password property="password" size="10"/>
                <!-- <span id="txtPasswordMsg">
                    Le mot de passe spécifié est invalide !
                </span>
                 -->
                <html:errors property="password"/>     <--- DISPLAY error 
if
password is empty

                <br/>

_____________________________________________________________________ 
This e-mail has been scanned for viruses by MCI's Internet Managed 
Scanning Services - powered by MessageLabs. For further information 
visit http://www.mci.com

*********************************************************************************
Important Note
This email (including any attachments) contains information which is 
confidential and may be subject to legal privilege.  If you are not 
the intended recipient you must not use, distribute or copy this 
email.  If you have received this email in error please notify the 
sender immediately and delete this email. Any views expressed in this 
email are not necessarily the views of AXA.   Thank you.
**********************************************************************************

RE: validate question ...

Posted by Scott Purcell <sp...@ilevy.com>.
Basically, the way I would envision this, is that the validation framework checks to make sure the 'username' and 'password' fields are not NULL, or meet some form of low level character count.

Anyway, that is good. What I would do, is continue with that, then after the validator says this is acceptable, it should go to your controller. Within the controller, you should call a business object with the two fields, username, and password. The business object should return a value of success or failure.

If success, set user into session (or whatever) and let them in.

If not, throw a global exception (set a global exception in struts-config.xml) and set a message into the request. This should send them back to the login screen and they will see a message that the login was NOT successful.

Make sense? I think that is how I used to do it.

Scott





-----Original Message-----
From: Thomas Thomas [mailto:debussy007@gmail.com] 
Sent: Wednesday, November 29, 2006 3:52 PM
To: Struts Users Mailing List
Subject: validate question ...

Hi,

My web-application allows a user to authenticate to the website.

I check for login and password with the Validator Framework (correct length,
correct carachters, ...)
Then display with <html:errors property="login"/> and <html:errors
property="password"/> in my jsp.
This work ok.

If he the fields are valid, I need to check in my DB if the user is really
subscribed.

1) Where should I do the DB validation ?
2) How do I return the errors to JSP, how do I display the errors in my jsp
?
can I have something similar like : <html:errors property="dberror"/> or
something like that ?
what's best ?


I have for this a "DynaValidatorForm" and an Action "LoginAction" if fields
are correct for the validator :

    <form-beans>
        <form-bean name="loginForm" type="
org.apache.struts.validator.DynaValidatorForm">
                 <form-property name="login" type="java.lang.String" />
                 <form-property name="password" type="java.lang.String" />
        </form-bean>
        [...]
        <action
            path="/Login"
            type="controllers.submits.LoginAction"
            name="loginForm"
            input="/Error.do"
            validate="true"
            scope="request">
                <forward name="index" path="/index.jsp"/>
                <forward name="chat" path="/chat_form.jsp"/>
        </action>

And my JSP :

                    login :
                <br/>
                <html:text property="login" size="10"/>
                <!--  <span id="txtUsernameMsg">
                    Le login spécifié est invalide !
                </span>-->

                <html:errors property="login"/>     <--- DISPLAY error if
login is empty

<!--
                I WANT TO DISPLAY A MESSAGE HERE IF USER DOESNT EXIST IN
DATABASE, how ?
-->

                <br/>
                    mot de passe :
                <br/>
                <html:password property="password" size="10"/>
                <!-- <span id="txtPasswordMsg">
                    Le mot de passe spécifié est invalide !
                </span>
                 -->
                <html:errors property="password"/>     <--- DISPLAY error if
password is empty

                <br/>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org