Struts problem using checkbox with DynaActionForm
843836Jun 10 2005 — edited Jul 12 2005I am having a problem using checkboxes with struts with the DynaActionForm class. I am new to struts but I have looked at all of the relevant documents for learning struts and I thought I had everything set up correctly. However, whenever the action class ActionForward method is invoked the checkbox property always comes back false regardless of whether it is checked or unchecked. And as you can see in the code below the ActionForward method does set the parameter before returning to the jsp page.
I have included below the relevant portions of the struts-config.xml file, the jsp file and the action class.
Please submit a reply if you have any idea what the problem may be or what I have done incorrect.
Thank you
Relevant portions of struts-config.xml
...
<form-bean
name="WorkflowForm"
type="org.apache.struts.action.DynaActionForm">
<form-property
name="importing"
type="java.lang.Boolean"/>
</form-bean>
...
<action
path="/WorkflowManager"
name="WorkflowForm"
scope="session"
type="org.mitre.semantic.moie.ui.WorkFlowManagerAction">
<forward
name="ExecutionResult"
path="/pages/WebSvcFinder.jsp?display=result"/>
</action>
<action
path="/ExecuteWorkflow"
parameter="/pages/WorkflowManager.jsp"
type="org.apache.struts.actions.ForwardAction">
<forward
name="ExecutionResult"
path="/pages/WebSvcFinder.jsp?display=result"/>
</action>
...
Relevant portions of WebSvcFinder.jsp
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
...
<!-- main body table -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left" bgcolor="#ff8c00" height="100%">
...
<tr>
<html:form action="/WorkflowManager">
<td>
<html:checkbox property="importing" value="true">
Import Instance
</html:checkbox>
<td>
</html:form>
</tr>
...
</table>
ActionForward method of WorkFlowManagerAction class
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
System.out.println(request.getContextPath());
// Validate the request parameters specified by the user
ActionErrors errors = new ActionErrors();
HttpSession session = request.getSession();
OWLModel model = (OWLModel) session.getAttribute("model");
ForwardConfig forward = (ForwardConfig) session.getAttribute("forward");
String criteria = forward.getName() + "Result";
boolean importInstance = true;
Boolean importing = (Boolean) PropertyUtils.getSimpleProperty(form, "importing");
if (importing != null)
{
System.out.println("Import Instance: " + importing.booleanValue());
importInstance = importing.booleanValue();
}
else
{
System.out.println("Import Instance is null");
}
((DynaActionForm)form).set("importing", new Boolean(importInstance));
String service = request.getParameter("svc");
String url = null;
FlowManager flowManager;
try {
flowManager = new FlowManager(model);
url = flowManager.execute(service, importInstance);
} catch (Exception e) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError( "errors.internal.server", e.toString()));
e.printStackTrace();
}
// Report any errors we have discovered back to the original form
if (!errors.empty()) {
saveErrors(request, errors);
return (mapping.findForward(criteria));
}
if (url != null)
{
response.sendRedirect(url);
ActionForward directForward = new ActionForward(url);
return directForward;
}
else
{
return (mapping.findForward("ExecutionResult"));
}
}