Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Chris Wimmer

Greenhorn
+ Follow
since Aug 18, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chris Wimmer

Your suggestion to extend Struts and to let the ModuleConfig implementation do the replacement is a good idea. I've not thought about this till now. Thank you very much for that hint.

Ciao

Chris
13 years ago
Hello,

exists there any (easy) possibility to equalize the action forward patterns in struts config with static Java constants?
"Easy" means without parsing the files with any other language and to textual replace the strings.
The example below defines some mapping constants, uses them in action and in struts-config.xml.

WebConstants.java:

public interface WebConstants {
public static final String SUCCESS = "success";
public static final String FAILURE = "failure";

}


Action.java:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward forward = mapping.findForward(WebConstants.FAILURE);

if(form != null) {
...
forward = mapping.findForward(WebConstants.SUCCESS);

}

return forward;
}


struts-config.xml:

<action path="/ConfigInit"
type="app.myTest.struts.action.ConfigInitAction"
scope="session" >
<forward name="success" path="/ServerConfig.do" contextRelative="false" />
<forward name="failure" path="/errorFwd.do" contextRelative="false" />
</action>



In the example the WebConstants.java file contains static string constants for SUCCESS and FAILURE. In struts-config.xml the content of the definitions is used in the name attribute of the forward declaration.
In a greater software project you may have many different constants and many different labeled forward "names".


Exists there a solution to avoid misspelling in these two places?


Thanks


Chris
13 years ago
Hi,

I am running Tomcat 5.5 with Struts 1.2.8 and I want to use modules and the Struts validation framework.
Additional I want that my JSP pages are private that means not directly callable from the user. Therefore I put them inside the WEB-INF directory beneath my web application in directory "/WEB-INF/pages/archivewizard".
The web application has more steps to collect data and at the end the data is saved (wizard).

Now I've a big problem especially with the validation framework. I've a module called "wizard" and a corresponding wizard-config.xml file.

In the main JSP-page this wizard is started with:
<html:link module="/wizard" page="/startArchiveCreate.do">Create wizard</html:link>


The wizard works very well (next, previous, cancel), but if an validation error occures the JSP page navigated to can not be found!
The tomcat error message is:
type Status report
message /wizard/WEB-INF/pages/archivewizard/EnterName.jsp
description The requested resource (/wizard/WEB-INF/pages/archivewizard/EnterName.jsp) is not available.


The used path is not correct (the preceeding /wizard) and it differs from the input-path.


Why can the JSP page not be found after validation, but during input?




---------------------------------------------------------------------------------
The wizard-config.xml file contains the following action-mapping:

<action-mappings>
<action path="/default"
type="com.opentext.struts.action.SuccessAction" >
<forward name="success" path="/Welcome.do" contextRelative="true" redirect="true" />
</action>

<action path="/startArchiveCreate"
type="com.opentext.struts.action.SuccessForwardAction">
<forward module="" name="success" path="/WEB-INF/pages/archivewizard/EnterName.jsp" contextRelative="true" redirect="false" />
</action>
<action path="/typeStoreFwd"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/pages/archivewizard/TypeStore.jsp" />
<action path="/storageSystemContainerFwd"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/pages/archivewizard/StorageSystemContainer.jsp" />
<action path="/storageSystemSingleFwd"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/pages/archivewizard/StorageSystemSingle.jsp" />
<action path="/settingsFwd"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/pages/archivewizard/Settings.jsp" />
<action path="/archiveOverviewFwd"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/pages/archivewizard/ArchiveOverview.jsp" />
<action path="/errorFwd"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/pages/common/error.jsp" />

<!-- create archive wizard -->
<action path="/enterName"
type="com.opentext.struts.action.CreateArchiveWizardAction"
name="createArchiveWizardForm"
attribute="archivewizard"
scope="session"
input="/WEB-INF/pages/archivewizard/EnterName.jsp"
validate="true">
<forward name="next" path="/wizard/typeStoreFwd.do" contextRelative="true" />
<forward name="cancel" path="/wizard/default.do" contextRelative="true" />
<forward name="failure" path="/wizard/errorFwd.do" contextRelative="true" />
</action>

....

</action-mappings>

---------------------------------------------------------------------------------

Thanks

Chris
14 years ago
Hello alan do,

my problem is solved.

I've added in the form as you suggested:
private List definitions = new ArrayList();
which does not solve the problem at all. But adding a setter method:
public void setDefinitions(List defs) {
// ignore
}
together with using the <c:forEach>-Tag did the job.

The used <c:forEach>-Tag is:
<c:forEach items="${dynTestForm.definitions}" var="def">

<c:out value="${def.name}" />
<html:text property="${def.field}" size="20"/>

</c:forEach>


The action is now called twice, once to initialize and once to gain the result. That means I've changed some other smaller things to get the stuff working, but that had nothing to do with the exception.


Thank you very much for your help

Chris Wimmer
14 years ago
I'm new to Struts and JSP-Programming. I'm trying to use a DynaActionForm which has a certain count of predefined form-properties (strfield1 ... strfield4). Additional I've another logic which is located in the form implementation which assigns a property-name, property-type to a field-name. It should be a simple form generator which uses the predefined fields and assigns them a custom label/name and a user defined type (like TextField, PasswordField, NumberField, ...). The aim is to evaluate the type-field in the jsp-page and to display an adequate html-element.

In the TestDynaAction the service is only used to get some test data. The logging can be also neglected. In the struts-config.xml the "definitions" property is not defined explicitely as form-property, but it is implemented in the BaseDynaActionForm.
I'm using c ut for output and not bean:write, because some book authors claim that it will be soon deprecated. The c ut and html:text tags may be not fully correct, but I have never been coming to this place in the code.
The request is started with "..../testDyna.do". I'm using Tomcat 5.5 with Java 1.4.7 and Taglib Version 1.1.
The request is answered with the already well discussed error message, but the hints given have not solved my problem. I have a getter method and my dynTestForm is not replaced in the action form by sth.:

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: No getter method for property definitions of bean dynTestForm
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.pages.dyna.TestDyna_jsp._jspService(org.apache.jsp.pages.dyna.TestDyna_jsp:231)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:582)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:260)
ixos.webclient.base.BaseRequestProcessor.process(BaseRequestProcessor.java:42)
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:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



---------------------------------------------------------------------------
struts-config.xml:

<form-bean name="dynTestForm" type="ixos.webclient.base.BaseDynaActionForm">
<form-property initial="" name="strfield1" type="java.lang.String"/>
<form-property initial="0" name="strfield2" type="java.lang.String"/>
<form-property initial="0" name="strfield3" type="java.lang.String"/>
<form-property initial="false" name="strfield4" type="java.lang.String"/>
</form-bean>

<action path="/testDyna"
type="ixos.webclient.action.TestDynAction"
forward="/pages/dyna/TestDyna.jsp"
name="dynTestForm"
parameter="direction"
scope="session"/>
<action path="/testDyna_post"
type="ixos.webclient.action.TestDynaAction"
attribute="dynTestForm"
name="dynTestForm"
scope="session"
input="/pages/dyna/TestDyna.jsp"
validate="false"
>
<forward name="success" path="/pages/dyna/success.jsp" contextRelative="true" />
<forward name="error" path="/pages/dyna/error.jsp" contextRelative="true" />
</action>


--------------------------------------------------------------------------
TestDynaAction.java:

package ixos.webclient.action;

import ixos.base.log4j.Log;
import ixos.webclient.Const;
import ixos.webclient.base.BaseDynaActionForm;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class TestDynaAction extends AbstractAction {
/** Class identifier for logging */
private static final Log.Context LC = new Log.Context(TestDynaAction.class.getName());

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
final String MN = "execute";

LC.info(MN, "Executing...");

// set the available values as session attributes
GutlService gutlService = new GutlService();
HttpSession session = request.getSession();
Collection orders = gutlService.getOrders();
Collection types = gutlService.getTypes();
Collection fields = gutlService.getFields();
session.setAttribute("orders", orders);
session.setAttribute("types", types);
session.setAttribute("fields", fields);

BaseDynaActionForm dynForm = (BaseDynaActionForm)form;

dynForm.setPropertyNames(orders);
dynForm.setPropertyTypes(types);
dynForm.setFieldNames(fields);


Iterator types_it = types.iterator();
Iterator fields_it = fields.iterator();
for(Iterator order_it = orders.iterator(); order_it.hasNext() {
String key = (String)order_it.next();
String typ = (String)types_it.next();
String field = (String)fields_it.next();

processProperty(dynForm, key, typ, field);
}

return mapping.findForward(Const.SUCCESS);
}

private void processProperty(BaseDynaActionForm form, String key, String type, String field) {
final String MN = "processProperty";

if(key == null || key.equals("")) {
LC.error(MN, "Received property name is null or empty", null);
return;
}
if(type == null || type.equals("")) {
LC.error(MN, "Received property type for '" + key + "' is null or empty", null);
return;
}
if(field == null || field.equals("")) {
LC.error(MN, "Received field name for '" + key + "' is null or empty", null);
return;
}

Object val = form.get(field);
if(val == null) {
LC.error(MN, "Got for property '" + key + "' and field '" + field + "' null value", null);
return;
}
if(val instanceof String) {
String str = (String)val;
LC.info(MN, "Got property '" + key + "' = " + str + " (Type: " + type + ")");

} else if(val instanceof String[]) {
String[] arr = (String[])val;
StringBuffer sb = new StringBuffer();
for(int i = 0; i < arr.length; i++) {
if(i > 0) {
sb.append(" ");
}
sb.append(arr[i]);
}
LC.info(MN, "Got string array property '" + key + "' = " + sb.toString());
} else {
LC.warn(MN, "Got for property '" + key + "' and field '" + field + "' not supported value");
return;
}

return;
}
}

class GutlService {
public GutlService() {

}

public Collection getOrders() {
ArrayList orders = new ArrayList();
orders.add("Archive name:");
orders.add("Pool name:");
orders.add("Execute now:");

return orders;
}

public Collection getTypes() {
ArrayList types = new ArrayList();
types.add("TextField");
types.add("TextField");
types.add("BooleanField");
return types;
}
public Collection getFields() {
ArrayList fields = new ArrayList();
fields.add("strfield1");
fields.add("strfield2");
fields.add("strfield3");
return fields;
}
}


---------------------------------------------------------------------------
BaseDynaActionForm.java:

package ixos.webclient.base;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.struts.action.DynaActionForm;

public class BaseDynaActionForm extends DynaActionForm {
private ArrayList _propertyNames;
private ArrayList _propertyTypes;
private ArrayList _fieldNames;


/** helper class to have only one iterator over the items */
public static class Definition {
private String _name;
private String _type;
private String _field;

public Definition(String name, String type, String field) {
_name = name;
_type = type;
_field = field;
}
public String getName() {
return _name;
}
public void setName(String name) {
_name = name;
}
public String getType() {
return _type;
}
public void setType(String type) {
_type = type;
}
public String getField() {
return _field;
}
public void setField(String field) {
_field = field;
}
}


/** This is the method called to get a list to iterate through from JSP */
public List getDefinitions() {
int size = _propertyNames.size();
ArrayList definitions = new ArrayList(size);
for(int i = 0; i < size; i++) {
definitions.add(new Definition((String)_propertyNames.get(i),
(String)_propertyTypes.get(i),
(String)_fieldNames.get(i)));
}
return definitions;
}


public void setPropertyNames(Collection props) {
ArrayList arr = new ArrayList();
for(Iterator it = props.iterator(); it.hasNext() {
String name = (String)it.next();
arr.add(name);
}
_propertyNames = arr;
}

public void setPropertyTypes(Collection types) {
ArrayList arr = new ArrayList();
for(Iterator it = types.iterator(); it.hasNext() {
String type = (String)it.next();
arr.add(type);
}
_propertyTypes = arr;
}

public void setFieldNames(Collection names) {
ArrayList arr = new ArrayList();
for(Iterator it = names.iterator(); it.hasNext() {
String field = (String)it.next();
arr.add(field);
}
_fieldNames = arr;
}

}



--------------------------------------------------------------------------
TestDyna.jsp:

<%@ page language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"; prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"; prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"; prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"; prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"; prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template"; prefix="template" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested"; prefix="nested" %>

<%@ page isELIgnored="false" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />

<title>TestDyna.jsp</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is dyn action form test page">
</head>

<html:form action="/testDyna_post" focus="strfield1">
<body>
<H2>Testing dyna action form</H2>
<table>

<tr>
<td>
<c ut value="Property" />
</td>
<td>
<c ut value="Value" />
</td>
</tr>

<!-- iterate through properties -->
<logic:iterate id="def" name="dynTestForm" property="definitions" scope="session">
<tr>
<td>
<c ut value="${def.name}" />
</td>
<td>
<html:text name="def" property="${field}" size="20"/>
</td>
</tr>
</logic:iterate>


</table>
<html:submit value="Ok" styleId="submit" />
<html:cancel value="Cancel" styleId="cancel" />
<br>

</body>
</html:form>
</html:html>



Thanks in advance

Chris
14 years ago