|
|
 |
| 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.
|
 |

February 24th, 2009, 04:39 AM
|
|
Registered User
|
|
Join Date: Feb 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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"));
}
|

March 5th, 2009, 02:40 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

March 6th, 2009, 07:16 AM
|
|
Registered User
|
|
Join Date: Feb 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

March 24th, 2009, 01:10 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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"));
}
|

March 28th, 2009, 06:49 AM
|
|
Registered User
|
|
Join Date: Feb 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

March 31st, 2009, 09:55 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Cool :-)
Quote:
|
Hope u can still help me with my other future concern.
|
Sure.
|

July 20th, 2009, 06:49 AM
|
|
Registered User
|
|
Join Date: Feb 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |