If you hardcode value="42", the option with value '42' will always be selected. If you hardcode value="license", as you have below, the option with value 'license' will always be selected -- and you don't have an option with that value, so nothing is selected.

You need to *remove* the value=... attribute from the html:select tag. Struts will then use the value of the property, as you want; specifying the value attribute overrides it.

L.

Jonathan Drnek wrote:
I think I am.  I changed the JSP to also display the license id as a
text field. The JSP is
<html:form action="/updateSoftware" >
  <html:hidden  property="id"/>
  Name          <html:text  property="name" /><br>
  Location              <html:text  property="location" /><br>
  Approved              <html:checkbox property="approved"
value="true"/><br>
  License ID:   <html:text  property="license" /><br>
License <html:select property="license" value="license">
                                <html:option
value="-1">&nbsp;</html:option>
                                <html:options collection="allLicenses"
property="id" labelProperty="name" />
                        </html:select><br>
  Notes                 <html:text  property="notes" /><br>
                        <html:submit/>
</html:form>

The HTML that is outputted is
<form name="SoftwareForm" method="post"
action="/SoftwareTracker2/updateSoftware.do">
  <input type="hidden" name="id" value="1">
  Name  <input type="text" name="name" value="Apache Web Server"><br>
  Location      <input type="text" name="location" value="loc2"><br>
  Approved      <input type="checkbox" name="approved" value="true"><br>

  License ID: <input type="text" name="license" value="42"><br>
License <select name="license">
        <option value="-1">&nbsp;</option>
        <option value="22">Apache Software License</option>
        <option value="42">asd</option>
    </select><br>
  Notes <input type="text" name="notes" value=" "><br>
<input type="submit" value="Submit">
</form>

As you can see, the license id has a value of 42.  There is an option
with a value of 42 that is not selected.  If I hard code the 42 so I
have JSP that looks like

<html:select property="license" value="42">
    <html:option value="-1">&nbsp;</html:option>
    <html:options collection="allLicenses" property="id"
labelProperty="name" />
</html:select><br>

I get what I expect

<select name="license">
        <option value="-1">&nbsp;</option>
        <option value="22">Apache Software License</option>
        <option value="42" selected="selected">asd</option>
</select><br>

Jon

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Laurie Harper
Sent: Tuesday, August 22, 2006 4:53 PM
To: user@struts.apache.org
Subject: Re: select tag and value issue

Your JSP code looks OK (except obviously you want to remove the value="22" from the html:select tag). Are you sure the value you're setting in form.license is correct?

L.

Jonathan Drnek wrote:
I'm fairly new to struts and am having a problem with the
<html:select>
tag. I can't get the value property to work correctly.  I have a list
of
licenses that I want displayed in the drop down box.  I want the
license
that is used by the current software to be selected.
If I hard code the value property to be 22 for example, the license
that
has 22 for its key is selected.  It seems like I should be able to use
the license property in my SoftwareForm bean for the value but that
does
not work.  When I do that, nothing ends up being selected.

My JSP page looks like
<html:form action="/updateSoftware" >
  <html:hidden  property="id"/>
  Name <html:text  property="name" /><br>
  Location <html:text  property="location" /><br>
  Approved <html:checkbox property="approved" value="true"/><br>
License <html:select property="license" value="22">
    <html:option value="-1">&nbsp;</html:option>
    <html:options collection="allLicenses" property="id"
labelProperty="name" />
    </html:select><br>
  Notes <html:text  property="notes" /><br>
<html:submit/>
</html:form>

My action mapping looks like.

                <action name="SoftwareForm" path="/updateSoftware"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy"
input="/EditSoftware.jsp">
                        <forward name="success"
path="/loadAllSoftware.do">
                        </forward>
                        <forward name="Failure"
path="/EditSoftware.jsp">
                        </forward>
                </action>

As you can see I am using spring.
My SoftwareForm bean contains the String properties you would expect.

In the action that forwards to the above form I have the following
code
            Software s = softwareDAO.get(Long.decode(id));
            Iterator i = licenseDAO.getAllLicenses();
SoftwareForm sForm = new SoftwareForm();
            sForm.setApproved(Boolean.toString(s.isApproved()));
            sForm.setId(s.getId().toString());
            sForm.setLicense(s.getLicense().getId().toString());
            sForm.setLocation(s.getLocation());
            sForm.setName(s.getName());
            sForm.setNotes(s.getNotes());
request.setAttribute("SoftwareForm",sForm);
            request.setAttribute("allLicenses",i);

This seems like it should be a fairly simple thing to do.  What am I
missing?

Jon


---------------------------------------------------------------------
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