This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Struts and the fly likes html:option tag and default value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:option tag and default value" Watch "html:option tag and default value" New topic
Author

html:option tag and default value

Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
I am trying to figure out to set a default value using html ptions.

Here is my struts-config.xml



So, from displayTable.jsp , I am forwarding my request to display1.jsp where I need to default select a code. I have forms and actions associated with both jsp's. So, in the action associated with displayTable.jsp, I set the status cd for the next form(which I need to set the default) but since I do, mapping.findForward, it doesn't seem to be making much sense doing it. The actual form associated with the display1.jsp, where I need the default, seems to be too late to do anything. Would Request dispacther be a better idea ? I hope somebody can make some sense out of what I am saying. I appreciate anybody's help. Thanks.


SCJP,SCWCD(1.4)
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One possible solution might be to set the default in the form bean's reset() method, or possibly in the bean's constructor. That way, no matter which action precedes it, the default will always be set. Since reset() get's called before struts populates the properties of the form bean, it will be overriden by whatever the user enters.
[ March 23, 2005: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Gran Roguismo
Ranch Hand

Joined: Mar 10, 2005
Posts: 77
I think I am looking to do the same thing, not sure.
I have one action that is looking to pass values to a second action where the dropdowns will default to values from the formbean.

here is the tag that I am using:

how can I tell it to look at the reportForm bean and if the value dialdCntryCode matches the option this should be the one that is selected?


EOL
Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
Wow ! That worked. Thank you so much, Merrill!!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Gran,

Either in the action that forwards to the jsp, or in the reset() method of the form, simply call reportForm.setDialdCntryCode(). When the JSP is displayed, struts will automatcially make the comparison, and put "selected" in the appropriate option.
Gran Roguismo
Ranch Hand

Joined: Mar 10, 2005
Posts: 77
thanks Merril,
you were correct, and I found that my problem was actually do to another error dealing with the fact that one getter method was actually returning the string in upper case. When it found that these did not match it set it to it's default and I had my problem.
You did give me a better idea of how this pulls together though, and I'm sure that will come in handy in the future.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:option tag and default value
 
Similar Threads
Validation and HttpSession
I am getting error when starting Tomcat .How can I rectify it?
problem in getting data from request
data stored in DynaActionForm is not displayed on jsp page
problem:Invalid path was requested /RES_userhomepage