p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Java > Java and JDK > JSP Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 24th, 2009, 04:39 AM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 4
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"));
	}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old March 5th, 2009, 02:40 AM
Friend of Wrox
Points: 1,108, Level: 13
Points: 1,108, Level: 13 Points: 1,108, Level: 13 Points: 1,108, Level: 13
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 363
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old March 6th, 2009, 07:16 AM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 4
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old March 24th, 2009, 01:10 AM
Friend of Wrox
Points: 1,108, Level: 13
Points: 1,108, Level: 13 Points: 1,108, Level: 13 Points: 1,108, Level: 13
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 363
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old March 28th, 2009, 06:49 AM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 4
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old March 31st, 2009, 09:55 AM
Friend of Wrox
Points: 1,108, Level: 13
Points: 1,108, Level: 13 Points: 1,108, Level: 13 Points: 1,108, Level: 13
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 363
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old July 20th, 2009, 06:49 AM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 4
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help putting xsl:value-of in select option eruditionist XSLT 2 September 25th, 2008 09:27 AM
wrap a select option nerssi HTML Code Clinic 0 June 16th, 2007 08: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 04:32 PM
Getting select option name not value mildge Javascript How-To 2 April 5th, 2004 11:20 PM



All times are GMT -4. The time now is 06:45 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc