Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > html:select default value in Struts

Reply
Thread Tools

html:select default value in Struts

 
 
LDM
Guest
Posts: n/a
 
      10-10-2003
Hi,

I have this Struts html form in a JSP page:

<html:select property="id" onchange="submit();">
<htmlption value="">--- Choose one ---</htmlption>
<htmlptions collection="list" property="id" labelProperty="name"/>
</html:select>

When I select an option, some data are displayed under the form,
depending on the option I've selected, and the option I've chosen
still stays selected: that's ok because I stay on this page.
Now I want that when I go to another page and come back to this page,
the first option ("Choose one") is selected. Each time I come back to
the form, the last option I've selected appears selected. How to do
this???
 
Reply With Quote
 
 
 
 
Wendy S
Guest
Posts: n/a
 
      10-10-2003
> When I select an option, some data are displayed under the form,
> depending on the option I've selected, and the option I've chosen
> still stays selected: that's ok because I stay on this page.
> Now I want that when I go to another page and come back to this page,
> the first option ("Choose one") is selected. Each time I come back to
> the form, the last option I've selected appears selected. How to do
> this???


In the Action, determine whether this is the "first" time it is being
called. (First is relative, of course... what you want to know is, was THIS
form just submitted, or am I coming to this Action from somewhere else.)
Then set the 'id' property of the form bean to the empty String (or not,
depending.) Struts checks the "id" property of the ActionForm to determine
which of the options should be pre-selected.

Are you always going through an Action first, and never going straight to
the JSP?

--
Wendy in Chandler, AZ


 
Reply With Quote
 
 
 
 
LDM
Guest
Posts: n/a
 
      10-13-2003
I use an Action to do this.
So, how to do what you said?
If we consider that I have a 'BuildListAction' action which builds my
selection list, and in my JSP a 'GetDataForm' form associated with a
'GetDataAction', I just can't see how I should refer to my
'GetDataForm' form in my 'BuildListAction' action...
Thanks for your help.

"Wendy S" <(E-Mail Removed)> wrote in message news:<bm6nbu$q2c$(E-Mail Removed)>...
> > When I select an option, some data are displayed under the form,
> > depending on the option I've selected, and the option I've chosen
> > still stays selected: that's ok because I stay on this page.
> > Now I want that when I go to another page and come back to this page,
> > the first option ("Choose one") is selected. Each time I come back to
> > the form, the last option I've selected appears selected. How to do
> > this???

>
> In the Action, determine whether this is the "first" time it is being
> called. (First is relative, of course... what you want to know is, was THIS
> form just submitted, or am I coming to this Action from somewhere else.)
> Then set the 'id' property of the form bean to the empty String (or not,
> depending.) Struts checks the "id" property of the ActionForm to determine
> which of the options should be pre-selected.
>
> Are you always going through an Action first, and never going straight to
> the JSP?

 
Reply With Quote
 
Wendy S
Guest
Posts: n/a
 
      10-13-2003
"LDM" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I use an Action to do this.
> So, how to do what you said?
> If we consider that I have a 'BuildListAction' action which builds my
> selection list, and in my JSP a 'GetDataForm' form associated with a
> 'GetDataAction', I just can't see how I should refer to my
> 'GetDataForm' form in my 'BuildListAction' action...
> Thanks for your help.


Obviously I haven't seen your code, but I don't think 'BuildListAction'
needs to be its own separate Action. It sounds like it belongs in
supporting code, perhaps part of the data access layer if this data is
coming from a database.

Then in the 'GetDataAction', you call this other code, perhaps
ListDAO.getList("something"); and place that in request or session scope.
To figure out if this is the "first" time, you can do something like look
for the presence of a hidden form field, or check whether the request has
been POSTed to you, rather than a GET.

Can you post the workflow as it stands now? What URL is visited first,
which JSP does it go to, where does the form on that JSP go?

--
Wendy in Chandler, AZ


 
Reply With Quote
 
LDM
Guest
Posts: n/a
 
      10-14-2003
The workflow looks like this:

BuildList.do
page1.jsp ---------------> page2.jsp

BuildListAction is called, and builds a selection list in page2.jsp
with data retrieved from a database, as you guessed.

GetData.do
page2.jsp ---------------> page2.jsp (updated)

page2.jsp contains GetDataForm with the <html:select> valued to
"Choose one". When this form is submitted, page2.jsp is updated by
GetDataAction with other data retrieved from the database.
And I'd like the <html:select> staying with the value I've just
selected.

When I go back to page1.jsp and then return to page2.jsp,
<html:select> must be valued to "Choose one".


"Wendy S" <(E-Mail Removed)> wrote in message news:<bmee76$h88$(E-Mail Removed)>...
> "LDM" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > I use an Action to do this.
> > So, how to do what you said?
> > If we consider that I have a 'BuildListAction' action which builds my
> > selection list, and in my JSP a 'GetDataForm' form associated with a
> > 'GetDataAction', I just can't see how I should refer to my
> > 'GetDataForm' form in my 'BuildListAction' action...
> > Thanks for your help.

>
> Obviously I haven't seen your code, but I don't think 'BuildListAction'
> needs to be its own separate Action. It sounds like it belongs in
> supporting code, perhaps part of the data access layer if this data is
> coming from a database.
>
> Then in the 'GetDataAction', you call this other code, perhaps
> ListDAO.getList("something"); and place that in request or session scope.
> To figure out if this is the "first" time, you can do something like look
> for the presence of a hidden form field, or check whether the request has
> been POSTed to you, rather than a GET.
>
> Can you post the workflow as it stands now? What URL is visited first,
> which JSP does it go to, where does the form on that JSP go?

 
Reply With Quote
 
Wendy S
Guest
Posts: n/a
 
      10-15-2003
Are you ever visiting a URL with .jsp in it? In general, EVERY request has
to go through the Action, or things start falling apart. You have arrows
going _to_ page2.jsp, which worries me. I think it should be
page1.jsp ----> GetData.do

I still don't quite understand what's happening, but I think putting a
hidden form field on page2.jsp might help. Then in GetDataAction, look for
that hidden field in the form bean. If it's not there, set the property
that corresponds to the drop down to "" before forwarding to page2.jsp. If
the hidden property _is_ there, that tells you that the form on page2.jsp
was just submitted, and you need to preserve the value.

It also sounds like you have your form beans in session scope, and you might
find request scope more appropriate. Request scope forms have their own set
of problems, however!

--
Wendy in Chandler, AZ

"LDM" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> The workflow looks like this:
>
> BuildList.do
> page1.jsp ---------------> page2.jsp
>
> BuildListAction is called, and builds a selection list in page2.jsp
> with data retrieved from a database, as you guessed.
>
> GetData.do
> page2.jsp ---------------> page2.jsp (updated)
>
> page2.jsp contains GetDataForm with the <html:select> valued to
> "Choose one". When this form is submitted, page2.jsp is updated by
> GetDataAction with other data retrieved from the database.
> And I'd like the <html:select> staying with the value I've just
> selected.
>
> When I go back to page1.jsp and then return to page2.jsp,
> <html:select> must be valued to "Choose one".
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using default a empty dictionary as a default value C Gillespie Python 3 03-22-2005 12:22 PM
Is it safe to point to Internet for locating struts DTD files in struts TLDs and XML files? Katie Wright Java 8 01-07-2005 03:37 PM
[Struts]output javascript in struts perform() sin Java 3 02-22-2004 08:27 AM
Integrate a Struts app with a non-struts app jc1771 Java 0 12-28-2003 06:36 PM
Struts Installation - missing struts.tld??? Jason Us Java 0 10-03-2003 11:36 PM



Advertisments