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 Using HTML:Multibox 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 "Using HTML:Multibox" Watch "Using HTML:Multibox" New topic
Author

Using HTML:Multibox

Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
Can anyone avise me on how to populate my formbean with the values in the html:multibox element.

I do a search for a client and return a list of clients. Each client has a checkbox associated with them. If I tick one or few of the checkboxes then submit the form my action class throws a nullpointer because the string array which holds the multibox values has not been populated.

In my jsp I have the following:

<html:form action="/actionClient"
name="actionClientForm"
type="com.web.forms.ActionClientForm">

<logic:iterate id="client" name="searchClientForm" property="results">

<td width="14%">
<div align="center">
<html:multibox property="resourceIds">
<bean:write name="client" property="resourceId"/>
</html:multibox>
</div>
</td>

the results property of searchClientform holds a list of clientVOs. The clientVO has a field resourceId. please note that clientVO has filed resourceID and action client form has field resourceIds.

The actionclientform is as follows:

private String [] resourceIds = {};


/**
* @return Returns the resourceIds.
*/
public String[] getResourceIds() {
return resourceIds;
}
/**
* @param resourceIds The resourceIds to set.
*/
public void setResourceIds(String[] resourceIds) {
this.resourceIds = resourceIds;
}

my struts config action mapping is as follows:

<action path="/actionClient"
type="com.web.action.ActionClientAction"
name="actionClientForm"
scope="request"
input="/searchClient.jsp">
<forward name="edit" path="/createClient.jsp"/>
</action>


The error thrown is:

java.lang.NullPointerException
com.medina.web.action.ActionClientAction.execute(ActionClientAction.java:44)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

The code throws a null pointer on the following line:

ActionClientForm clntForm = (ActionClientForm)actionForm;

System.out.println("resource Id = " + (clntForm.getResourceIds()).length);

So can anyone tell mewhat I am doing wrong and how to pass the value to my action class

thanks in advance
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Your <html:multibox> tag is missing a value attribute. The value attribute indicates what value is to be placed in the resourceIds array if the box is checked.

See the following link for more information about this tag:

http://struts.apache.org/userGuide/struts-html.html#multibox


Merrill
Consultant, Sima Solutions
Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
The value that I want to put in the resourceIDs array is the resourceId of the clientVO. So how would I specify that in the value tag of the multibox element.
Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
In all the examples I have seen the bean:write tag has been used in between the multibix tags. this is holds the value I am trying to write to the action form so if I added the value property to the multibox tag would i need to remove this?

Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You're right. The internal text will be used as the value if you don't provide a value attribute. As I look at your example, I don't see anything wrong with the jsp or the form. I'm beginning to wonder if it isn't the variable clntForm in your Action class that's null. Is the variable actionForm the name of the parameter being passed into the execute method? I'd put a test in the action class to make sure the form itself isn't null.
Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
the variable actionForm is the name of the param being passed into the action class execute method.

I have the form beans tag referencing my actionform in the struts config xml. I debugged my action class and the form itself is not null however the value resourceIds within the form is null.

Any ideas why this value would not be populated.

the <bean:write name="client" property="resourceId"/> also returns a value because I put this into the multibox element and the checkboxes were ticked when the jsp loaded as follows:

<html:multibox name="client" property="resourceId">
</html:multibox>

All further suggestions will be appreciated

Thanks
Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
the variable actionForm is the name of the param being passed into the action class execute method.

I have the form beans tag referencing my actionform in the struts config xml. I debugged my action class and the form itself is not null however the value resourceIds within the form is null.

Any ideas why this value would not be populated.

the <bean:write name="client" property="resourceId"/> also returns a value because I put this into the multibox element and the checkboxes were ticked when the jsp loaded as follows:

<html:multibox name="client" property="resourceId">
</html:multibox>

All further suggestions will be appreciated

Thanks
Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
I have also tried putting the actual object I am referencing within the html multibox tag as follows:

<html:multibox property="resourceIds" name="actionClientForm">
<bean:write name="client" property="resourceId"/>
</html:multibox>

but this returns a null value as resourceIds!

I just dont see what i am doing wrong
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using HTML:Multibox
 
Similar Threads
struts help needed for error No getter method
Problem with indexed property !
Sending value from popup to parent window
using indexId
Multi check boxes error