Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2009, 04:39 AM
Registered User
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Double display of html:select option

Hello Everyone:

I am a neophyte JSP programmer. I create a small web application
inorder to enhance my programming skills. Although, this web application
is running but I encounter a problem in the html:select tags.

There are only two options in my html:select tag(admin and ordinary) but
during the browser display the options will double.

Pls. help.

CESAR V.

Below is my jsp code.


Code:
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html>
<head>
<title>SPC WF System</title>
<style type="text/css">
<!--
.style1 {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 14px;
}
.style2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; }
-->
</style>
</head>
<html:form action="/dispatchfromMaintConfirm">
<body>
<table border="0" width="600">
    <%-- Error Display --%>
    <tr><td><font color="red"><html:errors/></font></td></tr>
  <tr>
    <td align="center"><h2><bean:message key="prompt.maint.title"/></td>
  </tr>
  <tr>
    <td align="center">
      <bean:message key="prompt.maint.input"/>
      <br>
    </td>
  </tr>
  <tr>
    <td align="center">
      <table border="1">
        <tr>
          <th>EMP ID</th>
          <td><html:text name="loginForm" property="emp_id" maxlength="10"/></td>
        </tr>
        <tr>
          <th>LastName</th>
          <td><html:text name="loginForm" property="lname" maxlength="30"/></td>
        </tr>
        <tr>
          <th>FirstName</th>
          <td><html:text name="loginForm" property="fname" maxlength="30"/></td>
        </tr>
        <tr>
          <th>MI</th>
          <td><html:text name="loginForm" property="mi" maxlength="30"/></td>
        </tr>
        <tr>
          <th>Username</th>
          <td><html:text name="loginForm" property="username" maxlength="20"/></td>
        </tr>
        <tr>
          <th>Permission</th>
          <%--<td><html:text name="loginForm" property="permission"
size="10"/></td>--%>
        
                  <bean:define id="list" name="loginForm" property="comboList"
type="java.util.ArrayList"/>
                        <td><html:select property="permission" name="loginForm">
                                        <html:options collection="list" property="label" labelProperty="label"/>
                                </html:select>
            </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td align="center">
            <html:submit property="action"><bean:message key="button.submit"/></html:submit>
                <html:submit property="action"><bean:message key="button.back"/></html:submit>
    </td>
  </tr>
</table>
</body>
</html:form>
</html:html>
A portion of my action form class:
Code:
public ArrayList getComboList() {
		return comboList;
	}

	/**
	 * @param comboList the comboList to set
	 */
	public void setComboList(ArrayList comboList) {
		this.comboList = comboList;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public void reset(ActionMapping mapping, 
			HttpServletRequest request) {
		// TODO Auto-generated method stub
		//super.reset(arg0, arg1);
		comboList.add(new LabelValueBean("admin","admin"));
		comboList.add(new LabelValueBean("ordinary","ordinary"));
	}
 
Old March 5th, 2009, 02:40 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

reset() method will be called twise
1. When the form bean is created first time
2. When the form is submitted [before calling setters].

You can try creating new list in reset instead of just adding to existing list. And you might not need the setter for the property "comboList"!

Hope that solves your problem.
__________________
- Rakesh
http://iam-rakesh.blogspot.com
 
Old March 6th, 2009, 07:16 AM
Registered User
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Double display of html:select option

rakesh_mscit:

Thanks a lot and II really appreciate your response.

I tried to review my code and I noticed that my Action form class extends from Validator form not from ActionForm. I tried to correct it but still didn't work.

If I may ask, where am I going to call my reset method? In the ActionForm class or in Action class?

Hope u response my concern. Again, thanks a lot.

cesarv
 
Old March 24th, 2009, 12:10 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry for the delayed reply!

You dont need to call reset() method, it is called by struts framework. You can try updating your reset() method like the below mentioned one
Code:
public void reset(ActionMapping mapping, HttpServletRequest request) {
        comboList = new ArrayList();
        comboList.add(new LabelValueBean("admin","admin"));
        comboList.add(new LabelValueBean("ordinary","ordinary"));
}
__________________
- Rakesh
http://iam-rakesh.blogspot.com
 
Old March 28th, 2009, 05:49 AM
Registered User
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Double display of html:select option

rakesh_mscit:

The last code you were suggested works.

Thanks a lot, now I can proceed with my coding and design. Hope u can still help me with my other future concern.

Again, thank you very much.

cesarv
 
Old March 31st, 2009, 08:55 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Cool :-)
Quote:
Hope u can still help me with my other future concern.
Sure.
__________________
- Rakesh
http://iam-rakesh.blogspot.com
 
Old July 20th, 2009, 05:49 AM
Registered User
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to use html:select tags in dynamic display

Hi rakesh_mscit or anyone:

Can you please help me how to use html:select tags in displaying dynamic data, I mean data that I created from the database?

Regards,

cesarv





Similar Threads
Thread Thread Starter Forum Replies Last Post
need help putting xsl:value-of in select option eruditionist XSLT 2 September 25th, 2008 08:27 AM
wrap a select option nerssi HTML Code Clinic 0 June 16th, 2007 07:43 AM
disable Select option Dj Kat HTML Code Clinic 2 March 10th, 2006 04:03 AM
Select/Option Problem TSEROOGY Javascript 2 October 4th, 2004 03:32 PM
Getting select option name not value mildge Javascript How-To 2 April 5th, 2004 10:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.