public class BeanVO {
private String a;
private String b;
private String c;
public String geta (){return a;}
public void setA(String a) {this.a=a};
public String getB (){return b;}
public void setB(String b) {this.b=b};
public String getC (){return c;}
public void setC(String c) {this.c=c};
}
public class MyForm extends ActionForm{
private BeanVO beanVO;
private String submit; //submit property of html:button
public String getSubmit (){return submit;}
public void setSubmit(String submit) {this.submit=submit};
public MyForm (){
beanVO = new BeanVO();
}
public BeanVO getBeanVO(){ return beanVO;}
public void setBeanVO(){ this.beanVO = beanVO;}
}
pubic class MyAction extends Action {
ActionForward execute(.....){
MyForm form = (ActionForm)MyForm;
if (form!=null){
String action = form.getSubmit();
if (action == null){
this.loadForm(req,form);//this method will get the sql data and display in jsp
return mapping.findForward("success");
}
if ("Save".equals(action)){
this.updateForm(req,form);
return mapping.findForward("save");
}
public void loadForm(HttpServletRequest req, ActionForm actionForm){
//get collection of other objects from databaseand extract field a,b,c of other objects
//and put them in Collection<BeanVO> then set this collection in session
//for loading them in jsp to display to web browser
Collection<MyObject> myObjectCollection = new Collection<MyObject>();
Collection<OtherObject> records = retriveFromDAO(baseOnSomeCriteriaField);
Iterator<OtherObject> iter = records.iterator();
while(iter.hasNext()){
MyObject myObject = new MyObject();
myObject.setA(iter.getFielda);
myObject.setB(iter.getFieldB);
myObjectCollection.add(myObject);
}
setSessionObject(req,"myObjectCollection",myObjectCollection);
}
//when some value is entered in textbox c and
//Save button is clicked updateForm is called
public void updateForm(HttpServletRequest req, ActionForm actionForm){
//get the MyObject Collection from session stored in loadForm
Collection<MyObject> myObjectCollection = (Collection<MyObject>)
getSessionObject(req,"myObjectCollection");
MyForm form = (ActionForm) MyForm;
//here comes the null problem: after ** execute,
// c is null when I Step over the Eclipse debug mode
String c = form.getMyObject().getC(); //**
//could not do any thing at thispoint until I can get some value from c
// the rest is held because of this problem
}
}
public class MyJsp {
-----skip the long unrelated issues----
---some common header and body from tiles
<html:form action="/myAction.do" method="post">
some craps.....
//here come the logic:iterate over the myObjectCollection
<table>
<tr><th>A</th><th>B</th><th>C</th></tr>
<logic:iterate id="myObject" name="myObjectCollection" >
<tr>
<td><html:text><bean:write name="myObject" property="a"/><td>
<td><html:text><bean:write name="myObject" property="b"/><td>
<td><html:text><bean:write name="myObject" property="c"/><td>
</tr>
</logic:iterate>
<tr>
<td>
<html:submit property="submit" value="Save"/>
</td>
</tr>
</table>
</html:form>
<logic:iterate id="myObject" name="myObjectCollection" >
<tr>
<td><html:text><bean:write name="myObject" property="a"/><td>
<td><html:text><bean:write name="myObject" property="b"/><td>
<td><html:text><bean:write name="myObject"><td>property="c" disable="true"/
</tr>
</logic:iterate>
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|