aspose file tools*
The moose likes Struts and the fly likes how to start an action from a link... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to start an action from a link..." Watch "how to start an action from a link..." New topic
Author

how to start an action from a link...

hans meiser
Greenhorn

Joined: Dec 29, 2008
Posts: 22
Hello!

I have a problem, i have a struts output on my jsp page. for example:

<table>
<s:iterator value="problemVector">
<tr>
<td>
<s roperty value="problemNumber"/>
<s roperty value="problemTitle"/>
<s roperty value="problemDescription"/>
</td>
</tr>
</s:iterator>
</table>

now i would like to display the "problemNumber" as a link, where the User can click on. With this click a new Action should start. How can i do that? and if i would like to use this "problemNumber" value in the following action, how can i access it?

Thank you, for your help!
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057


Additional javascript function and hidden form variable.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
For the 'html' namespace I used above, I use:

hans meiser
Greenhorn

Joined: Dec 29, 2008
Posts: 22
thank you very much!

any idea, why :

<html:hidden property="problemNumber" value="" />

the html:hidden Tag is "unknown Tag"
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Mine is used on Struts 1.x. The namespace is the one I posted above.

What Struts version are you using?

Just use whatever you use on hidden form fields.
hans meiser
Greenhorn

Joined: Dec 29, 2008
Posts: 22
i am using struts 2.

if i change the tag to:

<s:hidden property="problemNumber" value="" />

the problem is, that property is not defined...

Im new into this, so i dont really see the problem, thanks for your help..
[ December 31, 2008: Message edited by: hans meiser ]
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
You have to add that problemNumber in your class.

Define it just like any other form fields in your Struts 2 action class.

Like


[ December 31, 2008: Message edited by: Jesus Angeles ]
hans meiser
Greenhorn

Joined: Dec 29, 2008
Posts: 22
<action name="Customer_Ticket_Page_Load_From_Overview"
class="de.bamos.ticketsystem.struts.data.CustomerProblemDetailLoad" method="loadFromOverview">
<result name="success">/WEB-INF/jsp/pages/CustomerTicketPage.jsp</result>
<result name="error">/WEB-INF/jsp/pages/Error.jsp</result>
</action>



this is my action...


now how exactly do i have to call it?


<script type="text/javascript" language="javascript">
function goToCase(selectedProblemNumber)
{
document.forms[0].problemNumber.value = selectedProblemNumber;
document.forms[0].action = '<%=request.getContextPath()%>/Customer_Ticket_Page_Load_From_Overview';
document.forms[0].submit();
}
</script>



in this Customer_Ticket_Page_Load_From_Overview Actin class, i will define the problemNumber right?
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Define the phoneNumber in the de.bamos.ticketsystem.struts.data.CustomerProblemDetailLoad class.

For how to call, try



without the request path thing.
hans meiser
Greenhorn

Joined: Dec 29, 2008
Posts: 22
nothing happens if i click on the link...
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
One way, try

in the javascript



meaning, add the 'action' extension.

If that doesnt work, try below. Below is easier and I actually did on struts 2. (I should have given you this before. The one above is one that I used on struts 1.x; and I thought it would work on struts 2 also).



Note, on the above:
- no javascript
- no hidden variable
- as in first way, add the problemNumber in the action class
[ December 31, 2008: Message edited by: Jesus Angeles ]
hans meiser
Greenhorn

Joined: Dec 29, 2008
Posts: 22
Ok, the second version works perfect!

Thank you very very much for your help, you saved my day! and the rest of the old year
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Ok. You're welcome. The first one is from my struts 1.x project. I just tried to fit into your struts 2 code but didnt make it. The second one I gave you is from my struts 2 project.

Im glad it worked for you.
[ December 31, 2008: Message edited by: Jesus Angeles ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to start an action from a link...