This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes No action is occured when i click the delete link to delete. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "No action is occured when i click the delete link to delete." Watch "No action is occured when i click the delete link to delete." New topic
Author

No action is occured when i click the delete link to delete.

struts junior
Greenhorn

Joined: Sep 17, 2004
Posts: 1
Hi all


error is described at the bottom of the page.pls see

here is my struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration
1.1//EN"
"<http://jakarta.apache.org/struts/dtds/struts->
config_1_1.dtd">

<struts-config>

<form-beans>
<form-bean name="addItemForm"
type="com.edhand.example1.AddItemForm"/>
<form-bean name="deleteItemForm"
type="com.edhand.example1.DeleteItemForm"/>

</form-beans>

<action-mappings>

<action
path="/actions/items"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/AddItem.jsp"/>

<action
path="/actions/addItem"
type="com.edhand.example1.AddItemAction"
name="addItemForm"
scope="request"
validate="true"
input="/pages/AddItem1.jsp">
<forward name="success" path="/pages/AddItem1.jsp" />
</action>


<action
path="/actions/itemDel"
type="com.edhand.example1.DeleteItemAction"
name="deleteItemForm"
scope="request"
validate="true"
input="/pages/DeleteItem.jsp">
<forward name="success"
path="/pages/loginerror.jsp" />

</action>


</action-mappings>

<message-resources parameter="resources.application"
null="false"/>

</struts-config>

DELETEITEM.JSP

<%@ page import="com.edhand.example1.ItemService" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator"%>

<html>
<head>
<title>Example 1</title>
</head>
<body bgcolor="white">

<h3>Example 1</h3>

<%
/*
* This code will generate a list of objects from the
* database and place a reference to this list in the
* request object.
*
*/
List itemList = ItemService.getInstance().getItemList();
Iterator iter = itemList.iterator();
%>
<p>List of items in <code>item</code> table of database
<code>test</code>.</p>

<table>

<tr>
<td><b> Item Name </b></td> <td><b> Item Description
</b></td> <td><b> Delete Records </b></td>

</tr>


<%

while (iter.hasNext()) {

com.edhand.example1.Item item =
(com.edhand.example1.Item) iter.next();
String name=item.getName();
String des=item.getDescription();
Long id=item.getId();


%>


<tr>
<td><%= name%></td> <td><%= des%></td> <td><a href='itemDel.do?id=<%
= id%>'>

delete </a></td>
</tr>


<%
}
%>

</table>
</body>
</html>


here is the output of
<http://localhost:8080/hibernate/actions/itemDel.do>

Example 1
List of items in item table of database test.

Item Name Item Description Delete Records
fg fgf delete
fsdf erw delete
gimhan weddaaa delete
gimhan priyantha delete
grger ger delete

When I click the delete link , no action is occurred, even no error page is dispalyed

DELETEITEMACTION.JAVA

package com.edhand.example1;

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

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

/**
* Processes user's request to delete an <code>Item</code> from the
database.
*
* Copyright 2004 Gimhan Priyantha
* @author Gimhan Priyantha
*
*/
public class DeleteItemAction extends Action
{

/**
* execute() processes a user's request to add an
<code>Item</code> to the database,
* given the data in the AddItemForm. Forwards the user back
to the input page.
*
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{

/*
* Cast generic form to the AddItemForm.
*/
AddItemForm addItemForm = (AddItemForm) form;

/*
* If the user has typed a name into the form,
*
* Create an item with the name and description
contained
* in the form.
*
* Using the ItemService, add the item to the
persistence
* layer.
*
* Clear the form so that the two fields will be empty
* upon the next load.
*/



String newid=request.getParameter("id");
ItemService.getInstance().deleteItem(Long.getLong(newid));




/*
* Always return to the "success" forward, currently
* configured in struts-config.xml to return the user
* to the AddItem.jsp.
*/
return mapping.findForward("success");

}


ADDITEMFORM.JAVA

package com.edhand.example1;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
* Stores information related to an <code>Item</code>
* within the Struts framework. Also provides validation on the
Item's name.
*
* Copyright 2004 Gimhan Priyantha
*
* @author Gimhan Priyantha
*
*/
public class AddItemForm extends ActionForm
{
private String name;
private String description;
private Long id;

/**
* validate() ensures the user's item is valid and returns the
appropriate <code>ActionErrors</code>
* object, if any errors are generated.
*
* @return <code>ActionErrors</code> A collection of errors
generated by validation process.
*
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request)
{
/*
* Create new ActionErrors object to hold any errors
we discover
* upon validation of the form's fields.
*
*/
ActionErrors errors = new ActionErrors();

/*
* Check the name field to ensure that it is neither
empty nor
* contains a zero length string.
*
*/
if (name == null || name.length() < 1)
{
/*
* Create a new ActionError item, using
the "errros.required" property
* found in application.properties:
*
* errors.required={0} is required.
*
* The "Name" string will replace the {0} tag
found in the properties.
*
* The AddItem.jsp page will be reloaded, and
the <html:errors /> tag
* will be replaced with a list of errors.
The first item will be:
*
* Name is required.
*
*/
errors.add("name", new ActionError
("errors.required", "Name"));

}

return errors;
}

/**
* Clears the object prior to each request.
*
*/
public void reset(ActionMapping mapping, HttpServletRequest
request)
{
this.clear();
}

/**
* getDescription() retrieves <code>description</code> field.
*
*/
public String getDescription()
{
return description;
}

public void setName(String name)
{
this.name = name;
}

/**
* getId() retrieves <code>id</code> field.
*
*/
public Long getId(){
return this.id;
}

/**
* Sets <code>id</code> field.
*
*/
public void setId(Long id)
{
this.id = id;
}


/**
*
* clear() sets all the object's fields to <code>null</code>.
*
*/
public void clear()
{
this.name = null;
this.description = null;
}

}

DELETEITEMFORM.JAVA

package com.edhand.example1;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
* Stores information related to an <code>Item</code>
* within the Struts framework. Also provides validation on the Item's name.
*
* Copyright 2004 Gimhan Priyantha
*
* @author Gimhan Priyantha
*
*/
public class DeleteItemForm extends ActionForm
{
private String name;
private String description;
private Long id;

/**
* getDescription() retrieves <code>description</code> field.
*
*/
public String getDescription()
{
return description;
}

/**
* getName() retrieves <code>name</code> field.
*
*/
public String getName()
{
return name;
}

/**
* setDescription() sets <code>description</code> field.
*
*/
public void setDescription(String description)
{
this.description = description;
}

/**
* Sets <code>name</code> field.
*
*/
public void setName(String name)
{
this.name = name;
}

/**
* getId() retrieves <code>id</code> field.
*
*/
public Long getId(){
return this.id;
}

/**
* Sets <code>id</code> field.
*
*/
public void setId(Long id)
{
this.id = id;
}


/**
*
* clear() sets all the object's fields to <code>null</code>.
*
*/
public void clear()
{
this.name = null;
this.description = null;
}

}

here is the output of
<http://localhost:8080/hibernate/actions/itemDel.do>

Example 1
List of items in item table of database test.

Item Name Item Description Delete Records
fg fgf delete
fsdf erw delete
gimhan weddaaa delete
gimhan priyantha delete
grger ger delete


When I click the delete link , no action is occurred, even no error page is dispalyed



but the error is when i click the delete link no action is occured

could u pls help me to solve the question

thx

gimhan
Kim Lilienfeld
Greenhorn

Joined: Apr 13, 2004
Posts: 25
Hi

There's quite a lot of code posted there so I'm finding it quite difficult to read and follow but I did notice one error..

In your struts-config you define the following form:

<form-bean name="deleteItemForm"
type="com.edhand.example1.DeleteItemForm"/>


And associate it with the DeleteItemAction:

<action
path="/actions/itemDel"
type="com.edhand.example1.DeleteItemAction"
name="deleteItemForm"


However, in your DeleteItemAction, you cast the form being passed to you into an AddItemForm... looks like a copy paste error:

public class DeleteItemAction extends Action
{

/**
* execute() processes a user's request to add an
<code>Item</code> to the database,
* given the data in the AddItemForm. Forwards the user back
to the input page.
*
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{

/*
* Cast generic form to the AddItemForm.
*/
AddItemForm addItemForm = (AddItemForm) form;

Sorry.. was just trying to follow logic and picked up on that first,.. will yell if I see anything else that might help.

Good Luck.
Kim
 
Don't get me started about those stupid light bulbs.
 
subject: No action is occured when i click the delete link to delete.