Repopulation is a freebie under normal circumstances.  Using JavaScript to
manipulate a form (at least to the extreme of changing the entire number of
elements on the form etc.) is not normal circumstances.

How about your JavaScript will work under normal circumstances but, wait, if
a user turns off JavaScript then your app will be almost useless.  There's
definitely variables to every equation.



-----Original Message-----
From: Sashi Ravipati [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 06, 2003 11:35 AM
To: [EMAIL PROTECTED]
Subject: RE: How to repopulate Form which has html elementswithsamename

This is a small example I started off, but in my actual application I
have Six columns what are enterable with a combination of List boxes and
text boxes. I am still not sure as how this works.

Struts says repopulation is a Freebie, but looks like it is not in my
case. 

I am struggling to understand the code snippet u sent, hope I will come
out success full


>>> [EMAIL PROTECTED] 06/06/03 11:17AM >>>

I can't think of anything special.  But actually, I don't think it makes
it
into your action if validation fails anyway.

I can see many little problems with doing what you need to do.  What if
nothing is entered for one element and not the other?  I think the
arrays
would be off...

This gets you started but I would guess that you should use a hidden
field
for the name along with a <bean:write> so that they won't submit a blank
name and make your arrays off.  This is for within the iterate tag only
of
course.  For the select you shouldn't have to worry about null so you
could
leave that as is.

Have a remove button next to each one on the error page (since they
can't
edit the name if you do a hidden field).

Are you sure you don't want to just punt?

:-)

-----Original Message-----
From: Sashi Ravipati [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 06, 2003 11:19 AM
To: [EMAIL PROTECTED]
Subject: RE: How to repopulate Form which has html elementswithsamename

Thanks for the code, this will help to start off,

Should I do any thing in the ActionForm . I do have get and set methods
for the firstname and Sex wchich accepts array .

>>> [EMAIL PROTECTED] 06/06/03 11:07AM >>>

<html:text property="firstName" value="currPerson" />
should be:
<html:text property="firstName" value="<%=currPerson%>" />

Anyway, it is untest code and not all tags (some scriplets).
Best I could do on short notice.


-----Original Message-----
From: Bailey, Shane C. [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 06, 2003 11:02 AM
To: 'Struts Users Mailing List'
Subject: RE: How to repopulate Form which has html elementswithsamename


I think I missed your original code example. With iterate tags when I
saw
the dashed lines I thought it was your email footer printing out below.

Sorry.

I think the Ray is right then.  If you are going to do things that are
outside the norm of standard HTML (like JavaScript) then you will have
to
use the same way to get out of it.

Some other posts suggest logic iterate. I guess that would work.  You
would
have to do something like:

<TABLE id="mytable">
<!-- Do a present check in case you are coming into this form for the
     first time.  Write out the ones already submitted -->
<logic:present property="firstName">
<bean:define id="sexArray" ... />
<logic:iterate id="currPerson" property="firstName" indexId="curr" >
    <% String currSex = sexArray[curr.intValue()]; %>
<TR>
  <TD>
      <html:text name="sex"
value="<%=Util.getDisplayNameFromId(currSex)%>"
       />
  </TD>
  <td><html:text property="firstName" value="currPerson" /></td>
</TR>
</logic:iterate>
</logic:present>

<TR>
  <TD>
    <html:select   property="sex">
      <html:option value="MALE">Male</html:option>
      <html:option value="FEMALE">Female</html:option>
    </html:select>
  </TD>
  <td><html:text property="firstName" /></td>
</tr>
</TABLE>


-----Original Message-----
From: Sashi Ravipati [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 06, 2003 10:31 AM
To: [EMAIL PROTECTED]
Subject: RE: How to repopulate Form which has html elementswithsamename

Shane

Sorry for all the confusion and please bear with me..

How do I get Struts to repopulate multiple elements with all with the
same property? this is my exact problem..

Let me give u my .jsp page example (Initiall the table will have one
row)

<TABLE id="mytable">
<TR>
  <TD>
    <html:select   property="sex">
      <html:option value="MALE">Male</html:option>
      <html:option value="FEMALE">Female</html:option>
    </html:select>
  </TD>
  <td><html:text property="firstName" /></td>
</tr>
</TABLE>

I have a Javascript which adds rows to the table on click of a button. 

So if user has enetered five rows of data then  How do I get Struts to
repopulate the table?

Hope i am clear.

Thanks


>>> [EMAIL PROTECTED] 06/06/03 10:08AM >>>

Then the original question from the start and asked 3 times in an hour
because it wasn't answered should have been a one liner:

How do I get Struts to repopulate multiple elements with all with the
same
property?  Or something like that.  

>From your question you say you have a (single) table with a (single)
html:text and a (single) html:select.  Now you show the code and it is a
more clear that you don't have what you mentioned.  You should have
posted a
code example in the first place. It would save time.

Now, what doesn't make sense is the same key for the bean:message.  This
is
because I have an interesting solution I am thinking about but if I knew
the
real way you intend to use the tags believe I could help better.
I can't picture the need for this on a form:

Name [     ]
Name [     ]
Name [     ]

Then if you say, it is really key="du.theName1" and the next one is
"du.theName2" then that wouldn't be truly dynamic.



-----Original Message-----
From: Sashi Ravipati [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 06, 2003 8:26 AM
To: [EMAIL PROTECTED]
Subject: RE: How to repopulate Form which has html elementswithsamename

Thanks for the sample and I have that working. But my issues is slightly
different where there are Multiple HTML elements with the same name

Eg: <bean:message key="du.theName" /><html:text property="name" />
<bean:message key="du.theName" /><html:text property="name" />
<bean:message key="du.theName" /><html:text property="name" />
<bean:message key="du.theName" /><html:text property="name" />

Then in this case how do u repopulate the page.

Thanks



>>> [EMAIL PROTECTED] 06/05/03 05:13PM >>>

Here, no more asking about it.  The code is very close but not tested.
So if
it isn't 100% right do some leg work for gosh sakes.

form.jsp:

<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<!-- I wonder if you are not putting the above line in your JSP??? -->
<html:form action="/test.do" >
<bean:message key="du.theName" /><html:text property="name" />
<bean:message key="du.whatever" /><html:text property="whatever" />
</html:form>

ActionForm class:

package my.package;
class MyForm extends org.apache.struts.action.ActionForm
{
    private String name;
    private String whatever;
    
    public void setName(String name){ this.name=name; }
    public String getName(){ return this.name; }
    public void setWhatever(String whatever){ this.whatever=whatever; }
    public String getWhatever(){ return this.whatever; }

    public String whatThe(){ return "Look at documentation closer!!!"; }

    //Define the validate method or use the struts validator.  Since you
    //a newbie which likes to repost and repost you should not use
    //validator at this point in time, please
}

Action class:

package my.package;
class MyAction extends org.apache.struts.action.Action
{
    //do stuff in the execute method
}

struts-config:

    <form-bean      name="aForm"
                    type="my.package.MyForm">
    </form-bean>

    <action    path="/showform"
        type="my.package.MyAction" 
        name="aForm" 
          input="form.jsp"
          validate="true"
        scope="request">
        <forward name="display"      path="form.jsp"/>
        <forward   name="blah"          path="crap.jsp"/>
    </action>





-----Original Message-----
From: Sashi Ravipati [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 05, 2003 4:29 PM
To: [EMAIL PROTECTED]
Subject: Re: How to repopulate Form which has html elements withsamename

Do u have any working sample so that I can build from there

>>> [EMAIL PROTECTED] 06/05/03 01:54PM >>>
Repopulating Fields.

I keep hearing that this is a freebie in struts but i have note seen it
work
on
my app yet.  i just stuff what i want to repopulate with in the session
(for
now).

It would be nice if someone could post what "setup write"  IS.  so we
can
check
if we have something set up "WRONG".

After all,  WSAD 5 came with struts preloaded so how can it be setup
wrong?



"Sashi Ravipati" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Let me rephrase my question.
>
> I have a table which looks like this.. example
> <table width="300" border="0" cellspacing="1" cellpadding="1">
> <tr>
>   <th>Name</th>
>   <th>Sex</th>
> </tr>
> <tr>
> <td><html:text  property="name" /></td>
>   <td><html:select  property="sex" >
>       <html:option value="">&nbsp;</html:option>
>        <html:option value="M" >Male</html:option>
>        <html:option value="F" >Female</html:option>
>     </html:select>
>   </td>
>   </tr>
> <tr>
>   <td><html:text property="name" /></td>
>   <td><html:select  property="sex" >
>       <html:option value="">&nbsp;</html:option>
>       <html:option value="">&nbsp;</html:option>
>        <html:option value="M" >Male</html:option>
>        <html:option value="F" >Female</html:option>
>     </html:select>
>   </td>
> </tr>
> </table>
>
> So when I add data like
> Sashi     Male
> Sushma FEMALE
>
> now I submit the form, and say there are some validation errors
>
> how can I build the table with the above values retrieving from the
Form
> Bean .My  form bean has the following methods
>
> public String[] getName(){
>     return name;
>   }
>
>   public void setName(String[] newName){
>     name = newName;
>   }
>
>   public String[] getSex(){
>     return sex;
>   }
>
>   public void setSex(String[] newSex){
>     sex = newSex;
>   }
>
> The values are getting stored in the array, but to get them back and
> build my table is what is not clear to me..
>
> <logic:iterate > may do the job but how to use it??
>
> Hope I am clear now
>
>
> >>> [EMAIL PROTECTED] 06/05/03 11:30AM >>>
>
> Sounds like you might be missing input="theform.jsp" in your action
> where
> theform.jsp is the name of your JSP you want to have come back with
the
> errors.  Also, have <html:errors/> in the JSP to report the errors
(just
> as
> important (more) than repopulating).
>
> If this doesn't help find a better (for you) online struts tutorial.
> What
> you are trying to do  is a freebie in struts (if everything is setup
> right).
>
>
> -----Original Message-----
> From: Sashi Ravipati [mailto:[EMAIL PROTECTED]
> Sent: Thursday, June 05, 2003 10:59 AM
> To: [EMAIL PROTECTED]
> Subject: How to repopulate Form which has html elements with same name
>
> Hi
>
> I am a newbie to struts...
>
> I have a dynamic table which has a <html:text >  and a <html:select> .
> The
> user cliks on a add button and enter values in each row of the table
and
> submits the form.
>
> How can I repopulate the valuse if validation fails.
>
> Can some body give a working exapmle of the Action Form that is
required
> for
> this kind of requirement.
>
> I found this in Ted Husted site but had no clue as what he is trying
to
> do,
> What is RESULT etc
>
--------------------------------------------------------------------------
--
> ---------------
> <TABLE><html:form action="/item/StoreCategory">
> <logic:iterate name="RESULT" property="iterator" id="row">
> <TR>
> <TH>name</TH>
> <TH>category</TH>
> </TR>
> <TR>
> <TD><bean:write name="row" property="name"/></TD>
> <TD><%-- REMEMBER TO SPECIFY THE ITERATE ID AS THE NAME --%>
> <html:select name="row" property="category">
> <html:option value="ART">Art</html:option>
> <html:option value="AUT">Automotive</html:option>
> <%-- ... --%>
> </html:select>
> <%-- REMEMBER TO SPECIFY THE ITERATE ID AS THE NAME --%>
> <html:hidden name="row" property="key"/>
> </TD>
> </TR>
> </logic:iterate>
> <TR>
> <TD colspan="2" align="right">
> <html:submit/>
> </TD>
> </TR>
> </html:form>
> </TABLE>
>
--------------------------------------------------------------------------
--
> -------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to