tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Montero Canabal <carlosmonterocana...@gmail.com>
Subject Handling a bad context and component events
Date Mon, 14 Sep 2015 09:57:05 GMT
Hi,

I would like to know if I develop the best option to handle a bad context in my webapp.

I have a website (http://www.ryalive.com <http://www.ryalive.com/>) with a form where
you have to put various values. When you search, webapp redirect to http://page/arg0/arg1/arg2/arg3
<http://page/arg0/arg1/arg2/arg3> . I have an onActivate method with (pseudocode):

Object onActivate(arg0, arg1, arg2, arg3){

	if (arg0 == null)
		record error;

	if (arg1 == null || arg1 is not valid)
		record error

	…

	if (!errors.isEmpty())
		return IndexPage.class;

	else
		return Boolean.TRUE; // And then setupRender method is executed.

}

Problem: if a user remove some parameter from url, onActivate didn´t call it because does´t
match the number of parameters. So I program another method:

Object onActivate(EventContext ec){

	Object[] params = new Object[4];
	for(int i=0; i<ec.getcount(); i++){ 
		params[i] = ec.get(i);
	}
	
	return onActivate(params[0], params[1], params[2], params[3]);
}

It works very good. So I have a big problem. My page have a components and the onActivate(EventContext)
method is called every time for the component events with a emptycontextevent, so it produced
a redirection to IndexPage as a error, but it isn´t a error. My solution for last method
is:

@Inject
private ComponentEventLinkEncoder componentEventLinkEncoder;

@Inject
private Request request;

Object onActivate(EventContext ec){

	final ComponentEventRequestParameters eventParams = componentEventLinkEncoder.decodeComponentEventRequest(request);
    if (eventParams != null) {
	// This request is a request for a component => I don’t have to validate the params
	return Boolean.TRUE;
    }

	Object[] params = new Object[4];
	for(int i=0; i<ec.getcount(); i++){ 
		params[i] = ec.get(i);
	}
	
	return onActivate(params[0], params[1], params[2], params[3]);

}

It works perfect for me now, but… is the best option? I have other webapps with the same
problem and I would get a good solution.

Regards

Carlos Montero


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message