You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by nitin dubey <ni...@yahoo.com> on 2005/03/29 12:22:52 UTC

Best strategy

Hello,

I am using DispatchAction unspecified() method to
populate the ActionForm.  Form object in unspecified()
method is coming properly but when I try to access the
properties in my JSP using JSTL it does not show up. 
I am putting some values in the form that have no
associated controls in the HTML form.

struts-config.xml
~~~~~~~~~~~~~~~~~
<form-beans>
	<form-bean name="commonForm"
type="com.imc.startec.web.form.CommonForm" />
	<form-bean name="dummyForm"
type="com.imc.startec.web.form.DummyForm" />
</form-beans>

<action-mappings>
      <action path="/admin/main"
         name="commonForm"
         parameter="dispatch"	
         scope="session"
         input="/admin/Main.jsp" 
        
type="com.imc.startec.web.processor.MainAction" >
         <forward name="self" path="/admin/Main.jsp"
/>
      </action>

</action-mappings>


MainAction.java
~~~~~~~~~~~~~~~
protected ActionForward unspecified(ActionMapping
mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse
response) throws Exception {

	log.info("~unspecified called");

	CommonForm cf = (CommonForm) form;

	StringBuffer folder	= 	new StringBuffer();

folder.append(getServlet().getServletContext().getInitParameter("ContextPhysicalPath"));
	folder.append(System.getProperty("file.separator"));
	folder.append(Constants.TEST_SITE);

	File folderObject = new File(folder.toString());

	File filesArray[] = folderObject.listFiles();

	ArrayList directories	= null;
	ArrayList files			= null;

	ArrayList directoryNames = null;
	ArrayList fileNames		= null;

	if(filesArray != null)	{
		directories	= new ArrayList();
		files		= new ArrayList();

		directoryNames	= new ArrayList();
		fileNames		= new ArrayList();

		for(int counter = 0; counter < filesArray.length;
counter++)	{

			if(filesArray[counter].isDirectory())	{
				directories.add(filesArray[counter]);
				directoryNames.add(filesArray[counter].getName());
			}				

			if(filesArray[counter].isFile())	{
				files.add(filesArray[counter]);
				fileNames.add(filesArray[counter].getName());
			}
		}
	}

	cf.setDirectoryNames(directoryNames);
	cf.setFileNames(fileNames);

	form = cf;

	return mapping.findForward("self");
}


Main.jsp
~~~~~~~~
<html:form action="/admin/main" > 
								<table border="1" width="100%" cellspacing="0"
cellpadding="0">
									<tr>
										<td width="57%"
align="center"><b><bean:message key="label.title"
/></b></td>
										<td width="22%"
align="center"><b><bean:message
key="label.templateName" /></b></td>
										<td width="21%"
align="center"><b><bean:message
key="label.lastModificationDate" /></b></td>
									</tr>

									<c:if test="${! empty
commonForm.directoryNames}">
										<c:forEach var="directoryName"
items="commonForm.directoryNames">
											<tr>
												<td width="57%">/test folder browsing
comes here.</td>
												<td width="22%"><c:out
value="${directoryName}" /></td>
												<td width="21%">&nbsp;</td>
											</tr>
										</c:forEach>
									</c:if>

									<c:if test="${! empty commonForm.fileNames}">
										<c:forEach var="fileName"
items="commonForm.fileNames">
											<tr>
												<td width="57%">/test files browsing comes
here.</td>
												<td width="22%"><c:out value="${fileName}"
/></td>
												<td width="21%">&nbsp;</td>
											</tr>
										</c:forEach>
									</c:if>
								</table>
	  <html:hidden property="dispatch" value="refresh" />
</html:form>



Regards,

Nitin Dubey


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org