• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiboxes

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Its a struts project.
Im using html:multibox tag and it use to select the multi boxes and delete the selected boxes.

In this im having fields like name,dob,age,height,country..

Im not cleared about how to use the multiboxes, below is the code.

In listA.jsp page
-----------------
<input name="submit3" type="button" value="Delete"
calling "deleteUsers()" /></td>

<logic resent name="OBList">
<% int count = 0; %>
<logic:iterate id="OB" name="OBList" type="com.integrosys.cms.ui.test.bus.OBA" scope="page">
<tr class="<%=count++%2==0?"even":"odd"%>">
<td class="index"><%=count%></td>
<td><%=OB.getName() %></td>
<td><%=OB.getDob() %></td>
<td><%=OB.getAge() %></td>
<td><%=OB.getGender() %></td>
<td><%=OB.getHeight() %></td>
<td><%=OB.getWeight() %></td>

<td><%=AHelper.getCountryName(OB.getCountry()) %></td>
<td style="text-align:center"><select name="select3" onChange="JumpOnSelectactive(this, '<%=OB.getName() %>')">
<option selected="selected" >Please Select</option>
<option value="edit">Edit</option>
<option value="view">View</option>
<!--option value="delete">Delete</option-->
</select>
</td>
<td><html:multibox property="name" value="<%=OB.getName()%" /></td>
</tr>
</logic:iterate>
</logic resent>

Scripting
----------
delete(){
document.forms[0].action="A.do?event=delete&name=";(how to pass the multi name )
document.forms[0].submit();
}

Thanks in Advanced
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid there's a bit of a flaw in your design. The user could check more than one box to delete, but it looks like your Action is only equipped to delete one record at a time. Since it is not possible to submit the same page more than once, you're going to need an action that can delete more than one record at a time.

Once you've created such an action, you can do something like this:


[ July 04, 2007: Message edited by: Merrill Higginson ]
 
Mohammed Niaz M.
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,
Thanks for your reply and its working but i have to work in Action to perform the deleting more names.
I let you know the process.
 
Mohammed Niaz M.
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,
still im not able to delete more than one name
Javascript:
-----------
var boxes = document.getElementsByName('name');
var uri = 'A.do?event=delete';
var atLeastOneBoxChecked = false;
for (var i=0;i<boxes.length;i++) {
if (boxes[i].checked) {
atLeastOneBoxChecked = true;
uri = uri + "&name=" + boxes[i].value;
deleteNameList[i] = boxes[i].value; //Added
}
}
if (atLeastOneBoxChecked) {
document.forms[0].action=uri+"&deleteNameList"+deleteNameList;
document.forms[0].submit();
}
------------------
<html:multibox property="name" value="<% OB.getName() %>" />
----------------------Whether i pass the value array instead of OB.getName() to bean

In Formbean
----------
i decalred

String[] deleteNameList;

public String[] getDeleteNameList(){
return deleteNameList;
}

public void setDeleteNameList(String[] deleteNameList){

this.deleteNameList = deleteNameList;
}


public String getName() {
return name;
}

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


--------------------------------------
In the URL:
http://localhost:7080/training/A.do?event=delete&name=fds&name=hyg&deleteNameListfds,,hyg

The deleteNameList array is passing to bean but i cannt assign the multi-value to name field or deleteNameList

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

Thanks In Advanced.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you've added won't work. It will not create a well-formed URI. Besides, it isn't necessary. Just use the code I gave you as-is and add the following line to your Action:

Because the URI passes the parameter "name" multiple times in the query string, the getParameterValues() method returns a string array with one element for each value. In the example you gave, deletedEvents would contain {"fds", "hyg"}. You can then iterate through this array and process the delete for each item.

As an alternative to calling the getParameterValues method, you could simply define the name property as a string array in your ActionForm bean.
 
Mohammed Niaz M.
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,
Im using struts based framework but some additional classes are added they are Mapper,Commands,Declared input parameters and output results � controlled scope.
Im using AAction n AForm.

The Action File
----------------

AForm
-----

AMapper Class
-------------


DeleteACommand Class
--------------------


AHelper Class
--------------


AProxy Class
------------


ListA.jsp
---------


AForm Class
-----------

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

Still im able to delete only one Name.

Can you help out..

Thanks in Advanced
-- Added UBB [ c o d e ] [ / c o d e ] tags to make code easier to read
[ July 06, 2007: Message edited by: Merrill Higginson ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mohammed,

Let me explain what I posted earlier. I said that your code will not produce a well-formed URL, and that is still the case. A well-formed url has the format:
http://myserver.com?parm1=value1&parm2=value2&parm3=value3.. etc. Your code does not put the required ampersand between parameters, nor the equal sign between parameter name and value. I've shown you what needs to go into the URL and now its up to you to write code that will produce a well-formed URL.

I'm afraid I'm not going to be able to help you integrate this change into this rather cumbersome framework you're working with. I don't understand how it works, and even with the large amount of code you've already posted, you'd still have to post a lot more of it before I'd even begin to understand it.

Aside from that, writing your code for you is not what I'm here for. I'm simply pointing out to you certain principles and truths about Struts and JavaScript, and then it's up to you to apply them. My advice would be to talk to your supervisor or someone at your company who either wrote or is familiar with this framework and get them to help you make it work for deleting multiple rows.

Having said that, below is a simple Action class that would accomplish the task without your framework. It may help you in figuring out how to make it work within your framework.


[ July 06, 2007: Message edited by: Merrill Higginson ]
 
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
very nice one and good example for new developers
reply
    Bookmark Topic Watch Topic
  • New Topic