Re: AJAX updating table row

2012-11-30 Thread Geoff Callender
In onDeactivate(Long serviceID), get the service! Tapestry is trying to render 
the row so it can send it back in the response - so it needs the service.

Cheers,

Geoff

On 01/12/2012, at 4:01 AM, Pillar wrote:

> Hey! Always more questions!
> 
> I'm following this example:  Ajax EventLinks in a Loop
> <http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/eventlinksinaloop>
>  
> . I've modified some code to fit my use case. I have a table that uses a
> t:loop to iterate through services and show if they are activated. I then
> have eventlinks to activate/deactivate services. My server code writes to a
> database based on the eventlink clicked. Here are parts of the code (dunno
> how to post html):
> 
>
> <(tr) t:type = "Zone" t:id = "rowZone" id = "currentRowZoneId" t:update =
> "show">
> <(td)>${service.name}<(/td)>
> <(a) t:type = "eventlink" t:event = "deactivate" t:context =
> "service.serviceID" t:zone = "^" href = "#">Deactivate<(/a)>
> 
> My java:
> 
>   private List services;
>   
>   @InjectComponent
>   private Zone rowZone;
>   
>   @Inject
>   private Request request;
>   
>   @Inject
>   private AjaxResponseRenderer ajaxResponseRenderer;
>   
>   @Property
>   private Service service;
>   
>   void setupRender() {
>   services = getServices();
>   }
>   
>   public boolean getIsActivated() {
>   User u = getUser();
>   for (UserService us : u.getUserServices()) {
>   if (us.getService().getServiceID() == 
> service.getServiceID())
>   return true;
>   }
>   return false;
>   }
> 
>   public List getServices() {
>   if (services == null) {
>   services = serviceDao.findAll();
>   }
>   return services;
>   }
>   
>   public void onDeactivate(Long serviceID) {
>   UserService us = 
> userServiceDao.findByUserIdAndServiceId(currentUserID,
> serviceID);
>   userServiceDao.delete(us.getUserserviceID());   
>   
>   if (request.isXHR()) {
>   ajaxResponseRenderer.addRender(rowZone);
>   }
>   }
>   
>   public String getCurrentRowZoneId() {
>   return "rowZone_" + service.getServiceID();
>   }
> 
> So when the eventlink is clicked, the onDeactivate() method gets called with
> serviceID as context. This removes the userservice from the db and calls
> addRender() on the rowZone. I immediately get this error:
> 
> Render queue error in Expansion[PropBinding[expansion
> service/ActivationAjax(service.name)]]: Property 'service' (within property
> expression 'service.name', of
> org.synchronica.example.pages.service.ServiceActivationAjax@53e1b8fb) is
> null.
> 
> Since ajax is only making the specific row to update, we aren't looping
> again so how does it know which service (thus NPE)? In the tutorial I posted
> above, it works fine. Any ideas?
> 
> 
> 
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/AJAX-updating-table-row-tp5718433.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


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



Re: AJAX updating table row

2012-11-30 Thread Paul Stanton
each ajax request is still a new request and therefore properties in 
your page class are lost from the previous render.


unless you mark them as @Persist.

but in your case, your `service` property is set by the loop component. 
this is not going to be "emmulated" by the ajax request processing since 
you are just updating the 'insides' of one iteration of the loop.


you will need to use your context parameters or some other mechanism to 
set your "service" value for each subsequent ajax request.


p.

On 1/12/2012 4:01 AM, Pillar wrote:

Hey! Always more questions!

I'm following this example:  Ajax EventLinks in a Loop
<http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/eventlinksinaloop>
. I've modified some code to fit my use case. I have a table that uses a
t:loop to iterate through services and show if they are activated. I then
have eventlinks to activate/deactivate services. My server code writes to a
database based on the eventlink clicked. Here are parts of the code (dunno
how to post html):


<(tr) t:type = "Zone" t:id = "rowZone" id = "currentRowZoneId" t:update =
"show">
<(td)>${service.name}<(/td)>
<(a) t:type = "eventlink" t:event = "deactivate" t:context =
"service.serviceID" t:zone = "^" href = "#">Deactivate<(/a)>

My java:

private List services;

@InjectComponent
private Zone rowZone;

@Inject
private Request request;

@Inject
private AjaxResponseRenderer ajaxResponseRenderer;

@Property
private Service service;

void setupRender() {
services = getServices();
}

public boolean getIsActivated() {
User u = getUser();
for (UserService us : u.getUserServices()) {
if (us.getService().getServiceID() == 
service.getServiceID())
return true;
}
return false;
}

public List getServices() {
if (services == null) {
services = serviceDao.findAll();
}
return services;
}

public void onDeactivate(Long serviceID) {
UserService us = 
userServiceDao.findByUserIdAndServiceId(currentUserID,
serviceID);
userServiceDao.delete(us.getUserserviceID());   

if (request.isXHR()) {
ajaxResponseRenderer.addRender(rowZone);
}
}

public String getCurrentRowZoneId() {
return "rowZone_" + service.getServiceID();
}

So when the eventlink is clicked, the onDeactivate() method gets called with
serviceID as context. This removes the userservice from the db and calls
addRender() on the rowZone. I immediately get this error:

Render queue error in Expansion[PropBinding[expansion
service/ActivationAjax(service.name)]]: Property 'service' (within property
expression 'service.name', of
org.synchronica.example.pages.service.ServiceActivationAjax@53e1b8fb) is
null.

Since ajax is only making the specific row to update, we aren't looping
again so how does it know which service (thus NPE)? In the tutorial I posted
above, it works fine. Any ideas?



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/AJAX-updating-table-row-tp5718433.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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





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



AJAX updating table row

2012-11-30 Thread Pillar
Hey! Always more questions!

I'm following this example:  Ajax EventLinks in a Loop
<http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/eventlinksinaloop>
 
. I've modified some code to fit my use case. I have a table that uses a
t:loop to iterate through services and show if they are activated. I then
have eventlinks to activate/deactivate services. My server code writes to a
database based on the eventlink clicked. Here are parts of the code (dunno
how to post html):

   
<(tr) t:type = "Zone" t:id = "rowZone" id = "currentRowZoneId" t:update =
"show">
<(td)>${service.name}<(/td)>
<(a) t:type = "eventlink" t:event = "deactivate" t:context =
"service.serviceID" t:zone = "^" href = "#">Deactivate<(/a)>

My java:

private List services;

@InjectComponent
private Zone rowZone;

@Inject
private Request request;

@Inject
private AjaxResponseRenderer ajaxResponseRenderer;

@Property
private Service service;

void setupRender() {
services = getServices();
}

public boolean getIsActivated() {
User u = getUser();
for (UserService us : u.getUserServices()) {
if (us.getService().getServiceID() == 
service.getServiceID())
return true;
}
return false;
}

public List getServices() {
if (services == null) {
services = serviceDao.findAll();
}
return services;
}

public void onDeactivate(Long serviceID) {
UserService us = 
userServiceDao.findByUserIdAndServiceId(currentUserID,
serviceID);
userServiceDao.delete(us.getUserserviceID());   

if (request.isXHR()) {
ajaxResponseRenderer.addRender(rowZone);
}
}

public String getCurrentRowZoneId() {
return "rowZone_" + service.getServiceID();
}

So when the eventlink is clicked, the onDeactivate() method gets called with
serviceID as context. This removes the userservice from the db and calls
addRender() on the rowZone. I immediately get this error:

Render queue error in Expansion[PropBinding[expansion
service/ActivationAjax(service.name)]]: Property 'service' (within property
expression 'service.name', of
org.synchronica.example.pages.service.ServiceActivationAjax@53e1b8fb) is
null.

Since ajax is only making the specific row to update, we aren't looping
again so how does it know which service (thus NPE)? In the tutorial I posted
above, it works fine. Any ideas?



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/AJAX-updating-table-row-tp5718433.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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