set proprty as value of another property
my datacollector bean has refrenc of type data with 4 different properties
<jsp:useBean id="data" class="com.custom.util.DataCollector" scope="request"/>
<c:set target="${data}" property="IP1" value="${param.subnet1}" />
<c:set target="${data}" property="IP2" value="${param.subnet2}" />
<c:set target="${data}" property="IP3" value="${param.subnet3}" />
<c:set target="${data}" property="IP4" value="${param.subnet4}" />
now i want to set the data as property of another refernce. I tried this way
<jsp:useBean id="saved" class="com.custom.util.SaveData" scope="request"/>
<c:set target="${saved}" property="DataSafe" value="${data}" />
my SaveData class
package com.custom.util;
import java.util.*;
import java.io.*;
publicclass SaveDataimplements Serializable{
ObjectOutputStream dos;
int ip1;
int ip2;
int ip3;
int ip4;
public SaveData(){
}
publicvoid setIP1(int ip1){
this.ip1 = ip1;
}
publicvoid setIP2(int ip2){
this.ip2 = ip2;
}
publicvoid setIP3(int ip3){
this.ip3 = ip3;
}
publicvoid setIP4(int ip3){
this.ip3 = ip3;
}
publicvoid setDataSafe(SaveData sd)throws FileNotFoundException, IOException{
dos =new ObjectOutputStream(new FileOutputStream("data.txt"));
dos.writeObject(sd);
dos.flush();
}
}
and my DataCollector class
package com.custom.util;
import java.util.*;
import java.io.*;
publicclass DataCollectorimplements Serializable{
TreeMap dataMap =new TreeMap();
int ip1;
int ip2;
int ip3;
int ip4;
public DataCollector(){
}
publicvoid setIP1(int ip1){
this.ip1 = ip1;
}
publicvoid setIP2(int ip2){
this.ip2 = ip2;
}
publicvoid setIP3(int ip3){
this.ip3 = ip3;
}
publicvoid setIP4(int ip4){
this.ip4 = ip4;
}
}
and i got illegalargumentexception
please help..
[5076 byte] By [
rajitoora] at [2007-11-27 8:03:36]

# 1
Your property should start with a lowercase letter. ie DataSafe -> dataSafe.
<c:set target="${saved}" property="dataSafe" value="${data}" />
The IP_ properties remain with the first letter uppercase, because the second letter is upper case as well. See the method java.beans.Introspector decapitalize() at
http://java.sun.com/j2se/1.5.0/docs/api/java/beans/Introspector.html
for the rules on how it treats it.
If that doesn't solve it, please post the full exception you are getting.
# 2
from ehat i could understand from the method is that my code should be like this
<jsp:useBean id="data" class="com.custom.util.DataCollector" scope="request"/>
<c:set target="${data}" property="IP1" value="${param.subnet1}" />
<c:set target="${data}" property="IP2" value="${param.subnet2}" />
<c:set target="${data}" property="IP3" value="${param.subnet3}" />
<c:set target="${data}" property="IP4" value="${param.subnet4}" />
<jsp:useBean id="saved" class="com.custom.util.SaveData" scope="request"/>
<c:set target="${saved}" property="dataSafe" value="${data}" />
and exception i m getting because of this
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
root cause
java.lang.IllegalArgumentException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(SetSupport.java:154)
org.apache.jsp.basics1.Saved_jsp._jspx_meth_c_set_0(Saved_jsp.java:139)
org.apache.jsp.basics1.Saved_jsp._jspService(Saved_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
# 4
i have been able to reach the exact cause and here it is
<jsp:useBean id="data" class="com.custom.util.DataCollector" scope="request"/>
<c:set target="${data}" property="IP1" value="${param.subnet1}" />
<c:set target="${data}" property="IP2" value="${param.subnet2}" />
<c:set target="${data}" property="IP3" value="${param.subnet3}" />
<c:set target="${data}" property="IP4" value="${param.subnet4}" />
${param.subnet1} was not compatible with setter methods
public void setIP1(int ip1){
this.ip1 = ip1;
}
as they were int datatypes. as i changed them to String app worked.
Now the problem is i want to manipulate them as int's not strings what should i do.
# 5
Hi,
Everything you have written is correct except one small mistake.
While passing the property parameter to the <c:set> tag u need to pass the iP1,iP2, and iP3 because the internal code of the <c:set> will capitalize the first letter and uses the methods setIP1(), setIP2(), and setIP3() to set the values.
Just try by passing the iP1, iP2, and iP3 values to <c:set>
If you have any queries let me know... or send a mail to doubtsplz@gmail.com
Bye....
Thanks & Regards,
Santhosh Reddy Mandadi.