You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Leung Ping Cheung <pc...@gmail.com> on 2005/12/08 09:55:43 UTC

prepopulating a dropdown box in a struts way.

I think there are many people asking the same question. But I cannot
find the answer. any web sites have more or less coding example of 
populating a dropdown box or list in a Struts way before the web page
displays.

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: prepopulating a dropdown box in a struts way.

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Ah, in the "modern" world of AJAX and the like, enclosing forms many times
are no longer much use.  I wouldn't say it does much harm to still do it
in most cases, it just becomes somewhat superfluous.

Maybe you have a <select> who's purpose is to change the contents of a
<div> by firing off an AJAX event.  No form to submit, so there isn't much
benefit to having that <select> in a form.  But again, probably not much
harm in most cases.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

On Mon, December 12, 2005 3:46 pm, Laurie Harper said:
> The documentation for html:select states that, 'This tag is only valid
> when nested inside a form tag body.' It *might* work without an
> enclosing html:form tag, but you would need to tell the
> html:optionsCollection tag where to lookup the 'system_href' property.
> Try adding name="availableSystem" to the html:optionsCollection tag.
>
> I'm not sure why you're using html:select / html:optionsCollection
> without an enclosing form in the first place, though. What use is a
> select list outside a form?
>
> L.
>
> Leung Ping Cheung wrote:
>> Should the jsp be tied to a form for this case?
>>
>> I do not make up a form.
>> I do this in the jsp.
>> <%
>>   List availableSystemList =
>> UserSystemService.getInstance().getAvailableSystemList(request.getRemoteUser());
>>   request.setAttribute("availableSystem", availableSystemList);
>> %>
>>
>> <html:select property="availableSystem">
>>        <html:optionsCollection property="system_href"/>
>> </html:select>
>>
>> where system_href is one of the attributes of availableSystem.
>>
>> I get the error message of
>>
>> ERROR - Servlet.service() for servlet jsp threw exception
>> javax.servlet.jsp.JspException: Cannot find bean under name
>> org.apache.struts.taglib.html.BEAN
>> 	at
>> org.apache.struts.taglib.html.SelectTag.calculateMatchValues(SelectTag.java:240)
>> 	at
>> org.apache.struts.taglib.html.SelectTag.doStartTag(SelectTag.java:200)
>> 	at
>> org.apache.jsp.user.assignUserSystem_jsp._jspx_meth_html_select_0(org.apache.jsp.user.assignUserSystem_jsp:123)
>> 	at
>> org.apache.jsp.user.assignUserSystem_jsp._jspService(org.apache.jsp.user.assignUserSystem_jsp:82)
>> 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
>>
>>
>>
>> On 12/8/05, Keith Sader <ks...@gmail.com> wrote:
>>> You need to make use of the html:optionsCollection tag
>>>
>>> <html:select property="yearOfManufacture">
>>>        <html:optionsCollection property="years"/>
>>> </html:select>
>>>
>>> In your form bean you need an object that has the properties label and
>>> value.  Like this:
>>>
>>> public class ComboBoxItem implements Serializable, Comparable {
>>>        private String label;
>>>        private String value;
>>>
>>>        // This is the contract for html:optionsCollection, label is
>>> what is
>>>        // displayed on the form, and value is the code behind it.
>>>        public ComboBoxItem(String label, String value) {
>>>                this.label = label;
>>>                this.value = value;
>>>        }
>>>
>>>        public String getLabel() {
>>>                return label;
>>>        }
>>>        public String getValue() {
>>>                return value;
>>>        }
>>>
>>>        public int compareTo(Object o) {...}
>>>
>>> Then, in your populate action, you'll set a Collection<ComboBoxItem>
>>> on the form.  That should to it.
>>>
>>> On 12/8/05, Leung Ping Cheung <pc...@gmail.com> wrote:
>>>> I think there are many people asking the same question. But I cannot
>>>> find the answer. any web sites have more or less coding example of
>>>> populating a dropdown box or list in a Struts way before the web page
>>>> displays.
>>>>
>>>> Thanks
>>>>
>>>
>>> --
>>> Keith Sader
>>> ksader@gmail.com
>>> http://www.saderfamily.org/roller/page/ksader
>>> http://www.jroller.com/page/certifieddanger
>>>
>>> ---------------------------------------------------------------------
>>> 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: prepopulating a dropdown box in a struts way.

Posted by Laurie Harper <la...@holoweb.net>.
The documentation for html:select states that, 'This tag is only valid 
when nested inside a form tag body.' It *might* work without an 
enclosing html:form tag, but you would need to tell the 
html:optionsCollection tag where to lookup the 'system_href' property. 
Try adding name="availableSystem" to the html:optionsCollection tag.

I'm not sure why you're using html:select / html:optionsCollection 
without an enclosing form in the first place, though. What use is a 
select list outside a form?

L.

Leung Ping Cheung wrote:
> Should the jsp be tied to a form for this case?
> 
> I do not make up a form.
> I do this in the jsp.
> <%
>   List availableSystemList =
> UserSystemService.getInstance().getAvailableSystemList(request.getRemoteUser());
>   request.setAttribute("availableSystem", availableSystemList);
> %>
> 
> <html:select property="availableSystem">
>        <html:optionsCollection property="system_href"/>
> </html:select>
> 
> where system_href is one of the attributes of availableSystem.
> 
> I get the error message of
> 
> ERROR - Servlet.service() for servlet jsp threw exception
> javax.servlet.jsp.JspException: Cannot find bean under name
> org.apache.struts.taglib.html.BEAN
> 	at org.apache.struts.taglib.html.SelectTag.calculateMatchValues(SelectTag.java:240)
> 	at org.apache.struts.taglib.html.SelectTag.doStartTag(SelectTag.java:200)
> 	at org.apache.jsp.user.assignUserSystem_jsp._jspx_meth_html_select_0(org.apache.jsp.user.assignUserSystem_jsp:123)
> 	at org.apache.jsp.user.assignUserSystem_jsp._jspService(org.apache.jsp.user.assignUserSystem_jsp:82)
> 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
> 
> 
> 
> On 12/8/05, Keith Sader <ks...@gmail.com> wrote:
>> You need to make use of the html:optionsCollection tag
>>
>> <html:select property="yearOfManufacture">
>>        <html:optionsCollection property="years"/>
>> </html:select>
>>
>> In your form bean you need an object that has the properties label and
>> value.  Like this:
>>
>> public class ComboBoxItem implements Serializable, Comparable {
>>        private String label;
>>        private String value;
>>
>>        // This is the contract for html:optionsCollection, label is what is
>>        // displayed on the form, and value is the code behind it.
>>        public ComboBoxItem(String label, String value) {
>>                this.label = label;
>>                this.value = value;
>>        }
>>
>>        public String getLabel() {
>>                return label;
>>        }
>>        public String getValue() {
>>                return value;
>>        }
>>
>>        public int compareTo(Object o) {...}
>>
>> Then, in your populate action, you'll set a Collection<ComboBoxItem>
>> on the form.  That should to it.
>>
>> On 12/8/05, Leung Ping Cheung <pc...@gmail.com> wrote:
>>> I think there are many people asking the same question. But I cannot
>>> find the answer. any web sites have more or less coding example of
>>> populating a dropdown box or list in a Struts way before the web page
>>> displays.
>>>
>>> Thanks
>>>
>>
>> --
>> Keith Sader
>> ksader@gmail.com
>> http://www.saderfamily.org/roller/page/ksader
>> http://www.jroller.com/page/certifieddanger
>>
>> ---------------------------------------------------------------------
>> 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: prepopulating a dropdown box _in_a_struts_way_.

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
There are also limitless ways in struts of instantiating the lists of 
beans or values for dropdowns.

In my experience the only factors involved in making a list available to 
a JSP taglib are: (1) which list is needed (2) what parameters are 
required to constrain the list and (3) how long it should be cached for.

I think this is widely known as 'view logic' - and there's a whole heap 
of functionality coming up in future versions of struts to help on the 
view logic front, I believe. Since I am currently in retro-mode working 
with 1.1 at my current job, I'm not sure what version brings view logic 
- anyone?

I envisage at some point a view logic component that integrates with the 
taglibs and some config xml to allow struts developers to set up 
dropdown lists without mixing it in their actions, with declared cache 
levels (application / session / request scope), automatic i18n with 
substitution of resource strings, and stuff like that. Does this match 
anyone else's plans?




Keith Sader on 12/12/05 18:35, wrote:
> Mine are, because I do submits off of those pages.  If you use a form,
> then the scriptlet logic you have can go into the action and you don't
> have that messy java code in your jsp.
> 
> On 12/12/05, Leung Ping Cheung <pc...@gmail.com> wrote:
> 
>>Should the jsp be tied to a form for this case?
>>
>>I do not make up a form.
>>I do this in the jsp.
>><%
>>  List availableSystemList =
>>UserSystemService.getInstance().getAvailableSystemList(request.getRemoteUser());
>>  request.setAttribute("availableSystem", availableSystemList);
>>%>
>>
>><html:select property="availableSystem">
>>       <html:optionsCollection property="system_href"/>
>></html:select>
>>
>>where system_href is one of the attributes of availableSystem.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: prepopulating a dropdown box in a struts way.

Posted by Keith Sader <ks...@gmail.com>.
Mine are, because I do submits off of those pages.  If you use a form,
then the scriptlet logic you have can go into the action and you don't
have that messy java code in your jsp.

On 12/12/05, Leung Ping Cheung <pc...@gmail.com> wrote:
> Should the jsp be tied to a form for this case?
>
> I do not make up a form.
> I do this in the jsp.
> <%
>   List availableSystemList =
> UserSystemService.getInstance().getAvailableSystemList(request.getRemoteUser());
>   request.setAttribute("availableSystem", availableSystemList);
> %>
>
> <html:select property="availableSystem">
>        <html:optionsCollection property="system_href"/>
> </html:select>
>
> where system_href is one of the attributes of availableSystem.


--
Keith Sader
ksader@gmail.com
http://www.saderfamily.org/roller/page/ksader
http://www.jroller.com/page/certifieddanger

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: prepopulating a dropdown box in a struts way.

Posted by Leung Ping Cheung <pc...@gmail.com>.
Should the jsp be tied to a form for this case?

I do not make up a form.
I do this in the jsp.
<%
  List availableSystemList =
UserSystemService.getInstance().getAvailableSystemList(request.getRemoteUser());
  request.setAttribute("availableSystem", availableSystemList);
%>

<html:select property="availableSystem">
       <html:optionsCollection property="system_href"/>
</html:select>

where system_href is one of the attributes of availableSystem.

I get the error message of

ERROR - Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Cannot find bean under name
org.apache.struts.taglib.html.BEAN
	at org.apache.struts.taglib.html.SelectTag.calculateMatchValues(SelectTag.java:240)
	at org.apache.struts.taglib.html.SelectTag.doStartTag(SelectTag.java:200)
	at org.apache.jsp.user.assignUserSystem_jsp._jspx_meth_html_select_0(org.apache.jsp.user.assignUserSystem_jsp:123)
	at org.apache.jsp.user.assignUserSystem_jsp._jspService(org.apache.jsp.user.assignUserSystem_jsp:82)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)



On 12/8/05, Keith Sader <ks...@gmail.com> wrote:
> You need to make use of the html:optionsCollection tag
>
> <html:select property="yearOfManufacture">
>        <html:optionsCollection property="years"/>
> </html:select>
>
> In your form bean you need an object that has the properties label and
> value.  Like this:
>
> public class ComboBoxItem implements Serializable, Comparable {
>        private String label;
>        private String value;
>
>        // This is the contract for html:optionsCollection, label is what is
>        // displayed on the form, and value is the code behind it.
>        public ComboBoxItem(String label, String value) {
>                this.label = label;
>                this.value = value;
>        }
>
>        public String getLabel() {
>                return label;
>        }
>        public String getValue() {
>                return value;
>        }
>
>        public int compareTo(Object o) {...}
>
> Then, in your populate action, you'll set a Collection<ComboBoxItem>
> on the form.  That should to it.
>
> On 12/8/05, Leung Ping Cheung <pc...@gmail.com> wrote:
> > I think there are many people asking the same question. But I cannot
> > find the answer. any web sites have more or less coding example of
> > populating a dropdown box or list in a Struts way before the web page
> > displays.
> >
> > Thanks
> >
>
>
> --
> Keith Sader
> ksader@gmail.com
> http://www.saderfamily.org/roller/page/ksader
> http://www.jroller.com/page/certifieddanger
>
> ---------------------------------------------------------------------
> 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: prepopulating a dropdown box in a struts way.

Posted by Keith Sader <ks...@gmail.com>.
You need to make use of the html:optionsCollection tag

<html:select property="yearOfManufacture">
	<html:optionsCollection property="years"/>
</html:select>

In your form bean you need an object that has the properties label and
value.  Like this:

public class ComboBoxItem implements Serializable, Comparable {
	private String label;
	private String value;
	
	// This is the contract for html:optionsCollection, label is what is
	// displayed on the form, and value is the code behind it.
	public ComboBoxItem(String label, String value) {
		this.label = label;
		this.value = value;
	}
	
	public String getLabel() {
		return label;
	}
	public String getValue() {
		return value;
	}

	public int compareTo(Object o) {...}

Then, in your populate action, you'll set a Collection<ComboBoxItem>
on the form.  That should to it.

On 12/8/05, Leung Ping Cheung <pc...@gmail.com> wrote:
> I think there are many people asking the same question. But I cannot
> find the answer. any web sites have more or less coding example of
> populating a dropdown box or list in a Struts way before the web page
> displays.
>
> Thanks
>


--
Keith Sader
ksader@gmail.com
http://www.saderfamily.org/roller/page/ksader
http://www.jroller.com/page/certifieddanger

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org