wood burning stoves 2.0*
The moose likes Struts and the fly likes Set the value in html:select tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Set the value in html:select tag" Watch "Set the value in html:select tag" New topic
Author

Set the value in html:select tag

Achyut Behera
Greenhorn

Joined: Mar 09, 2009
Posts: 17
Hi All,

I have store the value in action class session scope.
I want to show that value in jsp drop down box.
I am using the following format.

<sLogic:iterate name="interCompanyRent" id="interCompany">
<TR>
<TD align="right"><layout:label>Rem Div:</layout:label></TD>
<TD>
<rem:select property="divisionId" value='<bean:write name="interCompany" property="divisionId"/>' onchange="retriveData(this.value)">
<htmlption value="">-- Select Division --</htmlption>
<htmlptions collection="all_division_list" property="id" labelProperty="label" />
</rem:select>
</TD>
</sLogic:iterate>

i am setting the value in the value attribute of rem:select tag.
but i am not able to set the vale.
In the loop i have adde two text box. That is working fine.

Can anybody tell me how to do that.

Thanks,
Achyut
Achyut Behera
Greenhorn

Joined: Mar 09, 2009
Posts: 17
i have checked that the value is empty means it is not able to retrive.
Can any body tell me how to set the value, if not this way any other way.

Thanks,
Achyut
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You can't nest custom tags like that. One solution would be to use the container's JSP EL if it's JSP 2+.
Achyut Behera
Greenhorn

Joined: Mar 09, 2009
Posts: 17
Can you please tell me, Using struts tag how i will set the value into drop down box.
Or Using EL how to set.

Please send me the code, so that i can do it.

Thanks,
Achyut
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm not sure what a "rem:select" tag does. If it's your own custom tag, I can't help you.

However, the html:select tag will auomatically set the selected option to the value that you specify in the property attribute. So, all you have to do is set the ActionForm bean's property to the right value, and the correct option will be displayed. For more details, see question 3 of our FAQ.


Merrill
Consultant, Sima Solutions
Achyut Behera
Greenhorn

Joined: Mar 09, 2009
Posts: 17
you are correct. but i have used property name 'divisonId' as an array in formbean class.
I am using two select box having same property name.
That' why i am not able to set in the select box.
rem:select is same as html:select.

What i am doing is, i am storing the divisonId into a bean class. and add into a list and store into the session.
in the jsp page i am going to iterate.

problem is i am not able to set the value through iterarion into the select box.

Can you please help me out.

Thanks,
Achyut
rk palleru
Greenhorn

Joined: Feb 26, 2009
Posts: 22
instead of that use logic:present

like

<html:select name="sform" property="course" styleId="course" >
<logic:present scope="session" name="alist" >
<htmlptions collection="alist" name="CourseForm"
labelName="c_name" property="c_name" labelProperty="c_name"/>
</logic:present>
</html:select>
rk palleru
Greenhorn

Joined: Feb 26, 2009
Posts: 22
try with above code . you can get the correct result
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

To use EL you can either use a JSP 2+ container (any modern app server) or the HTML EL tags:Please use code tags and disable HTML when posting code.

@rk: Your <html:select> tag doesn't include a "value" attribute, so cannot address the OP's question.
Achyut Behera
Greenhorn

Joined: Mar 09, 2009
Posts: 17
As per yours,
I have used EL tags. It is not coming.

Any other way to define.

Thanks,
Achyut
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If there's a bean stored under the "interCompany" key in app, session, request, or page scope, and it has a property called "divisionId" then either JSP EL or the EL tags will work: if it's not, then it's likely something else is wrong.
Achyut Behera
Greenhorn

Joined: Mar 09, 2009
Posts: 17
In my application i am not using JSP 2.x.

Is there any other way to set the value.

Thanks,
Achyut
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use the HTML-EL tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set the value in html:select tag
 
Similar Threads
JSP Page when submitted, List becomes empty
pass <bean:write> to a function
Need help selected text fields visible for particular option from drop down list in JSP(struts)
Show the value in select tag
Moving ArrayList of Objects from JSP to Action