Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes html:Submit with more properties 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 "html:Submit with more properties" Watch "html:Submit with more properties" New topic
Author

html:Submit with more properties

Andrea Biraghi
Greenhorn

Joined: Jun 23, 2009
Posts: 4
Hi,

I have a table with several row. For each row i need to insert a submit button to delete row.

Problem: I used the submit property to define dispatch value (method name inside the action)
How can I pass to action selected row's number id?


JSP:

<logic:iterate id="place" name="details" property="info.places" indexId="indexList">
....
<html:submit property="dispatch" styleClass="<%= buttonStyle %>">
<bean:message key="button.delete"/>
</html:submit>
</logic:iterate>


ACTION (I use LookupDispatchAction):
....
public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

String indexId = req.getParameter("indexList"); ??? I need indexId parameter ???
...
delete record on DB
}

P.S. I can't use JavaScript

Thanks

Andrea
Andrea Biraghi
Greenhorn

Joined: Jun 23, 2009
Posts: 4
No solution?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Andrea Biraghi wrote:How can I pass to action selected row's number id?

You can pass it as an "query string", like
http://host/YourAction.do?rowid=3

OR
Pass row id as a hidden attribute.
JSP:



[Please this is the approach not complete code ]



[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Andrea Biraghi
Greenhorn

Joined: Jun 23, 2009
Posts: 4
Hi Sagar,
thank you for your reply but it doesn't work.

1st solution: I need to submit form. I can't use link with attributes

2nd solution: rowid is the same for every row. This value isn't dynamic! "rowid = last indexList"

Here's my code:


I tried to use indexed attribute but nothing.

Any idea?

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Andrea Biraghi wrote:1st solution: I need to submit form. I can't use link with attributes

Usually, the delete action requires a single attribute, e.g to delete "person/user" record I'll submit person id/user id and delete that row from db, If this is what you're doing then you can pass that id using link.

I don't know your html form or which property you're submitting. But to pass "id" through link, I'll use html:link tag instead of html:submit.
like

Andrea Biraghi wrote:2nd solution: rowid is the same for every row. This value isn't dynamic! "rowid = last indexList"

Sorry for that.

Finally, you need to pass an "request" attribute when you call delete action, either pass using "query string" or hidden request parameter, concentrate on that, you will get your answer.
Andrea Biraghi
Greenhorn

Joined: Jun 23, 2009
Posts: 4
I can't use html:link because I need to submit form values
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Andrea Biraghi wrote:I can't use html:link because I need to submit form values

And which value you're submitting, As I quote earlier, to DELETE, you hardly require a FORM to submit. so whats your need ?

And If you still want to SUBMIT a FORM, a hidden ID can be passed any time OR If I'm not getting your requirement then read this.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: html:Submit with more properties