This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Urgent: How to use Indexed Properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Urgent: How to use Indexed Properties " Watch "Urgent: How to use Indexed Properties " New topic
Author

Urgent: How to use Indexed Properties

Prashant Vasudeo
Ranch Hand

Joined: Mar 25, 2003
Posts: 38
hi
I am trying to use the nested tags in form bean . please help me on this.
I have a form which will have 8 element (textbox,radio box,...) in one row
and user have (add and delete buton) after the user clicks on + button one row should be displayed in the screen.
I tried this using nested tags.but giving some errors. also
It is possible that after user has entered the data the formbean will be populated with the user data?
please help as i have trying it for 3 days ..and i have to delivery on monday.
the code is as follows
Form Bean
------------
public class TestBean extends XmlCoeActionForm {
private MyBean myBean;
private String attb = "attribute";
public TestBean() {
Logger.writeDebug("creating TestBean.............");
this.myBean = new MyBean(this);
}
public MyBean getMyBean() {
Logger.writeDebug("getting MyBean.............");
return this.myBean;
}
public void setMyBean(MyBean mybean) {
Logger.writeDebug("setting MyBean.............");
this.myBean = mybean;
}
public String getAttb() {
Logger.writeDebug("getting arrb.............");
return this.attb;
}
public void setAttb(String attb) {
Logger.writeDebug("setting arrb.............");
this.attb = attb;
}
}
my MyBean class
----------------
public class MyBean {
private TestBean testbean;
private ArrayList myBeanList= new ArrayList();
private String newButton;

public MyBean(TestBean testBean) {
Logger.writeDebug("creating MyBean.........");
/* set the master bean */
this.testbean = testBean;
this.myBeanList = new ArrayList();
ActualBean bb = new ActualBean(this);
bb.setTxtLeftValue("leftvalue");
bb.setTxtRightValue("rightvalue");
this.myBeanList.add(bb);
}

public Object[] getMyBeanList() {
Logger.writeDebug("getting MyBeanList.........");
return this.myBeanList.toArray();
}

public void setMyBeanList(Object[] newMyBeanList) {
Logger.writeDebug("setting MyBeanList.........");
this.myBeanList = new ArrayList();
for (int i = 0; i < newMyBeanList.length; i++) {
this.myBeanList.add(newMyBeanList[i]);
}
}

public void setNewButton(String empty) {
Logger.writeDebug("setting NewButton.........");
ActualBean bb = new ActualBean(this);
bb.setTxtLeftValue("");
bb.setTxtRightValue("");
this.myBeanList.add(bb);
}


}
my ActualBEan class
----------------------
public class ActualBean {

private String txtLeftValue;
private String txtRightValue;
private MyBean myBean;
public ActualBean(MyBean myBean){
this.myBean = myBean;
}
/**
* @return
*/
public String getTxtLeftValue() {
return this.txtLeftValue;
}
/**
* @return
*/
public String getTxtRightValue() {
return this.txtRightValue;
}
/**
* @param string
*/
public void setTxtLeftValue(String txtLeftValue) {
this.txtLeftValue = txtLeftValue;
}
/**
* @param string
*/
public void setTxtRightValue(String txtLeftValue) {
this.txtRightValue = txtLeftValue;
}
}
my Jsp is
----------------
<%@ 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" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@page import="com.chase.xmlcoe.xmltoolkit.codegenerator.mappingservice.MyBean" %>
<%@page import="com.chase.xmlcoe.xmltoolkit.codegenerator.mappingservice.TestBean" %>

<html>
<form name="test" action="/xmlcoe/test.do" method="post">
<input type="hidden" name="actionKey" value="SUBMIT">

<jsp:useBean id="bean" class="com.chase.xmlcoe.xmltoolkit.codegenerator.mappingservice.TestBean"/>
<jsp:getProperty name="bean" property="myBean"/>
<% MyBean myBean = bean.getMyBean();
out.print("myBean is:"+myBean);
System.out.println("myBean is:"+myBean);
Object obj[] = myBean.getMyBeanList();
out.print("obj.length is:"+obj.length);
System.out.println("obj.length is:"+obj.length);
System.out.println("obj is:"+obj);
%>
<nested:nest property="myBean">
<nested:submit property="newButton" >NEW Button</nested:submit>
<nested:iterate property="myBeanList">
<nested:text property="txtLeftValue" />
<nested:text property="txtRightValue" />
</nested:iterate>
</nested:nest>
</form>
</html>
The error shoen is myBean is not found in any scope.
if i comment the iterator for myBeanList it shows the button generated
but if try to get values for txtLeftValue,txtrightValue , it is giving error.
regards
prashant
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Urgent: How to use Indexed Properties
 
Similar Threads
Get name of bean into .tag file through attribute
new to Struts
No getter method for property
problem on c:set
form bean is not getting updated upon submit in jsp