T5: page as application/json response

2008-10-07 Thread Waldo Mendoza
Hello

Is there any way to tell tapestry to render a entire page as JSON response? 
Currently there is a support like this for blocks and components, but i tried 
the following:

@ContentType("application/json")
public class TestPage {

}

But nothing happens, i want to get a json response, with .content, .scripts 
and .script properties as a part of the json object.

I am making an Ajax request, with prototype.

Thanks you


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Customizing grid sorting

2008-05-21 Thread Waldo Mendoza
Dan Adams  ifactory.com> writes:

> 
> There are two situations we hit often in our applications:
>  - disabling sorting for one specific column because it doesn't have a 
corresponding db column
>  - not allowing sorting by any of the columns because the data is sorted 
explicitly
> 
> In T4 with contrib:Table you could specify a list of colums like 
"foo,!bar,baz" and then "bar" wouldn't be
> sorted. How have others handled this in T5?
> 
> Dan Adams
> Senior Software Engineer
> Interactive Factory
> p: 617.235.5857
> 
> -
> To unsubscribe, e-mail: users-unsubscribe  tapestry.apache.org
> For additional commands, e-mail: users-help  tapestry.apache.org
> 
> 


Hello Dan!

I think you cannot do that using actual Grid parameters, but you can use the 
BeanModel API to disable sorting on specific properties, maybe a good place to 
make it is the setupRender phase method:

private BeanModel _model;

...

void setupRender()
{
  _model.get("name").sortable(false);
}




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: T5: accessing another page/component's message catalog

2008-04-24 Thread Waldo Mendoza
Adam Zimowski  gmail.com> writes:

> 
> Is there a way to access message catalog of some page or component
> from another page or component? I know of two ways to do this, but
> both are "hacks" IMHO:
> 
> class SomePage {
> 
> @Inject
> private Messages _messages;
> 
> public getMessages() {
>  return _messages;
> }
> }
> 
> class Foo {
> 
> @InjectPage
> private SomePage _page;
> 
> // now I can access messages from _page
> }
> 
> Above way is a pain because every page/component needs to explicitly
> expose message catalog for use by other page. Another way to do this
> would be to obtain page/component resource path, and do it
> old-fashioned way with java.util.Property - ughh... !
> 
> What I was looking for is some support by Messages, perhaps overriden
> method get(String key):
> 
> Messages.get(String resourcePath, String key)
> Messages.get(Class component, String key)
> 
> The thing is, that I need to read another componen't message catalog
> not knowing ahead of time what the comopnent is. I don't see a "clean"
> way of doing it at the moment, any ideas?
> 
> -adam
> 
> -
> To unsubscribe, e-mail: users-unsubscribe  tapestry.apache.org
> For additional commands, e-mail: users-help  tapestry.apache.org
> 
> 


Hello Adam

One posibility is to Inject ComponentSource and ComponentMessageSource, after 
that you can use ComponentSource to get the page by name, and use 
ComponentMessageSource to get the page Messages, something like:

private ComponentMessagesSource _componentMessageSource;

private ComponentSource _componentSource;

...
Component page = _componentSource.getPage("foo");
Messages messages = _componentMessageSource.getMessages(
page.getComponentResources().getComponentModel(), 
page.getComponentResources().getLocale()); 



Maybe it would be more clean to create a specific service that you can inject 
to your page.

Hope this helps.
Bye



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: T5: A component returning StreamResponse?

2007-10-10 Thread Waldo Mendoza
Sorry, forgot to mention that in WizardPage.tml should be a actionlink component
 

 
and the handler method should be
 
void onActionFromStepChanged(String toPage) {
  _currentPage = toPage;
}
 
The Ajax request can be done:
 
new Ajax.Request('/context/wizardpage.stepchanged/step2', {
  method: 'GET',
  onSuccess: function (t) {
  //really nothing to do here
  }
});

 
____

From: Waldo Mendoza [mailto:[EMAIL PROTECTED]
Sent: Wed 10/10/2007 11:44 AM
To: Tapestry users
Subject: RE: T5: A component returning StreamResponse?



Hi there!

Why not instead of a component the htmlFragment comes from a Page?, so in your 
javascript code, you can make a page request.

For example, in my Main Page:

class WizardPage {
  @Persist
  private String _currentPage;

  void onStepChanged(String toPage) {
_currentPage = toPage;
  }
}

Then the javascript code can use that property to render the actual step.

new Ajax.Request('GET', ${currentPage}, {
   onSuccess: function (transport) {
  var replaceElement = $(...);
  replaceElement.innerHTML = transport.responseText;
  //load scripts as necessary.
}
});

${currentPage} can be a string that the ComponentResources generates, just a 
detail that you already used.

And of course there should be a chain of pages to take in account.



From: Borut Bolcina [mailto:[EMAIL PROTECTED]
Sent: Wed 10/10/2007 7:01 AM
To: Tapestry
Subject: T5: A component returning StreamResponse?



Hello,

I would like to create an ajax dialog (actually a series of them to act as a
wizard). The content of the dialog should change according to user
interaction and therefore create a series of steps. If this wizard is going
to have 3 steps then 3 ajax requests for dialog content would be made.

I would like each ajax request to call (different) T5 component returning
HTML fragment.

I am using jQuery to make a request

* TEMPLATE **

$().ready(function() {
  $('#ex2').jqm({ajax: '${thelink}'}).jqmShow();
});


* CLASS *
public String getTheLink() {
Link l = _resources.createActionLink("myAction", false);
return l.toURI();
}

StreamResponse onMyAction() {
String htmlFragment = "paragraph bold";
return new TextStreamResponse("text/html", htmlFragment);
}


I would like the htmlFragment to be generated by T5 component for example
WizardStep1.

If I declare a component in the class above:
@Component
private WizardStep1 wizardStep1;

and modify method onMyAction like this

StreamResponse onMyAction() {
wizardStep1.setMessage("hello");
return (StreamResponse) wizardStep1;
}

then I get Exception:
Component ui/dialog/JQModalAjax does not contain an embedded component with
id 'wizardStep1'.

which is true, as I don't have WizardStep1 in my ui/dialog/JQModalAjax.tml


Any suggestions?






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

RE: T5: A component returning StreamResponse?

2007-10-10 Thread Waldo Mendoza
Hi there!
 
Why not instead of a component the htmlFragment comes from a Page?, so in your 
javascript code, you can make a page request.
 
For example, in my Main Page:
 
class WizardPage {
  @Persist
  private String _currentPage;
 
  void onStepChanged(String toPage) {
_currentPage = toPage;
  }
}
 
Then the javascript code can use that property to render the actual step.
 
new Ajax.Request('GET', ${currentPage}, {
   onSuccess: function (transport) {
  var replaceElement = $(...);
  replaceElement.innerHTML = transport.responseText;
  //load scripts as necessary.
}
});
 
${currentPage} can be a string that the ComponentResources generates, just a 
detail that you already used.

And of course there should be a chain of pages to take in account.
 


From: Borut Bolcina [mailto:[EMAIL PROTECTED]
Sent: Wed 10/10/2007 7:01 AM
To: Tapestry
Subject: T5: A component returning StreamResponse?



Hello,

I would like to create an ajax dialog (actually a series of them to act as a
wizard). The content of the dialog should change according to user
interaction and therefore create a series of steps. If this wizard is going
to have 3 steps then 3 ajax requests for dialog content would be made.

I would like each ajax request to call (different) T5 component returning
HTML fragment.

I am using jQuery to make a request

* TEMPLATE **

$().ready(function() {
  $('#ex2').jqm({ajax: '${thelink}'}).jqmShow();
});


* CLASS *
public String getTheLink() {
Link l = _resources.createActionLink("myAction", false);
return l.toURI();
}

StreamResponse onMyAction() {
String htmlFragment = "paragraph bold";
return new TextStreamResponse("text/html", htmlFragment);
}


I would like the htmlFragment to be generated by T5 component for example
WizardStep1.

If I declare a component in the class above:
@Component
private WizardStep1 wizardStep1;

and modify method onMyAction like this

StreamResponse onMyAction() {
wizardStep1.setMessage("hello");
return (StreamResponse) wizardStep1;
}

then I get Exception:
Component ui/dialog/JQModalAjax does not contain an embedded component with
id 'wizardStep1'.

which is true, as I don't have WizardStep1 in my ui/dialog/JQModalAjax.tml


Any suggestions?



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

RE: [T5] navigation component

2007-07-17 Thread Waldo Mendoza
Hello Ognen!
 
I have made some similar behavior for a past Tapestry version, i think 5.0.2, 
but the idea should be standard:
 
1.- Read the files inside the pages folder that is subfolder of 
tapestry.app-package init param, of course filtering with a FilenameFilter, 
instead of that you can build a Tree of pages.
2.- Those file names are candidates for the navigation, next you have to get 
the Page instance for each result in step 1. You can do it with the help of 
ComponentSource that tapestry provides (just inject that in your service), with 
the page instance in hand you have to ask if that instance has the annotation 
you want.
 
maybe this code can help:
 
 
 public Page getPage(String pageName)
 {
  Component page = null;
  try 
  {
   page = _componentSource.getPage(pageName);
   Navigation navigation = page.getClass().getAnnotation(Navigation.class);
   
   if (navigation != null)
   {
Messages messages = _componentMessageSource.getMessages(
  page.getComponentResources().getComponentModel(), 
page.getComponentResources().getLocale());

return new Page(pageName,messages.get(TITLE_KEY),navigation.needslogin()); 
   }
   else
   {
_log.debug("The page '" + pageName + "' is not annotated with the 
annotation '" + Navigation.class.getSimpleName() + "'");
return null;
   } 
  } 
  catch (IllegalArgumentException e) 
  {
   _log.debug("The page '" + pageName + "' has no title in it´s properties 
file");
   return null;
  }  
 }

 
This method takes the pageName as a parameter and returns a Page instance that 
is just a simple bean with name an title properties. This method is called by 
each candidate page that were collected by the method that reads the folder 
where the pages are. Note that the ComponentSource and ComponentMessagesSource 
were used.
 
One more think, when you call _componentSource.getPage(pageName); tapestry will 
create the instance of the page, as the documentation says that process is 
really involved and if you have a lot of pages the process will consume a lot 
of time, so it´s better to call this process on application start.

 


From: Ognen Ivanovski [mailto:[EMAIL PROTECTED]
Sent: Mon 7/16/2007 11:21 AM
To: Tapestry users
Subject: [T5] navigation component



Hi everyone,

I am trying to build up a T5 navigation component. The general idea is:

  - it should figure out the navigational tree based on the pages 
available around
  - Showing a page in the navigational component should be a matter 
of tagging a component with an annotation (@Navigable, or 
@ShowsInNavigation)
 - Additional info (i.e. display text, icon, etc..) also from 
annotation
- The grouping of pages should be based on sub packages in the *.pages)
- package-info.java would be used for annotating the groups (text, 
icons)



So here are the questions:

1) How can I iterate through all pages present in an app?

2) How can I access the annotations on a Page class. I saw the 
Component / ComponentModel interfaces but they do not offer access to 
the annotations. Perhaps the @Meta annotation can help here but I 
don't want to limit myself to strings.
   

--
Ognen Ivanovski | [EMAIL PROTECTED]
phone +389 -2- 30 64 532 | fax +389 -2- 30 79 495
Netcetera | 1000 Skopje | Macedonia | http://netcetera.com.mk 
 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

T5: Loop component fails

2007-02-13 Thread Waldo Mendoza
Hi there!

Congratulations to howard, tapestry 5 it´s really amazing and fun.

I have been trying the components that comes bundled with tapestry, and i got 
and exception with a Loop test.

The template is:

http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>

Loop Test




${number}





and the class:

public class Test
{

private int[] _numbers;

private int _number;

public int[] getNumbers()
{
return _numbers;
}

public int getNumber()
{
return _number;
}

public void setNumber(int number)
{
_number = number;
}

@SetupRender
void setupNumbers()
{
_numbers = new int[10];
for (int i = 0; i < _numbers.length; i++)
{
_numbers[i] = i;
}
}
}

The Exception is:

org.apache.tapestry.ioc.internal.util.TapestryException
Failure writing parameter value of component 
com.tierconnect.licence.pages.Test:loop: For input string: "[EMAIL PROTECTED]" 
location:
classpath:com/tierconnect/licence/pages/Test.html, line 7, column 55
java.lang.NumberFormatException
For input string: "[EMAIL PROTECTED]" 
Stack trace:
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Long.parseLong(Long.java:403)
java.lang.Long.(Long.java:671)
org.apache.tapestry.ioc.services.TapestryIOCModule$9.coerce(TapestryIOCModule.java:301)
org.apache.tapestry.ioc.services.TapestryIOCModule$9.coerce(TapestryIOCModule.java:299)
org.apache.tapestry.ioc.internal.services.CompoundCoercion.coerce(CompoundCoercion.java:47)
org.apache.tapestry.ioc.internal.services.CompoundCoercion.coerce(CompoundCoercion.java:47)
org.apache.tapestry.ioc.internal.services.TypeCoercerImpl.coerce(TypeCoercerImpl.java:138)
$TypeCoercer_110bb52dac4.coerce($TypeCoercer_110bb52dac4.java)
org.apache.tapestry.internal.structure.InternalComponentResourcesImpl.writeParameter(InternalComponentResourcesImpl.java:218)
org.apache.tapestry.corelib.components.Loop._$update_parameter_value(Loop.java)
org.apache.tapestry.corelib.components.Loop.begin(Loop.java:275)
org.apache.tapestry.corelib.components.Loop.beginRender(Loop.java)
org.apache.tapestry.internal.structure.ComponentPageElementImpl$10$1.run(ComponentPageElementImpl.java:339)
org.apache.tapestry.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:936)
org.apache.tapestry.internal.structure.ComponentPageElementImpl.access$000(ComponentPageElementImpl.java:68)
org.apache.tapestry.internal.structure.ComponentPageElementImpl$10.render(ComponentPageElementImpl.java:343)
org.apache.tapestry.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:57)
org.apache.tapestry.internal.services.PageMarkupRendererImpl.renderPageMarkup(PageMarkupRendererImpl.java:40)
$PageMarkupRenderer_110bb52db45.renderPageMarkup($PageMarkupRenderer_110bb52db45.java)
$PageMarkupRenderer_110bb52db40.renderPageMarkup($PageMarkupRenderer_110bb52db40.java)
org.apache.tapestry.internal.services.PageResponseRendererImpl.renderPageResponse(PageResponseRendererImpl.java:45)
$PageResponseRenderer_110bb52db41.renderPageResponse($PageResponseRenderer_110bb52db41.java)
$PageResponseRenderer_110bb52daec.renderPageResponse($PageResponseRenderer_110bb52daec.java)
org.apache.tapestry.internal.services.PageRenderDispatcher$1.renderPage(PageRenderDispatcher.java:78)
org.apache.tapestry.internal.services.PageLinkHandlerImpl.handle(PageLinkHandlerImpl.java:54)
org.apache.tapestry.internal.services.PageLinkHandlerImpl.handle(PageLinkHandlerImpl.java:39)
$PageLinkHandler_110bb52db1d.handle($PageLinkHandler_110bb52db1d.java)
$PageLinkHandler_110bb52db19.handle($PageLinkHandler_110bb52db19.java)
org.apache.tapestry.internal.services.PageRenderDispatcher.dispatch(PageRenderDispatcher.java:88)
$Dispatcher_110bb52db1b.dispatch($Dispatcher_110bb52db1b.java)


Maybe i am doing something wrong, but the same code works with the _numbers 
field as a array of Strings.

Thanks for your help, and again great job with Tapestry 5

Waldo

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]