You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vikrama Sanjeeva <vi...@gmail.com> on 2005/12/21 15:35:52 UTC

text field not populating after validate() fails.

Hi,

 I have a form which consists of pull-down menus, radio button, text area
and text fields. The form takes all the required input fields from user,
validate them and if validation fail's, the same form is called with
pre-populated values (as entered 1st time by user). This is true when there
is NO form "name" and "type" is given in form tag. But when I give form
"name" and "type" in form tag, only pull-down menus are populated if
validation fails. Whereas, text field, text area and radio buttons are not
pre-poulated.

  I'm not sure what is going wrong here?? Below is the related code I'm
using.

/******** struts-config.xml*******/

<form-bean name="myForm" type="com.world.MyForm"/>

<action path="/MyActionPath"
            type="com.world.MyActionClass"
            name="myForm"
            scope="request"
            validate="true"
            input="myForm.jsp"
            >
            <forward
                    name="success"
                    path="/myHome.jsp"/>
 </action>

/******** struts-config.xml*******/

/********START myForm.jsp*******/

<!-- When given form "name" and "type", it fails to populate the text field,
radio-button and text-area after validation falis. -->

<html:form   name="myForm" type="com.world.MyForm"  action="/MyActionPath"
method="post" enctype="multipart/form-data">

        <html:radio property="happy"  value="Y">Happy</html:radio>

        <html:select name="myForm" property="country">
            <html:option value="">Select Country</html:option>
             <html:options collection="countryNames" property="countryName"
labelProperty="countryName" />
        </html:select>

        <html:text property="name"></html:text>

       <html:textarea property="details"></html:textarea>

</html:form>
/******** END myForm.jsp*******/


Bye,
Viki.

Re: text field not populating after validate() fails.

Posted by Vikrama Sanjeeva <vi...@gmail.com>.
Hi,

     Ok I will read Rick's article. Right now situation is bit different
(I'm sure most of junior developers face more or less same situation). As
for me, I've certain deadline to achieve the functionality, which I have
achieved by just setting scope=session.

   Now as Rick said:

"(nothing wrong with using the Session either but personally I don't think
you should use the Session for storing lists for form dropdowns.) "

At this stage, I'm more curious about the difference b/w two approaches.
Which one is more effecient (in terms of performance), reliable and
scalable. So that I can adopt the right approach for future struts based
development.

Thanks guys for discussing this topic.

Bye,
Viki.


On 12/24/05, Rahul Akolkar <ra...@gmail.com> wrote:
>
> On 12/24/05, Vikrama Sanjeeva <vi...@gmail.com> wrote:
> > H,
> >  Rahul: The pull-down menus are prepopulated using the session. For
> > pull-down menus, I'm using the same approach as Rick used in "LESSON II
> - 9
> > - Create SetUpEmployeeAction". You can see here:
> > http://www.reumann.net/struts/lesson2/step9.do
> >
> <snip/>
>
> OK, my question was about the text fields and textareas that were
> *not* getting populated after validation failure.
>
> But, please see Rick's pointer in the earlier email to this thread.
>
> -Rahul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: text field not populating after validate() fails.

Posted by Rahul Akolkar <ra...@gmail.com>.
On 12/24/05, Vikrama Sanjeeva <vi...@gmail.com> wrote:
> H,
>  Rahul: The pull-down menus are prepopulated using the session. For
> pull-down menus, I'm using the same approach as Rick used in "LESSON II - 9
> - Create SetUpEmployeeAction". You can see here:
> http://www.reumann.net/struts/lesson2/step9.do
>
<snip/>

OK, my question was about the text fields and textareas that were
*not* getting populated after validation failure.

But, please see Rick's pointer in the earlier email to this thread.

-Rahul

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


Re: text field not populating after validate() fails.

Posted by Rick Reumann <ri...@gmail.com>.
On 12/24/05, Vikrama Sanjeeva <vi...@gmail.com> wrote:
>
>
> Rick: I've change the "scope" in struts-config from "request" to "session"
> and it is working fine now. But question is, why it is not working with
> scope=request?


Did you read this article I posted?
http://www.reumann.net/struts/articles/request_lists.jsp Not trying to avoid
the question, but I mention it there in better detail in the first
paragraph. You shouldn't need to use the Session to store those lists if you
read that article (nothing wrong with using the Session either but
personally I don't think you should use the Session for storing lists for
form dropdowns.)

--
Rick

Re: text field not populating after validate() fails.

Posted by Vikrama Sanjeeva <vi...@gmail.com>.
H,
 Rahul: The pull-down menus are prepopulated using the session. For
pull-down menus, I'm using the same approach as Rick used in "LESSON II - 9
- Create SetUpEmployeeAction". You can see here:
http://www.reumann.net/struts/lesson2/step9.do

Rick: I've change the "scope" in struts-config from "request" to "session"
and it is working fine now. But question is, why it is not working with
scope=request?

Bye,
Viki.


On 12/24/05, Rick Reumann <ri...@gmail.com> wrote:
>
> On 12/21/05, Vikrama Sanjeeva <vi...@gmail.com> wrote:
> >
> >
> > I have a form which consists of pull-down menus, radio button, text area
> > and text fields. The form takes all the required input fields from user,
> > validate them and if validation fail's, the same form is called with
> > pre-populated values (as entered 1st time by user). This is true when
> > there
> > is NO form "name" and "type" is given in form tag. But when I give form
> > "name" and "type" in form tag, only pull-down menus are populated if
> > validation fails. Whereas, text field, text area and radio buttons are
> not
> > pre-poulated.
> >
> >   I'm not sure what is going wrong here?? Below is the related code I'm
> > using.
>
>
>
> This is a classic problem and it is why I recommend you call your
> validation
> manually from your Action class. I decribe in detail the exact problem you
> are encountering here
> http://www.reumann.net/struts/articles/request_lists.jsp and the solution
> I
> like to use.
>
> --
> Rick
>
>

Re: text field not populating after validate() fails.

Posted by Rick Reumann <ri...@gmail.com>.
On 12/21/05, Vikrama Sanjeeva <vi...@gmail.com> wrote:
>
>
> I have a form which consists of pull-down menus, radio button, text area
> and text fields. The form takes all the required input fields from user,
> validate them and if validation fail's, the same form is called with
> pre-populated values (as entered 1st time by user). This is true when
> there
> is NO form "name" and "type" is given in form tag. But when I give form
> "name" and "type" in form tag, only pull-down menus are populated if
> validation fails. Whereas, text field, text area and radio buttons are not
> pre-poulated.
>
>   I'm not sure what is going wrong here?? Below is the related code I'm
> using.



This is a classic problem and it is why I recommend you call your validation
manually from your Action class. I decribe in detail the exact problem you
are encountering here
http://www.reumann.net/struts/articles/request_lists.jsp and the solution I
like to use.

--
Rick

Re: text field not populating after validate() fails.

Posted by Rahul Akolkar <ra...@gmail.com>.
On 12/22/05, Vikrama Sanjeeva <vi...@gmail.com> wrote:
> Actually I'm using a javascript which needs to define form name. And in
> struts, when you define form name it is mandatory to define type too.
>
>    I just change the "scope" in struts-config from "request" to "session"
> and it is working fine now. But question is, why it is not working with
> scope=request?
>
<snip/>

What is the pre-population mechanism that you mention below? Is it
request-sensitive for the controls that don't get pre-populated?

-Rahul


> Bye,
> Viki.
>
> On 12/22/05, Laurie Harper <la...@holoweb.net> wrote:
> >
> > You shouldn't need either name or type, Struts will derive both from the
> > configuration. Since you say that's working OK for you, why are you
> > trying to add them?
> >
> > L.
> >
> > Vikrama Sanjeeva wrote:
> > > Hi,
> > >
> > >  I have a form which consists of pull-down menus, radio button, text
> > area
> > > and text fields. The form takes all the required input fields from user,
> > > validate them and if validation fail's, the same form is called with
> > > pre-populated values (as entered 1st time by user). This is true when
> > there
> > > is NO form "name" and "type" is given in form tag. But when I give form
> > > "name" and "type" in form tag, only pull-down menus are populated if
> > > validation fails. Whereas, text field, text area and radio buttons are
> > not
> > > pre-poulated.
> > >
> > >   I'm not sure what is going wrong here?? Below is the related code I'm
> > > using.
> > >
> > > /******** struts-config.xml*******/
> > >
> > > <form-bean name="myForm" type="com.world.MyForm"/>
> > >
> > > <action path="/MyActionPath"
> > >             type="com.world.MyActionClass"
> > >             name="myForm"
> > >             scope="request"
> > >             validate="true"
> > >             input="myForm.jsp"
> > >             >
> > >             <forward
> > >                     name="success"
> > >                     path="/myHome.jsp"/>
> > >  </action>
> > >
> > > /******** struts-config.xml*******/
> > >
> > > /********START myForm.jsp*******/
> > >
> > > <!-- When given form "name" and "type", it fails to populate the text
> > field,
> > > radio-button and text-area after validation falis. -->
> > >
> > > <html:form   name="myForm" type="com.world.MyForm
> > "  action="/MyActionPath"
> > > method="post" enctype="multipart/form-data">
> > >
> > >         <html:radio property="happy"  value="Y">Happy</html:radio>
> > >
> > >         <html:select name="myForm" property="country">
> > >             <html:option value="">Select Country</html:option>
> > >              <html:options collection="countryNames"
> > property="countryName"
> > > labelProperty="countryName" />
> > >         </html:select>
> > >
> > >         <html:text property="name"></html:text>
> > >
> > >        <html:textarea property="details"></html:textarea>
> > >
> > > </html:form>
> > > /******** END myForm.jsp*******/
> > >
> > >
> > > Bye,
> > > Viki.
> > >
<snap/>

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


Re: text field not populating after validate() fails.

Posted by Vikrama Sanjeeva <vi...@gmail.com>.
Actually I'm using a javascript which needs to define form name. And in
struts, when you define form name it is mandatory to define type too.

    I just change the "scope" in struts-config from "request" to "session"
and it is working fine now. But question is, why it is not working with
scope=request?

Bye,
Viki.

On 12/22/05, Laurie Harper <la...@holoweb.net> wrote:
>
> You shouldn't need either name or type, Struts will derive both from the
> configuration. Since you say that's working OK for you, why are you
> trying to add them?
>
> L.
>
> Vikrama Sanjeeva wrote:
> > Hi,
> >
> >  I have a form which consists of pull-down menus, radio button, text
> area
> > and text fields. The form takes all the required input fields from user,
> > validate them and if validation fail's, the same form is called with
> > pre-populated values (as entered 1st time by user). This is true when
> there
> > is NO form "name" and "type" is given in form tag. But when I give form
> > "name" and "type" in form tag, only pull-down menus are populated if
> > validation fails. Whereas, text field, text area and radio buttons are
> not
> > pre-poulated.
> >
> >   I'm not sure what is going wrong here?? Below is the related code I'm
> > using.
> >
> > /******** struts-config.xml*******/
> >
> > <form-bean name="myForm" type="com.world.MyForm"/>
> >
> > <action path="/MyActionPath"
> >             type="com.world.MyActionClass"
> >             name="myForm"
> >             scope="request"
> >             validate="true"
> >             input="myForm.jsp"
> >             >
> >             <forward
> >                     name="success"
> >                     path="/myHome.jsp"/>
> >  </action>
> >
> > /******** struts-config.xml*******/
> >
> > /********START myForm.jsp*******/
> >
> > <!-- When given form "name" and "type", it fails to populate the text
> field,
> > radio-button and text-area after validation falis. -->
> >
> > <html:form   name="myForm" type="com.world.MyForm
> "  action="/MyActionPath"
> > method="post" enctype="multipart/form-data">
> >
> >         <html:radio property="happy"  value="Y">Happy</html:radio>
> >
> >         <html:select name="myForm" property="country">
> >             <html:option value="">Select Country</html:option>
> >              <html:options collection="countryNames"
> property="countryName"
> > labelProperty="countryName" />
> >         </html:select>
> >
> >         <html:text property="name"></html:text>
> >
> >        <html:textarea property="details"></html:textarea>
> >
> > </html:form>
> > /******** END myForm.jsp*******/
> >
> >
> > Bye,
> > Viki.
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: text field not populating after validate() fails.

Posted by Laurie Harper <la...@holoweb.net>.
You shouldn't need either name or type, Struts will derive both from the 
configuration. Since you say that's working OK for you, why are you 
trying to add them?

L.

Vikrama Sanjeeva wrote:
> Hi,
> 
>  I have a form which consists of pull-down menus, radio button, text area
> and text fields. The form takes all the required input fields from user,
> validate them and if validation fail's, the same form is called with
> pre-populated values (as entered 1st time by user). This is true when there
> is NO form "name" and "type" is given in form tag. But when I give form
> "name" and "type" in form tag, only pull-down menus are populated if
> validation fails. Whereas, text field, text area and radio buttons are not
> pre-poulated.
> 
>   I'm not sure what is going wrong here?? Below is the related code I'm
> using.
> 
> /******** struts-config.xml*******/
> 
> <form-bean name="myForm" type="com.world.MyForm"/>
> 
> <action path="/MyActionPath"
>             type="com.world.MyActionClass"
>             name="myForm"
>             scope="request"
>             validate="true"
>             input="myForm.jsp"
>             >
>             <forward
>                     name="success"
>                     path="/myHome.jsp"/>
>  </action>
> 
> /******** struts-config.xml*******/
> 
> /********START myForm.jsp*******/
> 
> <!-- When given form "name" and "type", it fails to populate the text field,
> radio-button and text-area after validation falis. -->
> 
> <html:form   name="myForm" type="com.world.MyForm"  action="/MyActionPath"
> method="post" enctype="multipart/form-data">
> 
>         <html:radio property="happy"  value="Y">Happy</html:radio>
> 
>         <html:select name="myForm" property="country">
>             <html:option value="">Select Country</html:option>
>              <html:options collection="countryNames" property="countryName"
> labelProperty="countryName" />
>         </html:select>
> 
>         <html:text property="name"></html:text>
> 
>        <html:textarea property="details"></html:textarea>
> 
> </html:form>
> /******** END myForm.jsp*******/
> 
> 
> Bye,
> Viki.
> 


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