jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes Each row of a table as form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Each row of a table as form" Watch "Each row of a table as form" New topic
Author

Each row of a table as form

Dr Scott
Greenhorn

Joined: Jul 20, 2011
Posts: 2
Hi,

i am using <display:table ...... > tag to generate table data at run time.

each row in generated table has a link "post" in one cell.

below is rough table figure .

Sl No ------------ Action

1 --------------------- post

2 --------------------- post


below is the code to display the table:


<display:table name="loadQueriesApprovedList" class="its" id="loadMyQueryData">
<display:caption>Queries Approved</display:caption>
<s:form action="" method="POST">
<display:column property="slNo" title="Sl No" />
<display:column property="date_replied" title="Date replied" />
<display:column property="issue_summary" title="Issue Summary" maxLength="30"/>
<display:column property="response" title="Response" maxLength="30" />
<display:column property="link" title="Link on SDF" />
<display:column value="POST" href="/AppUpdatePortal/CQnA/PostQuery.action" title="ACTION" />

</s:form>
</display:table>

on click of link "post" its calling PostQuery action.
i want "Sl No" of the corresponding row in action calss.

Could you please tell me how to do that.

Thanks,
Scott

Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
Hi Scott,

Instead of the last line, you can do the following inside the display Column tag:

<display:column title="ACTION">
<a href="#" onclick="javascript:submitFormDetails('<bean:write name="loadMyQueryData" property="slNo"/>');">Post</a>
</display:column>

By this way, you can get the slNo in the javascript function 'submitFormDetails', which you can assign to a form property and extract in the Action class.

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
Dr Scott
Greenhorn

Joined: Jul 20, 2011
Posts: 2
Hi Komal,

Thanks for the reply.
But i am not able pass '<bean:write name="loadMyQueryData" property="slNo"/>' as parameter.
It closing the anchor tag at property="slNo"/> and hence creating page error.
Can you tell me how to do this.
and how to set bean property to form in javascript function.

Thanks.
Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
Hi Scott,

I've tried the same thing for <a href.... > in my project and it works as expected. Possibly there might be some other issue in your JSP which is causing the page error.

About setting the bean property in form, firstly define a property in form, say for eg: selectedSlNo. Now on the jsp give a hidden property for this.
the javascript function would be something like

function submitFormDetails(slNo){
document.getElementById(selectedSlNo).value = slNo;
// other operations if any and then form submit
}

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
 
Consider Paul's rocket mass heater.
 
subject: Each row of a table as form