You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "White, Susan" <Su...@troweprice.com> on 2004/01/02 21:10:30 UTC

Indexed Property in JSP

The form is not setting the value that the user inputs.  I used some of
the posts from this list to create this code and everything compiles,
throws no exceptions but does not work, either. The setter(s) is(are)
not being called Any ideas? 
PS The indexed='true' parameter seems to have no effect present or
absent. 
Thanks! Susan

JSP:
<logic:iterate id="thisParty" name="acctParties" indexId="idx">
	<tr valign="bottom">
		<td align="left" valign="top" class="dkBlue11b"
colspan="2">
		      Please enter the date of birth for
		      <bean:write name="thisParty"
property="firstName"/>&nbsp;
		      <logic:notEmpty name="thisParty"
property="middleName">
 		        <bean:write name="thisParty"
property="middleName"/>&nbsp;
		      </logic:notEmpty>
 		      <bean:write name="thisParty"
property="lastName"/>&nbsp;(MM/DD/YYYY)
		</td>
	</tr>
	<tr>
		<td colspan="2">
		      <html:text property='<%= "dateOfBirth[" + idx +
"]" %>' indexed='true'/>			
	   	</td>
	</tr>    
</logic:iterate>

Java:
    private String[] dateOfBirth=null;

	/**
	 * Returns the dateOfBirth by index.
	 * @param int index of array
	 * @return String date of birth value
	 */
	public String getDateOfBirth(int idx) {
		if (this.dateOfBirth==null) {
        		return new String("");
     		} 
     		else {
			if (idx < this.dateOfBirth.length) {
	        		return this.dateOfBirth[idx];
	 		} 
	     		else {
	        		return new String("");
	     		}
     		}
	}

	/**
	 * Sets the dateOfBirth.
	 * @param dateOfBirth The dateOfBirth to set
	 * @param idx The position of dateOfBirth to set
	 */
	public void setDateOfBirth(String dateOfBirth, int idx) {
		this.dateOfBirth[idx] = dateOfBirth;
	}

	/**
	 * Sets the dateOfBirth.
	 * @param dateOfBirth The dateOfBirth to set
	 * @param idx The position of dateOfBirth to set
	 */
	public void setDateOfBirth(String[] dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}
	/**
	 * Returns the dateOfBirth array.
	 * @return String array
	 */
	public String[] getDateOfBirth() {
         return dateOfBirth;
	}



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


Re: Indexed Property in JSP

Posted by Kris Schneider <kr...@dotech.com>.
One quick comment - the JavaBean spec defines the 2-arg setter as taking 
an int as the first arg:

public void setDateOfBirth(int idx, String dateOfBirth)

White, Susan wrote:
> The form is not setting the value that the user inputs.  I used some of
> the posts from this list to create this code and everything compiles,
> throws no exceptions but does not work, either. The setter(s) is(are)
> not being called Any ideas? 
> PS The indexed='true' parameter seems to have no effect present or
> absent. 
> Thanks! Susan
> 
> JSP:
> <logic:iterate id="thisParty" name="acctParties" indexId="idx">
> 	<tr valign="bottom">
> 		<td align="left" valign="top" class="dkBlue11b"
> colspan="2">
> 		      Please enter the date of birth for
> 		      <bean:write name="thisParty"
> property="firstName"/>&nbsp;
> 		      <logic:notEmpty name="thisParty"
> property="middleName">
>  		        <bean:write name="thisParty"
> property="middleName"/>&nbsp;
> 		      </logic:notEmpty>
>  		      <bean:write name="thisParty"
> property="lastName"/>&nbsp;(MM/DD/YYYY)
> 		</td>
> 	</tr>
> 	<tr>
> 		<td colspan="2">
> 		      <html:text property='<%= "dateOfBirth[" + idx +
> "]" %>' indexed='true'/>			
> 	   	</td>
> 	</tr>    
> </logic:iterate>
> 
> Java:
>     private String[] dateOfBirth=null;
> 
> 	/**
> 	 * Returns the dateOfBirth by index.
> 	 * @param int index of array
> 	 * @return String date of birth value
> 	 */
> 	public String getDateOfBirth(int idx) {
> 		if (this.dateOfBirth==null) {
>         		return new String("");
>      		} 
>      		else {
> 			if (idx < this.dateOfBirth.length) {
> 	        		return this.dateOfBirth[idx];
> 	 		} 
> 	     		else {
> 	        		return new String("");
> 	     		}
>      		}
> 	}
> 
> 	/**
> 	 * Sets the dateOfBirth.
> 	 * @param dateOfBirth The dateOfBirth to set
> 	 * @param idx The position of dateOfBirth to set
> 	 */
> 	public void setDateOfBirth(String dateOfBirth, int idx) {
> 		this.dateOfBirth[idx] = dateOfBirth;
> 	}
> 
> 	/**
> 	 * Sets the dateOfBirth.
> 	 * @param dateOfBirth The dateOfBirth to set
> 	 * @param idx The position of dateOfBirth to set
> 	 */
> 	public void setDateOfBirth(String[] dateOfBirth) {
> 		this.dateOfBirth = dateOfBirth;
> 	}
> 	/**
> 	 * Returns the dateOfBirth array.
> 	 * @return String array
> 	 */
> 	public String[] getDateOfBirth() {
>          return dateOfBirth;
> 	}

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>



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