| Author |
Setting value of java variable to hidden field
|
Saritha Penumudi
Ranch Hand
Joined: Aug 18, 2003
Posts: 146
|
|
Hi, I have a scenario where I will get data from the database as a collection of Valueobjects. In my struts Action class I am holding them in request scope and In my jsp I am using <logic:interate> tag to populate that data in a listing format using <html:table>. First column in the listing should be a hyperlink so that user can update that record. Now when user clicks on the hyperlink, I need to send the Id of that record so that I can navigate the user to the entry form in update mode. I thought of holding the Id in hidden field and set that field with Id through javascript on onclick event and submit the form. I am using Dispatchaction. So, I have an another hidden filed to which I would set method to call name on same event. Now, My problem is how can I set Id to my hidden field? part of my Jsp: --------------------------- <logic:iterate id="mList" scope="request" name="messageList" type="demo.vo.ErrorMessageVO"> <tr> <td> <html:checkbox property="deleteErrorMessages" value="<%=mList.getMessageNumber() %>"/> </td> <td align="left" valign="top" nowrap="nowrap"> <html:link href="#" onclik="setup('<%=mList.getMessageNumber()%>')" > <bean:write name="mList" property="messageNumber"/> </html:link> </td> <td align="left" valign="top" nowrap="nowrap"> <bean:write name="mList" property="logIndicator"/> </td> <td align="left" valign="top" nowrap="nowrap"> <% demo.vo.Code cd = mList.getSeverity();%> <%= cd.getDesc() %> </td> --------------------------- function setup(input){ document.CreateErrorMessageActionForm.methodToCall.value='setupUpdateMessage'; alert(input); document.CreateErrorMessageActionForm.messageNumber.value =input; alert(document.CreateErrorMessageActionForm.messageNumber.value); document.CreateErrorMessageActionForm.submit(); } -------------------------- How can I achieve this? early replys would be appreciated. Please help me out Thank you very much Saritha
|
 |
Saritha Penumudi
Ranch Hand
Joined: Aug 18, 2003
Posts: 146
|
|
|
I guess this is very common req. And Who have very good exp with struts can answer my question. Please help me
|
 |
Kim Lilienfeld
Greenhorn
Joined: Apr 13, 2004
Posts: 25
|
|
The simplest solution to your problem that I have used is to add the id to the end of the link.. so that the link may look something like http://host:8080/webapp/MyAction.do?id=234&action=delete ..This is how I do that (just formatted in a table): <logic:iterate id="elem" name="collectionName" type="com.mypackage.whatever.ObjectTypeVO"> <tr> <td align="center" height="20"> [<a href="MyAction.do?id=<bean:write name='elem' property='objectIdVariableName'/>&action=delete">Delete</a>] </td> <td align="center"> <bean:write name="elem" property="someDisplayField"/> </td> <td align="center"> <bean:write name="elem" property="someOtherDisplayField"/> </tr> </logic:iterate> You can obviously leave out the &action=whatever bit if you don't need it but it is especially useful when they have the option of viewing or updating or deleting at the same place! Hope this helps! K
|
 |
Saritha Penumudi
Ranch Hand
Joined: Aug 18, 2003
Posts: 146
|
|
Hi Kim Lilienfeld, Thank you very much. It worked. Instead of usign <html:link> i have used <a href=""> and it worked. Thank you Saritha
|
 |
madhavi thallam
Greenhorn
Joined: Jun 08, 2012
Posts: 2
|
|
Hi,
This is solution will use for my application.
I am new to struts please any one help me how to access the id in action class
Thanks
Madhavi thallam
|
 |
madhavi thallam
Greenhorn
Joined: Jun 08, 2012
Posts: 2
|
|
madhavi thallam wrote:Hi,
This solution is very useful to my application as I am suffering with the same problem but how to access the id which you set in jsp in action class.
I am new to struts please any one help me how to access the id in action class
please reply me ASAP.
Thanks
Madhavi thallam
|
 |
 |
|
|
subject: Setting value of java variable to hidden field
|
|
|