• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using HTML:Multibox

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jera Blade
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic