You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jonathan Drnek <Jo...@Haworth.com> on 2006/08/22 18:40:23 UTC
select tag and value issue
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"> </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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Re: select tag and value issue
Posted by Jonathan Drnek <Jo...@Haworth.com>.
It figures I was making it too complicated.
Thanks for your help
Jon
-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
Sent: Wednesday, August 23, 2006 4:14 PM
To: user@struts.apache.org
Subject: Re: select tag and value issue
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"> </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"> </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"> </html:option>
> <html:options collection="allLicenses" property="id"
> labelProperty="name" />
> </html:select><br>
>
> I get what I expect
>
> <select name="license">
> <option value="-1"> </option>
> <option value="22">Apache Software License</option>
> <option value="42" selected="selected">asd</option>
> </select><br>
>
> Jon
>
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] 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"> </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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: select tag and value issue
Posted by Laurie Harper <la...@holoweb.net>.
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"> </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"> </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"> </html:option>
> <html:options collection="allLicenses" property="id"
> labelProperty="name" />
> </html:select><br>
>
> I get what I expect
>
> <select name="license">
> <option value="-1"> </option>
> <option value="22">Apache Software License</option>
> <option value="42" selected="selected">asd</option>
> </select><br>
>
> Jon
>
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] 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"> </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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Re: select tag and value issue
Posted by Jonathan Drnek <Jo...@Haworth.com>.
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"> </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"> </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"> </html:option>
<html:options collection="allLicenses" property="id"
labelProperty="name" />
</html:select><br>
I get what I expect
<select name="license">
<option value="-1"> </option>
<option value="22">Apache Software License</option>
<option value="42" selected="selected">asd</option>
</select><br>
Jon
-----Original Message-----
From: news [mailto:news@sea.gmane.org] 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"> </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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: select tag and value issue
Posted by Laurie Harper <la...@holoweb.net>.
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"> </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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org