| | |
How to get Array type members' value from a class
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2006
Posts: 4
Reputation:
Solved Threads: 0
Hi friends.
i'm having problem to get values of a class member variable which itself is a class and resides inside another class as an array.
Parent class is CA. its one of the member is CB[] class.
my problem was to get values of CB class.
following is the dedtails of my code.
i was using weblogic workshop 8.1, using JSP, NETUI-tag, JPF.
please help me out -- how to get CB's value from CA class in action method.
thanks in advance.
[ if you need any more infos, please ask me for that.]
/******* class CA **********/
public class CA FormData
{
private String AID;
private String AName;
public CB[] cb;
public void setAID (String value) { this.AID= value;}
public void setAName (String value) { this.AName= value;}
public void setCB (CB[] value) { this.cb= value;}
public String getAID (){ return this.AID;}
public String getAName (){ return this.AName;}
public CB[] getCB (){ return this.cb;}
}
/********* Class CB ***********/
public class CB implements Serializable
{
private String BID;
private String BText;
private boolean select;
public void setSelect(boolean value){this.select = value;}
public void setBID (String value) { this.BID= value;}
public void setBText (String value) { this.BText= value;}
public String getBID (){ return this.BID;}
public String getBText (){ return this.BText;}
public boolean isSelect(){return this.select;}
}
/****** pageA.jsp *********/
<netui:form action="CreateTest">
<table>
<tr>
<td colspan="2">Create Tests</td>
</tr>
<tr>
<td>Name</td>
<td><netui:textBox dataSource="{actionForm.AName}" /></td>
</tr>
<tr>
<td colspan="2"> Select CBs</td>
</tr>
<tr>
<td colspan="2">
<netui-data:repeater dataSource="{actionForm.cb}">
<netui-data:repeaterItem>
<tr>
<td><netui:hidden dataSource="{container.item.BID}" />
<netui:checkBox tagId="chb" dataSource="{container.item.select}" /></td>
<td><netui:label value="{container.item.BText}" /></td>
</tr>
</netui-data:repeaterItem>
</netui-data:repeater>
</td>
</tr>
<tr>
<td><netui:button value="Create">Save</netui:button></td>
</tr>
</table>
</netui:form>
/******************************************************/
/**************** pageController.jpf *********************/
public class PageController extends PageFlowController
{
/**
* @common:control
*/
private DBControl dbControl;
/**
* @jpf:action
* @jpf:forward name="create" path="PageA.jsp"
*/
protected Forward goPageA()
{
CAeForm = new CA();
CB[] cb= dbControl.getCBs();
eForm.setCB(cb);
return new Forward("create",eForm);
}
/**
* @jpf:action
* @jpf:forward name="success" path="Default.jsp"
*/
protected Forward CreateTest(CA eForm)
{
eForm.cb= dbControl.getCBs();
String AID = null;
try
{
dbControl.insertCA(eForm.getAName());
AID = dbControl.getExamID(eForm.getAName());
String CBID = null;
for(int i=0; i<eForm.cb.length; i++)
/**** GOT NULLPOINTEREXCEPTION AS "eForm.cb" IS GIVING null RETURN !! ****/
{
if(eForm.cb[i].isSelect())
{
CBID = eForm.cb[i].getBID();
try
{
dbControl.insertCBInA(AID,CBID);
}
catch(SQLException e){String msg = e.getMessage();}
}
}
}
catch(SQLException e){String msg = e.getMessage();}
/******** INSERTION COMPLETE *****************/
return new Forward("success",eForm);
}
i'm having problem to get values of a class member variable which itself is a class and resides inside another class as an array.
Parent class is CA. its one of the member is CB[] class.
my problem was to get values of CB class.
following is the dedtails of my code.
i was using weblogic workshop 8.1, using JSP, NETUI-tag, JPF.
please help me out -- how to get CB's value from CA class in action method.
thanks in advance.
[ if you need any more infos, please ask me for that.]
/******* class CA **********/
public class CA FormData
{
private String AID;
private String AName;
public CB[] cb;
public void setAID (String value) { this.AID= value;}
public void setAName (String value) { this.AName= value;}
public void setCB (CB[] value) { this.cb= value;}
public String getAID (){ return this.AID;}
public String getAName (){ return this.AName;}
public CB[] getCB (){ return this.cb;}
}
/********* Class CB ***********/
public class CB implements Serializable
{
private String BID;
private String BText;
private boolean select;
public void setSelect(boolean value){this.select = value;}
public void setBID (String value) { this.BID= value;}
public void setBText (String value) { this.BText= value;}
public String getBID (){ return this.BID;}
public String getBText (){ return this.BText;}
public boolean isSelect(){return this.select;}
}
/****** pageA.jsp *********/
<netui:form action="CreateTest">
<table>
<tr>
<td colspan="2">Create Tests</td>
</tr>
<tr>
<td>Name</td>
<td><netui:textBox dataSource="{actionForm.AName}" /></td>
</tr>
<tr>
<td colspan="2"> Select CBs</td>
</tr>
<tr>
<td colspan="2">
<netui-data:repeater dataSource="{actionForm.cb}">
<netui-data:repeaterItem>
<tr>
<td><netui:hidden dataSource="{container.item.BID}" />
<netui:checkBox tagId="chb" dataSource="{container.item.select}" /></td>
<td><netui:label value="{container.item.BText}" /></td>
</tr>
</netui-data:repeaterItem>
</netui-data:repeater>
</td>
</tr>
<tr>
<td><netui:button value="Create">Save</netui:button></td>
</tr>
</table>
</netui:form>
/******************************************************/
/**************** pageController.jpf *********************/
public class PageController extends PageFlowController
{
/**
* @common:control
*/
private DBControl dbControl;
/**
* @jpf:action
* @jpf:forward name="create" path="PageA.jsp"
*/
protected Forward goPageA()
{
CAeForm = new CA();
CB[] cb= dbControl.getCBs();
eForm.setCB(cb);
return new Forward("create",eForm);
}
/**
* @jpf:action
* @jpf:forward name="success" path="Default.jsp"
*/
protected Forward CreateTest(CA eForm)
{
eForm.cb= dbControl.getCBs();
String AID = null;
try
{
dbControl.insertCA(eForm.getAName());
AID = dbControl.getExamID(eForm.getAName());
String CBID = null;
for(int i=0; i<eForm.cb.length; i++)
/**** GOT NULLPOINTEREXCEPTION AS "eForm.cb" IS GIVING null RETURN !! ****/
{
if(eForm.cb[i].isSelect())
{
CBID = eForm.cb[i].getBID();
try
{
dbControl.insertCBInA(AID,CBID);
}
catch(SQLException e){String msg = e.getMessage();}
}
}
}
catch(SQLException e){String msg = e.getMessage();}
/******** INSERTION COMPLETE *****************/
return new Forward("success",eForm);
}
![]() |
Similar Threads
- To arrange Array Members in ascending order ! (Java)
- only const static integral data members can be initialized inside a class or struct (C++)
- Pointers to class members - it just won't work. (C)
- Help with calling class members (C++)
- encapsulating an array in a class? (C#)
- template array initialization (C++)
- help with sort using Calendar class getting null pointer exception (Java)
- How do I create a program using an Array ? (C++)
Other Threads in the JSP Forum
- Previous Thread: How to write javascript regular expression for this case?
- Next Thread: creating a .exe file of a web application
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web





