You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Carlos Montero Canabal <ca...@gmail.com> on 2015/09/14 12:11:13 UTC

Handling a bad context and component events

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

Re: Handling a bad context and component events

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 14 Sep 2015 07:11:13 -0300, Carlos Montero Canabal  
<ca...@gmail.com> wrote:

> Hi,

Hi!

I'd say the recommended way of dealing with ma dynamic list of activation  
context values is to use a single onActivate(EventContenxt context) method  
and no other onActivate() methods.

By the way, if you just want to let rendering continue (i.e. not  
redirecting), return null instead of Boolean.TRUE.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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