aspose file tools*
The moose likes Struts and the fly likes How do iknow whether a link was clicked or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How do iknow whether a link was clicked or not" Watch "How do iknow whether a link was clicked or not" New topic
Author

How do iknow whether a link was clicked or not

Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
hii guyzz..

am using <html:link property="go">Go</Html:link> how do i know whether this link was pressed or not..

I have a ActionForm class with the coresponding get and set methods...


anil
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The property attribute of an <html:link> tag works completely differently than the property attribute of any other <html:xxx> tag. It does not update the ActionForm bean in any way, and it does not indicate whether the link was clicked or not. The Struts documentation defines this property as:
The name of a property of the bean specified by the name attribute, whose return value must be a java.util.Map containing the query parameters to be added to the hyperlink. You must specify the name attribute if you specify this attribute.

Also, remember that clicking on a hyperlink does not cause the form to be submitted, but simply calls another URI.


Merrill
Consultant, Sima Solutions
Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
hii,


can i get a sample code of how to identify which link was clicked..

anil
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
My suggestion would be to include a parameter in the link itself to tell where it came from. Example:
mo sayed
Ranch Hand

Joined: Jan 25, 2006
Posts: 88
Merrill,



How would you do this for a forward such as

<html:link forward="forwardToWhateverPage">whatever</html:link>

kind regards,
Mo


<a href="http://moongrails.blogspot.com/" rel="nofollow">grails</a>
Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
Hi guyzz

thanks for the solution i passed a parameter in the link and retrieved the value in the corresponding action class....


i have another problem now its that i have to generate some drop downs dynamically ...ie to add values from the database itself..
What i did was that i created an action class for the home page and pointed all my links to the home page.. here i got the values from the database and populated an arraylist with these values..
my problem is i can run the application the first time properly but if i try to access the same page twice the drop downs will have the same values added twice and would keep on increasing....

i know its the problem with my session variable...how do i control it

Anil
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by mo sayed:

How would you do this for a forward such as

<html:link forward="forwardToWhateverPage">whatever</html:link>


In this case, you'd use a combination of paramId and paramName to add a parameter to the forward. See the heading "link" in this link for more details.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Anil Verghese:
i have another problem now its that i have to generate some drop downs dynamically ...ie to add values from the database itself..
What i did was that i created an action class for the home page and pointed all my links to the home page.. here i got the values from the database and populated an arraylist with these values..
my problem is i can run the application the first time properly but if i try to access the same page twice the drop downs will have the same values added twice and would keep on increasing....

i know its the problem with my session variable...how do i control it

Anil,

Whenever you have an issue that is completely different than the issue your post was originally about, in the future we would appreciate it if you would post it in a new thread. It makes it easier for other developers to search the forum if we keep to the "one thread/one topic" rule.

In answer to your question, I'd suggest using a "lazy initialization" technique. By that, I mean check to see if the collection is null. If it is, create it. If it isn't, do nothing. Example:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do iknow whether a link was clicked or not