betweenGo

Set ATG Property And Popup Window After Clicking on Link

by on Mar.26, 2010, under Page Development

la cuarta ventana on Flickrla cuarta ventana by bachmont 

Sometimes when you click on a link in an ATG JSP/DSP page you want a property of an ATG component to be set as well.  For example:

<dsp:a href="foo.jsp">Foo
  <dsp:property bean="BarFormHandler.baz" paramvalue="index"/>
</dsp:a>

What gets tricky is if you also want a popup window to display the contents of this link.

The Wrong Way

I tried adapting the instructions from the tutorial Popup Windows | open new customised windows with JavaScript.

<dsp:a href="javascript:poptastic('foo.jsp');">Foo
  <dsp:property bean="BarFormHandler.baz" paramvalue="index"/>
</dsp:a>

This does not work, i.e. the setter for baz in BarFormHandler is never called.

The Brute Force Way

I then reverted to the original DSP and looked at the outputted HTML.  Based on that I updated the DSP like this.

<% atg.servlet.DynamoHttpServletRequest dreq = atg.servlet.ServletUtil.getCurrentRequest(); %>
<a href="javascript:poptastic('foo.jsp?_DARGS=/betweengo/test.jsp_AF&_dynSessConf=<%= dreq.getSessionConfirmationNumber() %>&_D%3A/betweengo/BarFormHandler.baz=+&/betweengo/BarFormHandler.baz=<dsp:valueof param="index" />');">Foo</a>

This works but is grotesque.

The Good Idea That Did Not Work

Then I realized I could just set a parameter in the URL and have the form handler use the value to set the property.

<a href="javascript:poptastic('foo.jsp?index=<dsp:valueof param="index" />');">Foo</a>

And in BarFormHandler

public boolean beforeSet(DynamoHttpServletRequest req,
            DynamoHttpServletResponse res) throws DropletFormException {

  String indexParam = request.getParameter("index");
  setIndex(Integer.parseInt(indexParam));

  return super.beforeSet(request, response);
}

This did not work plus I did not really like it because now I have a beforeSet method that is called for every single request.

The Winner

I then realized I did not read the tutorial Popup Windows | open new customised windows with JavaScript carefully.  There is a more elegant way to call the JavaScript which degrades gracefully for browsers that don’t support JavaScript.

<dsp:a href="foo.jsp" onclick="poptastic(this.href);return false;">Foo
  <dsp:property bean="BarFormHandler.baz" paramvalue="index"/>
</dsp:a>

This works, is elegant and requires just adding the onclick attribute to the original DSP.


Share

Related posts:

  1. How to Set an Array Property in an ATG Form
  2. Submitting an ATG Form Using a Text Link
  3. ATG Currency Converter Not Working With JSTL c:set
  4. The Strangely Behaved ATG textarea Tag
  5. user-defined property type gotcha’s

:,

Leave a Reply

 

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!