wood burning stoves 2.0*
The moose likes Struts and the fly likes html:options horrible default settings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:options horrible default settings" Watch "html:options horrible default settings" New topic
Author

html:options horrible default settings

John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
i am creating an html select pull-down menu based on collections i obtain from my bean. however, every single one of the option values it prints out has a default of selected="selected" which is totally unacceptable. this causes the _last_ item in the collection to be "selected" by default instead of the first hard-coded item "select", thus forcing the user to scroll _UP_ rather than the down.
the code is as follows:

the output is something like this:
<option value="select" selected>SELECT A GROUP</option>
<option value="CHEYETTE_TESTING_PP" selected="selected">CHEYETTE_TESTING_PP</option>
<option value="LON_PP_ALLStruct" selected="selected">LON_PP_ALLStruct</option>
... so on and so forth
any ideas as to how i can get rid of those defaults being automatically inserted into my option tags?
thanks,
john
[ March 24, 2003: Message edited by: John Low ]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4777
    
    8

The problem you are having is due to your using the same bean/property to provide the options and the values selected. The bean/property specified in the html:select tag controls which values are initially selected while the bean/property for the htmlptions tag controls the values you can selected from. If the two are the same, then all the values will be selected initially.
Normally, you will use another source for the option values. This allows you to reuse the same list source with different fields.
Example:
<html:select property="fromState" >
<htmlptions name="applists" property="states" />
</html:select>

<html:select property="toState" >
<htmlptions name="applists" property="states" />
</html:select>
Check out the org.apache.struts.util.LabelValueBean class. It comes in handy when creating lists of values for use with the options tag.


Junilu - [How to Ask Questions] [How to Answer Questions]
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
many thanks! works as expected now.
another (unrelated) question i have is regarding my error messages. my ActionForm subclass generates errors within the validate() method like this:

my jsp page simply references the ActionErrors like: <html:errors/>
however, this fails to print any messages to the jsp page despite log messages which confirm that the validation of the data failed. the application.properties file contains a key which matches the string in the ActionError so i'm not sure why this may be happening...
thanks in advance for your help!
regards
[ March 25, 2003: Message edited by: John Low ]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4777
    
    8

Where are these logging statements located? Are you sure the validate method is getting called? Does the related action mapping definition in struts-config.xml include the attribute validate="true"?
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
i excluded the logging message from my post, but it's within the validate method like:

my struts config maps this error like this:
<exception key="error.predefinedJob.groupname.required" type="java.lang.Exception" path="/pages/predefinedJob.jsp" />
from the documentation, i'm uncertain about the use of "type" in this since an error is what i specify as an error, no? is it correct to assume that the path should simply be the actual uri of the jsp or am i thinking about this incorrectly?
thanks!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4777
    
    8

Originally posted by John Low:

my struts config maps this error like this:
<exception key="error.predefinedJob.groupname.required" type="java.lang.Exception" path="/pages/predefinedJob.jsp" />
from the documentation, i'm uncertain about the use of "type" in this since an error is what i specify as an error, no? is it correct to assume that the path should simply be the actual uri of the jsp or am i thinking about this incorrectly?

You're using this incorrectly or at least it's not doing what you think it's doing. What you have defined is used by the ActionServlet when your perform/execute method throws a java.lang.Exception. It will create an ActionError using the key "error.predefinedJob.groupname.required" and then forward control to /pages/predefinedJob.jsp.
Again, this will only happen if an Exception is thrown by your Action perform().
I'm still not quite sure why your <html:errors> tag isn't displaying messages.
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
in that case, the ActionServlet will only generate this error in the case that a java.lang.Exception is thrown in the Action class? all i'm trying to do is present and record a submission error... i assume that the java.lang.Exception has no place in my mapping then... is that correct?
thanks for your help!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4777
    
    8

Re the exception in the mapping defintion: you don't need it.
Regarding the missing error message, check the mapping and make sure that the input attribute has been defined. The validate method is called prior to Action.perform/execute. If the validate method returns with a non-empty errors then Action.perform is bypassed and control is given directly back to the path defined by the mapping's input attribute. You can also set the input path programmatically using mapping.setInput().
John Low
Greenhorn

Joined: Mar 24, 2003
Posts: 15
i totally screwed up. since the container was not spitting out any "file not found"/io errors, i didn't realize that it could not find my properties file!
thanks so much for your help--much appreciated and helpful. i have another question, but i will post it in a new thread so people won't be deceived by the subject line... if you could take a look at that, it would be great.
thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:options horrible default settings