aspose file tools*
The moose likes Struts and the fly likes Struts: FormBean does not see String[] from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts: FormBean does not see String[] from JSP" Watch "Struts: FormBean does not see String[] from JSP" New topic
Author

Struts: FormBean does not see String[] from JSP

Kayla Siegel
Greenhorn

Joined: Jun 08, 2006
Posts: 8
Hi Experts,

I have a JSP page that needs to select a list of userIDs. The list of userIDs are populated from the database on a different JPS page. I need to pass this list of userIDs back to the original JPS page (the caller).
Some how my FormBean does not see this list. It is throwing a NullPointerException.

Here is my JSP code
<html:select property="subscriberList" multiple="multiple">
<%
int nRows = abean.getSubscribersList();
String subscriberName = null;

for (int i=0; i < nRows; i++){
subscriberName = abean.getString("UserID");
abean.moveNext();%>
<html ption value="<%=subscriberName%>"> <%=subscriberName%></html ption>
<%}%>
</html:select></TD>


Here is my FormBean code. Only one of these variables should be used but currently both of them are null.

private String subscriberName = null;
private String [] subscriberList = {};


/**
* Returns the subscriberList.
* @return String[]
*/
public String[] getSubscriberList() {
return subscriberList;
}

/**
* Sets the subscriberList.
* @param subscriberList The subscriberList to set
*/
public void setSubscriberList(String[] subscriberList) {
this.subscriberList = subscriberList;
}

/**
* Returns the subscriberName.
* @return String
*/
public String getSubscriberName() {
return subscriberName;
}

/**
* Sets the subscriberName.
* @param subscriberName The subscriberName to set
*/
public void setSubscriberName(String subscriberName) {
this.subscriberName = subscriberName;
}



Any help is greatly appreciated!

Yen
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
I think this really belongs in the Struts or JSP forum.

However, not seeing the rest of the code I do not know whether this is
all of the problem but if



is meant to be a call to



in FormBean, then you are trying to assign a String[] to an int.
If you have them spelled correctly in you OP, and it is not a typo, then disregard my comment as they are clearly different methods.

Also, is aBean in scope?
Kayla Siegel
Greenhorn

Joined: Jun 08, 2006
Posts: 8
Hi Edward,

Thank you for your reply...

I did not make a typo. How do I fix this problem?

aBean is in scope. I got the data back from the DAO fine. I cannot save this subscribersList, which will be passed back to another form.

Can you help me resolve this? How would you do this?


Thanks,
Yen
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Moved to the Struts forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, the line:

int nRows = abean.getSubscribersList();

Does not look right to me. I would expect a method named "getSubscribersList" to return a list of subscribers, not the number of subscribers. Are you sure this shouldn't be:

int nRows = abean.getSubscribersList().size();

?

As for your NullPointerException: Where is it occurring? In the JSP code, or in the ActionForm code? Can you show us the stack trace for the error?


Merrill
Consultant, Sima Solutions
Kayla Siegel
Greenhorn

Joined: Jun 08, 2006
Posts: 8
Hi Merrill,

Thank you for your suggestion...

I'll try it and let you know.

Thanks,
-Kayla
Kayla Siegel
Greenhorn

Joined: Jun 08, 2006
Posts: 8
I am still unable to get this problem resolved.

Does anyone has an example how to generate a list of users from JSP page and save them in the Form??

Your help is appreciated!

-Kayla
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
Hi hope this helps!!


<%@ page language="java" import="java.util.ArrayList" %>

<%@ taglib uri="struts-bean.tld" prefix="bean" %>
<%@ taglib uri="struts-html.tld" prefix="html" %>
<%@ taglib uri="struts.tld" prefix="struts" %>



<bean efine id="subscriberList" name="formBean" property="subscriberList" type="java.util.Collection"/>


<HEAD>


</HEAD>





<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td>Existing subscribers</td>
<td> <html:select property="subscriberName" styleClass="dropdownMenu">
<html ptions collection="subscriberList" property="value"/>
</html:select></td>
</tr>

</table>


//to be implemented in Action class

FormBean formBean =null;
formBean = (FormBean)form;
Arraylist subscriber_list=<get your arraylist of subscribers from backend>
formBean.setSubscriberList(subscriber_list);




//to be implemented in Action Form

private Collection subscriberList = new ArrayList();



/**
* Returns the subscriberName.
* @return String
*/
public String getSubscriberName() {
return this.subscriberName;
}

/**
* Sets the subscriberName.
* @param subscriberName The subscriberName to set
*/
public void setSubscriberName(String subscriberName) {
this.subscriberName = subscriberName;
}

/**
* Return the subscriber list.
*/
public Collection getsubscriberList() {

return (this.subscriberList);

}

/**
* Set the subscriber list.
*
*
*/
public void setsubscriberList(Collection subscriberList) {

this.subscriberList = subscriberList;

}
[ June 27, 2006: Message edited by: Christian Nash ]

- Christian
Kayla Siegel
Greenhorn

Joined: Jun 08, 2006
Posts: 8
Hi Christan,

Your example would work if my subscriberList is retrieved from the DB and remains unchanged.

The problem is I have to save the new subscriberList after the user selects them.

Here is what I have to do...
1) Create a 2 columes window. On the left I show the available Users, and on the right I show the current Subscribers.
2) In order to select from left to right or right to left, I provide the << or >> buttons.
3) The user can select from either box and click <Submit>. When this happens, I need to save the Current Subscribers only (subscriberList) ignore the Available Users

Currently I can save the Current Subscribers that I retrieved from the DB into an ArrayList. But I DON'T know how to save the newly selected subscriberList.

Thanks,
Kayla
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts: FormBean does not see String[] from JSP