0

i am new to portlet and I have a visit.jsp page with an href tag as follows:

<a href="www.randomUrl.com">Visit ....</a>

Basically my requirement is that i just have to call a method called methodVisit in a VisitController.java when i click on the href and return back to visit.jsp. Then in my methodVisit add an attribute called isVisited to my model and return to my visit.jsp page so my method will have the following line i guess:

VisitController.java
public .. methodVisit(...){
model.addAttribute("isVisited", isVisited));
}

Then when i return on my visit.jsp page i can use this check:

<c:if test="${isVisited}"> 
Then display this line when href  is clicked from visit.jsp page
</c:if>

I have seen the following example when submit button is used:

<portlet:actionURL var="returnToSearchUrl" >
    <portlet:param name="ActController" value="returnToSearch" />
</portlet:actionURL>


    <input type="button" class="button" value='<spring:message code="button.returSearch" />' onclick="self.location='${returnToSearchUrl}'"/>




@ActionMapping(params = "ActController=returnToSearch")
    public void returnToSearch(){

    ......
    }

However no example when using the href one, any advice how to do it with href please?

user1999453
  • 1,297
  • 4
  • 29
  • 65

2 Answers2

0

try this:

<a href = "${pageContext.request.contextPath}/methodVisit">Click here!</a>

@Controller
@RequestMapping(value ="/pathtoyourproject")
public class VisitController{

@RequestMapping(value = "/methodVisit")
public ModelAndView methodVisit(...){
ModelAndView mav = new ModelAndVew();
...
mav.addAttribute("isVisited", isVisited);
...
mav.setViewName("visit.jsp");
return mav;

}
kyla
  • 396
  • 1
  • 8
0

Why not to use Ajax and update the link once the Ajax request is completed?

var visitLink = $("a:contains('Visit')");
$(visitLink).click(function(event) {
        $.ajax({
                    url:"www.randomUrl.com",
                    success: function() {
                    $(visitLink).hide();
                }
        });
        event.preventDefault();
});
Ajinkya
  • 22,324
  • 33
  • 110
  • 161