You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Jouravlev <jm...@gmail.com> on 2005/11/08 17:56:31 UTC
Re: Using Struts-Dialogs for multi row update
> Cheers,
>
> Danny
Um... Struts Dialogs does not deal with persistence (at least yet). It
can simplify your CRUD (Create, Update, Delete) operations, that is,
to display the list of products and to have Create/View/Edit/Delete
links or buttons for each product.
Please take a look at these links, do you have something like this in
mind, or something else?
(1) This is an item list. I used pushbuttons for CRUD operations, but
links can be used too if you like. Notice that whatever you do, the
address in the browser address bar stays the same. So it is impossible
to delete a row and then click Back and see it again from a stale
page. Try to reload this page or to use Back and Forward buttons.
http://www.superinterface.com/strutsdialog/crudactionlite.do
But if you do not want to have one address for item list and all
operations, you do not have to.
See source code in the dowload file. In samples-struts-config.xml see
either "/crudactionlite" which handles CRUD as one action, or pair of
actions "/cruditemlist" and "/crudaction", where there is one action
for item list, and another for View/Edit operations.
(2) Another version of this list can be seen in MailReader example:
http://www.superinterface.com/mailreader
Create a new account, then login and select "Manage Subscriptions"
link. The table is pageable, each page fits 4 rows. You can try to add
more subscriptions and see how you can flip pages. You can see
included source code for MailReader to see how Subscriptions are
managed. The list can be reimplemented with DisplayTag and JSP would
look cleaner.
(3) See description of CRUDAction class, which was used to create these tables:
http://struts.sourceforge.net/strutsdialogs/crudaction.html
It has predefined events; I think that it simplifies development of
CRUD applications.
Michael.
Please don't hesitate to ask if you have any further questions.
--
Struts Dialogs: code-behind for Struts
http://struts.sourceforge.net/strutsdialogs
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Using Struts-Dialogs for multi row update
Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/9/05, Danny Lee <ha...@yahoo.de> wrote:
> Hi Michael,
>
> Persistance is no issue, becouse I have implemented managers, which can
> be simply used anywhere. Something like:
>
> "On update PersistanceManager.UpdateProductCount(prodID, newCount)"
>
> Well the question was about multi row update. It means for every list
> line I have a "Delete" button (no problem), and a update text-field
> where I can input custom integers and then submit it. Then the only
> thing I want is to be able to access the submited values as a array of
> custom objects like in this small example:
>
> http://www.developer.com/java/ent/article.php/2233591
>
> But using Struts Dialogs and without needing for "preAction" and
> "postAction" like they do in the example above.
This is quite simple. Just do what is done in article, the only thing
you need to remember is to initialize your cart before a its JSP page
is shown, that is, to initialize cart before getDialogView() is
called, or in getDialogView() itself. For example, this creates a
sample cart out of three items:
public ActionForward getDialogView(...) {
DynaActionForm poForm = (DynaActionForm) form;
CartItem[] lines = (CartItem[]) poForm.get("lines");
// Initialize shopping cart with free gifts from our store
if (lines == null || lines.length == 0) {
lines = new CartItem[] {
new CartItem(new ShoppingItem("BFG-666", "Vodoo Doll",
2000), 1),
new CartItem(new ShoppingItem("aaa", "some aaa", 100), 2),
new CartItem(new ShoppingItem("bbb", "some bbb", 350), 3)
};
poForm.set("lines", lines);
}
// Return standard mapping for action view. We can define this view
// using "view" attribute of <component> property,
// or a <forward name = "DIALOG-VIEW" .../> element of <action> element.
return super.getDialogView(mapping, form, request, response);
}
Here is how the mapping can be defined, using new <component> element
from Struts Dialogs 1.23:
<component path = "/Cart"
view = "/shoppingpages/cart.jsp"
type = "net.jspcontrols.shoppingcart.CartAction"
form = "cartForm">
</component>
Anytime you navigage to /Cart.do using GET requst, that is, by typing
in the browser or using a link, the action will display cart.jsp page.
The page can be as simple as this:
<html:form action="/Cart.do">
<TABLE WIDTH="80%" BORDER="1">
<TR>
<TH align="left">Art.No.</TH>
<TH align="left">Name</TH>
<TH align="left">Price</TH>
<TH align="left">Quantity</TH>
<TH align="left">Operations</TH>
</TR>
<c:forEach var="item" items="${cartForm.map.lines}" varStatus="status">
<TR>
<TD><c:out value="${item.articleNo}"/></TD>
<TD><c:out value="${item.name}"/></TD>
<TD><c:out value="${item.price}"/></TD>
<TD><input type="text"
name="lines[<c:out value="${status.index}"/>].quantity"
value="<c:out value="${item.quantity}"/>"
size="3"></TD>
<TD><html-el:link
href="Cart.do?DIALOG-EVENT-DELETE&itemID=${status.index}">
Remove Item
</html-el:link></TD>
</TR>
</c:forEach>
</table>
<br/>
<html:submit property="DIALOG-EVENT-CHANGE">Update quantity</html:submit>
</html:form>
There are two commands: Delete Item and Update Quantity. These
commands should invoke corresponding handlers in the CartAction class.
You need to create the handlers and to map events to method names,
like this:
protected Map getKeyMethodMap() {
Map methodMap = new HashMap();
// By default, getInitKey() returns "DIALOG-EVENT", the standard
// event prefix for SelectAction and DialogAction
methodMap.put("DIALOG-EVENT-CHANGE", "onUpdate");
methodMap.put("DIALOG-EVENT-DELETE", "onDelete");
return methodMap;
}
Actually, you do not need to do much for update, since Struts will
update your nested array for you. For deletion, you need to define
"itemID" property in your form bean, which will hold the ID of item to
delete.
Write back if you have more questions.
Michael.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Using Struts-Dialogs for multi row update
Posted by Danny Lee <ha...@yahoo.de>.
Hi Michael,
Persistance is no issue, becouse I have implemented managers, which can
be simply used anywhere. Something like:
"On update PersistanceManager.UpdateProductCount(prodID, newCount)"
Well the question was about multi row update. It means for every list
line I have a "Delete" button (no problem), and a update text-field
where I can input custom integers and then submit it. Then the only
thing I want is to be able to access the submited values as a array of
custom objects like in this small example:
http://www.developer.com/java/ent/article.php/2233591
But using Struts Dialogs and without needing for "preAction" and
"postAction" like they do in the example above.
Thank you in advance!
Cheers,
Danny
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org