You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by brazz <al...@man.eu> on 2011/08/08 08:18:02 UTC

custom (non wicket) modal dialog. Problem with urls.

Hello everyone, 

in our project i have to use our own modal dialog (application is included
in a portal). I have to open the dialog with the help of a javascript
function which is wrapped in a Behaviour. What i am doing now:

- in the constructor of my response page i call the javascript function via
a behaviour, so that immediately after the responsepage is rendered, the
javascript function gets called and the modal dialog opens.
- the javascript funtion accepts a url of the page that will be included in
the dialog.

In order to get the url i'm doing the this:

URL for Page in Modal Dialog:
ServletWebRequest servletWebRequest = (ServletWebRequest) comp
				.getRequest();
		HttpServletRequest request = servletWebRequest.getHttpServletRequest();
		String path = Strings.stripJSessionId(request.getRequestURI());
		CharSequence urlFor = comp.urlFor(targetPageClass, params);
		String contextRelativePath = path + urlFor;


Behaviour for opening the Modal Dialog:

public class OpenModalDialogBehaviour extends AbstractDefaultAjaxBehavior {

	private static final long serialVersionUID = -127624955452459934L;

	private String url;

	public OpenModalDialogBehaviour(String url) {
		this.url = url;
	}

	@Override
	protected void onComponentTag(ComponentTag tag) {
		super.onComponentTag(tag);
		ASPSession session = (ASPSession) ASPSession.get();
		String js = "{if(" + session.isShowModalDialog() + "){top.showForm('"
				+ url + " + ');}}";
		tag.append("onload", js , " ");
		session.setShowModalDialog(false);
	}

	@Override
	protected void respond(AjaxRequestTarget target) {
		System.out.println("respond");
	}
}

Now, my problem is, that the response page is the page in the background
(deactivated by the modal-dialog-javascript- function), not the page of the
modal dialog. Therefore the links in the page of my modal dialog are dead
(the onclick functions never get called). 

What i need is some trick to calculate and set the urls for my modal dialog
page manually, but i have no clue how to do this. Or maybe there is a much
simpler solution?

Thanks for any suggestions!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/custom-non-wicket-modal-dialog-Problem-with-urls-tp3726196p3726196.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: custom (non wicket) modal dialog. Problem with urls.

Posted by brazz <al...@man.eu>.
Hi, 

thank you very much for your answer. It's correct till number 3.
The link in the modal dialog has to be a resourcelink, which loads a pdf
document from the server. I cannot use an external link because there is a
firewall between user and document server (therefore i have to open an
http-connection on the server). My problem is that neither the getData()
method of the ResourceState nor the onclick() method of the link gets called
because the response page ist the page in the background and not the page in
the modal dialog where the links reside . Here's the code for my link. I
have tested it and it works outside of the modal dialog, no problem with
that. So i think the problem is really that i don't get callback messages
from wicket in my links because the page with the links is not the response
page. 


	private ResourceLink<Void> createResourceLink(
			final Link serviceInfoLink, String labelId, String linkId) {
			final ASPDynamicResource resource = new
ASPDynamicResource(URLUtil.extractFileName(serviceInfoLink.getUrl())){
			private static final long serialVersionUID = 1L;

			@Override
			public String getContentType() {
				return "application/pdf";
			};
			
			@Override
			public String getUrl() {
				return serviceInfoLink.getUrl();
			};
			
		};
		ResourceLink<Void> resourceLink = new ResourceLink<Void>(linkId, resource)
{
			@Override
			public void onClick() {
				if(resource.isResourceAvailable()){
					log.error("Resource with name: " + serviceInfoLink.getUrl()  + "is not
available");
				}
				super.onClick();
			}
			private static final long serialVersionUID = 192187593624907520L;
			
		};
		resourceLink.add(new Label(labelId, serviceInfoLink.getName()));
		return resourceLink;
	}

public abstract class ASPDynamicResource extends DynamicWebResource {

	private static final long serialVersionUID = -4500556464921243755L;
	
	private Log log = LogFactory.getLog(ASPDynamicResource.class);
	
	public ASPDynamicResource(String id){
		super(id);
	}

	@Override
	protected ResourceState getResourceState() {
		return new ASPResourceState();
	}
	
	private class ASPResourceState extends ResourceState {
	       
        public String getContentType() {
            return ASPDynamicResource.this.getContentType();
        }
       
        public byte[] getData() {
        	URLReader urlReader = URLReader.newInstance();
            try {
				return urlReader.getBytes(urlReader.webProxyUrl(getUrl()));
			} catch (MalformedURLException e) {
				log.error(e);
			} catch (Exception e) {
				log.error(e);
			}
			return null;
        }
    }
	
	public boolean isResourceAvailable() {
		URLTester urlTester = URLTester.newInstance();
		try {
			return urlTester.isReachable(urlTester.webProxyUrl(getUrl()));
		} catch (MalformedURLException e) {
			log.error(e);
			return false;
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	public abstract String getUrl();
	
	public abstract String getContentType();
	
}

public abstract class ASPDynamicResource extends DynamicWebResource {

	private static final long serialVersionUID = -4500556464921243755L;
	
	private Log log = LogFactory.getLog(ASPDynamicResource.class);
	
	public ASPDynamicResource(String id){
		super(id);
	}

	@Override
	protected ResourceState getResourceState() {
		return new ASPResourceState();
	}
	
	private class ASPResourceState extends ResourceState {
	       
        public String getContentType() {
            return ASPDynamicResource.this.getContentType();
        }
       
        public byte[] getData() {
        	URLReader urlReader = URLReader.newInstance();
            try {
				return urlReader.getBytes(urlReader.webProxyUrl(getUrl()));
			} catch (MalformedURLException e) {
				log.error(e);
			} catch (Exception e) {
				log.error(e);
			}
			return null;
        }
    }
	
	public boolean isResourceAvailable() {
		URLTester urlTester = URLTester.newInstance();
		try {
			return urlTester.isReachable(urlTester.webProxyUrl(getUrl()));
		} catch (MalformedURLException e) {
			log.error(e);
			return false;
		} catch (Exception e) {
			log.error(e);
			return false;
		}
	}
	
	public abstract String getUrl();
	
	public abstract String getContentType();
	
}

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/custom-non-wicket-modal-dialog-Problem-with-urls-tp3726196p3729050.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: custom (non wicket) modal dialog. Problem with urls.

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
Hi,

I'm not sure I have fully understood your situation. You should have:

1- a page which opens a modal dialog via Javascript
2- another page which is rendered inside modal dialog
3- in this last page (the one inside modal window) you want a link to 
the page in background (the starting page)

Is this right?

Couldn't you get the url of target page using the same code used for 
modal dialog page? i.e.:

comp.urlFor(TargetPageClass.class, params);


> Hello everyone,
>
> in our project i have to use our own modal dialog (application is included
> in a portal). I have to open the dialog with the help of a javascript
> function which is wrapped in a Behaviour. What i am doing now:
>
> - in the constructor of my response page i call the javascript function via
> a behaviour, so that immediately after the responsepage is rendered, the
> javascript function gets called and the modal dialog opens.
> - the javascript funtion accepts a url of the page that will be included in
> the dialog.
>
> In order to get the url i'm doing the this:
>
> URL for Page in Modal Dialog:
> ServletWebRequest servletWebRequest = (ServletWebRequest) comp
> 				.getRequest();
> 		HttpServletRequest request = servletWebRequest.getHttpServletRequest();
> 		String path = Strings.stripJSessionId(request.getRequestURI());
> 		CharSequence urlFor = comp.urlFor(targetPageClass, params);
> 		String contextRelativePath = path + urlFor;
>
>
> Behaviour for opening the Modal Dialog:
>
> public class OpenModalDialogBehaviour extends AbstractDefaultAjaxBehavior {
>
> 	private static final long serialVersionUID = -127624955452459934L;
>
> 	private String url;
>
> 	public OpenModalDialogBehaviour(String url) {
> 		this.url = url;
> 	}
>
> 	@Override
> 	protected void onComponentTag(ComponentTag tag) {
> 		super.onComponentTag(tag);
> 		ASPSession session = (ASPSession) ASPSession.get();
> 		String js = "{if(" + session.isShowModalDialog() + "){top.showForm('"
> 				+ url + " + ');}}";
> 		tag.append("onload", js , " ");
> 		session.setShowModalDialog(false);
> 	}
>
> 	@Override
> 	protected void respond(AjaxRequestTarget target) {
> 		System.out.println("respond");
> 	}
> }
>
> Now, my problem is, that the response page is the page in the background
> (deactivated by the modal-dialog-javascript- function), not the page of the
> modal dialog. Therefore the links in the page of my modal dialog are dead
> (the onclick functions never get called).
>
> What i need is some trick to calculate and set the urls for my modal dialog
> page manually, but i have no clue how to do this. Or maybe there is a much
> simpler solution?
>
> Thanks for any suggestions!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/custom-non-wicket-modal-dialog-Problem-with-urls-tp3726196p3726196.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: custom (non wicket) modal dialog. Problem with urls.

Posted by brazz <al...@man.eu>.
Could also be that it is a problem with iframes, because the Wicket page (in
the modal dialog, which is a div) gets opened in the top iframe with
top.showForm(...).



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/custom-non-wicket-modal-dialog-Problem-with-urls-tp3726196p3732156.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: custom (non wicket) modal dialog. Problem with urls.

Posted by brazz <al...@man.eu>.
Problem is solved now:

i extract the application-relative-path with:

String path = Strings.stripJSessionId(request.getRequestURI());

the trick is to overwrite method "onComponentTag(ComponentTag tag)" of class
ResourceLink and prepend  the application -relative path so i end up with
e.g.:

/mybaseurl/mypath/?wicket:interface=:85:border:_body:dialogContainer:contentPanels:infoTextContentPanel:externalLinks:0:externalLink::IResourceListener:: 

complete code:

public class CustomResourceLink extends ResourceLink<Void> {
	
	private static final long serialVersionUID = -4848428865939435963L;
	
	private boolean applicationRelative = false;
	
	private PopupSettings popupSettings = null;
	
	public CustomResourceLink (String id, Resource resource) {
		super(id, resource);
	}

	@Override
	protected void onComponentTag(ComponentTag tag)
	{
		super.onComponentTag(tag);

		if (isLinkEnabled() == false)
		{
			disableLink(tag);
		}
		else
		{
			if (getURL() != null)
			{
				String url = getURL().toString();

				if (applicationRelative)
				{
					if (url.length() > 0 && url.charAt(0) == '/')
					{
						url = url.substring(1);
					}
					
					url = RequestUtils.getBaseUrl(this) + url;
				}

				// if the tag is an anchor proper
				if (tag.getName().equalsIgnoreCase("a") ||
tag.getName().equalsIgnoreCase("link") ||
					tag.getName().equalsIgnoreCase("area"))
				{
					// generate the href attribute
					tag.put("href", Strings.replaceAll(url, "&", "&amp;"));

					// Add any popup script
					if (popupSettings != null)
					{
						// NOTE: don't encode to HTML as that is not valid
						// JavaScript
						tag.put("onclick", popupSettings.getPopupJavaScript());
					}
				}
				else
				{
					// generate a popup script by asking popup settings for one
					if (popupSettings != null)
					{
						popupSettings.setTarget("'" + url + "'");
						String popupScript = popupSettings.getPopupJavaScript();
						tag.put("onclick", popupScript);
					}
					else
					{
						// or generate an onclick JS handler directly
						tag.put("onclick", "window.location.href='" + url + "';return
false;");
					}
				}
			}

			if (popupSettings != null)
			{
				IPageMap popupPageMap = popupSettings.getPageMap(this);
				if (popupPageMap != null && popupPageMap.getName() != null)
				{
					tag.put("target", popupPageMap.getName());
				}
			}
		}
	}
	
	public void setApplicationRelative(boolean contextRelative) {
		this.applicationRelative = contextRelative;
	}
}

public class RequestUtils {
        public static String getBaseUrl(Component comp) {
		ServletWebRequest servletWebRequest = (ServletWebRequest) comp
				.getRequest();
		HttpServletRequest request = servletWebRequest.getHttpServletRequest();
		String path = Strings.stripJSessionId(request.getRequestURI());
		return path;
	}
}

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/custom-non-wicket-modal-dialog-Problem-with-urls-tp3726196p3735554.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: custom (non wicket) modal dialog. Problem with urls.

Posted by brazz <al...@man.eu>.
One step further. My original assumption was wrong. It is a problem with
iframes and the configuration of our firewall. But the situation hasn't
improved.

The url of the link is:

?wicket:interface=:85:border:_body:dialogContainer:contentPanels:infoTextContentPanel:externalLinks:0:externalLink::IResourceListener::

Now i have to prepend my  servlet path e.g. /mybaseurl/mypath to the
relative url of the link, e.g.:

/mybaseurl/mypath/?wicket:interface=:85:border:_body:dialogContainer:contentPanels:infoTextContentPanel:externalLinks:0:externalLink::IResourceListener::

FurtherMore i need an Ajax-ResourceLink (which i think doesn't exist by
now). 

Any suggestions would be greatly appreciated!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/custom-non-wicket-modal-dialog-Problem-with-urls-tp3726196p3733218.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org