You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by "florin.g" <fl...@bytenotes.com> on 2009/03/12 22:23:18 UTC

Unexpected #parse() behavior

Any hint would be much appreciated.

I'd like to include a page fragment using the velocity #parse() directive.
So, I got my Page ready, my template page as well, and it works. 

Then, I do a second one and it does not. If I load the fragment in the
browser it does work, /mypage.htm. Included via the #parse() method, it does
not. The debug logging does not show that the page is rendered, and the
$variables are not parsed, but displayed as simple text. 

I have no clue. 

On the other hand, I need more than the BorderPage idea. What I want is the
ability to make "components", or "portlets" that can be included in various
pages. For instance, I have a "user list" in at least three different pages
for different audiences and I want to reduce the amount of coding and
refactoring.

Thanks
-- 
View this message in context: http://n2.nabble.com/Unexpected--parse%28%29-behavior-tp2470163p2470163.html
Sent from the click-user mailing list archive at Nabble.com.


Re: Unexpected #parse() behavior

Posted by "florin.g" <fl...@bytenotes.com>.
Bob,

Here's why it did not work for me:

addModel("myString", "loaded"); 

According to the example in a post above, I added the form to the panel
inside the onInit method with the addModel("panel", panel) method and not
the addControl(form) method.

Thank you.


sabob wrote:
> 
> florin.g wrote:
>> 
>> I cannot get the onSubmit() action to execute.
>> 
>> A page contains a panel as described above. The form contained inside the
>> panel is rendered properly yet the onSubmit() action of the panel's form
>> is
>> not executed. Where would I find more example such as this?
> 
> 
> I've checked in a demo with a reusable panel for submitting client 
> details. You can review the demo here:
> 
> http://fisheye6.atlassian.com/changelog/click/?cs=754912
> 
> Let us know if you run into problems. It would also be interesting to 
> know why your Form did not fire the submit event.
> 
> kind regards
> 
> bob
> 
> 

-- 
View this message in context: http://n2.nabble.com/Unexpected--parse%28%29-behavior-tp2470163p2489283.html
Sent from the click-user mailing list archive at Nabble.com.


Re: Unexpected #parse() behavior

Posted by Bob Schellink <sa...@gmail.com>.
florin.g wrote:
> 
> I cannot get the onSubmit() action to execute.
> 
> A page contains a panel as described above. The form contained inside the
> panel is rendered properly yet the onSubmit() action of the panel's form is
> not executed. Where would I find more example such as this?


I've checked in a demo with a reusable panel for submitting client 
details. You can review the demo here:

http://fisheye6.atlassian.com/changelog/click/?cs=754912

Let us know if you run into problems. It would also be interesting to 
know why your Form did not fire the submit event.

kind regards

bob

Re: Unexpected #parse() behavior

Posted by "florin.g" <fl...@bytenotes.com>.
Bob,

I realized I did not read the docs regarding the panel API. I did though for
the following question and still need some help:

I cannot get the onSubmit() action to execute.

A page contains a panel as described above. The form contained inside the
panel is rendered properly yet the onSubmit() action of the panel's form is
not executed. Where would I find more example such as this?

Thanks.


sabob wrote:
> 
> florin.g wrote:
>> Can we place a form inside the panel and have actions attached to it just
>> like a normal page?
> 
> 
> Yep that should work.
> 
> bob
> 
> 

-- 
View this message in context: http://n2.nabble.com/Unexpected--parse%28%29-behavior-tp2470163p2486128.html
Sent from the click-user mailing list archive at Nabble.com.


Re: Unexpected #parse() behavior

Posted by Bob Schellink <sa...@gmail.com>.
florin.g wrote:
> Can we place a form inside the panel and have actions attached to it just
> like a normal page?


Yep that should work.

bob

Re: Unexpected #parse() behavior

Posted by "florin.g" <fl...@bytenotes.com>.
Can we place a form inside the panel and have actions attached to it just
like a normal page?



florin.g wrote:
> 
> Yes, it did work. Thank you.
> 
> 
> sabob wrote:
>> 
>> Bob Schellink wrote:
>>> public class MyPanel extends Panel { // Extend from Panel
>>>     public MyPanel() {
>>>         addModel("myString", "loaded");
>>>     }
>>> }
>> 
>> 
>> Here is a more concrete example with the proper constructor:
>> 
>> public class MyPanel extends Panel {
>>      public MyPanel(String name, String template) {
>>          super(name, template);
>>          addModel("myString", "loaded");
>>      }
>> }
>> 
>> public class ContainerPage extends Page {
>>     // reference MyPanel from ContainerPage
>>     public MyPanel panel = new MyPanel('mypanel', '/myPanel.htm');
>> }
>> 
>> 
>> bob
>> 
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Unexpected--parse%28%29-behavior-tp2470163p2475335.html
Sent from the click-user mailing list archive at Nabble.com.


Re: Unexpected #parse() behavior

Posted by "florin.g" <fl...@bytenotes.com>.
Yes, it did work. Thank you.


sabob wrote:
> 
> Bob Schellink wrote:
>> public class MyPanel extends Panel { // Extend from Panel
>>     public MyPanel() {
>>         addModel("myString", "loaded");
>>     }
>> }
> 
> 
> Here is a more concrete example with the proper constructor:
> 
> public class MyPanel extends Panel {
>      public MyPanel(String name, String template) {
>          super(name, template);
>          addModel("myString", "loaded");
>      }
> }
> 
> public class ContainerPage extends Page {
>     // reference MyPanel from ContainerPage
>     public MyPanel panel = new MyPanel('mypanel', '/myPanel.htm');
> }
> 
> 
> bob
> 
> 

-- 
View this message in context: http://n2.nabble.com/Unexpected--parse%28%29-behavior-tp2470163p2473535.html
Sent from the click-user mailing list archive at Nabble.com.


Re: Unexpected #parse() behavior

Posted by Bob Schellink <sa...@gmail.com>.
Bob Schellink wrote:
> public class MyPanel extends Panel { // Extend from Panel
>     public MyPanel() {
>         addModel("myString", "loaded");
>     }
> }


Here is a more concrete example with the proper constructor:

public class MyPanel extends Panel {
     public MyPanel(String name, String template) {
         super(name, template);
         addModel("myString", "loaded");
     }
}

public class ContainerPage extends Page {
    // reference MyPanel from ContainerPage
    public MyPanel panel = new MyPanel('mypanel', '/myPanel.htm');
}


bob

Re: Unexpected #parse() behavior

Posted by Bob Schellink <sa...@gmail.com>.
florin.g wrote:
> 
> public class ContainerPage extends Page {
>    public Panel panel = new Panel('mypanel', '/myPanel.htm');
> }


This looks right.

> 
> public class MyPanel extends Page {
>    public String myString = "loaded and parsed inside panel";
> }


This will be a problem. When ContainerPage parses its template and 
comes across $mypanel variable, Velocity basically invokes 
panel.toString(). The Panel declared inside ContainerPage does not set 
the myString property which is why $myString prints out "as is".

It seems you want to include the myPanel.htm template and have the 
MyPanel Page processed. However from Velocity's point of view it does 
not know about MyPanel Page. It simply prints out the myPanel.htm 
template and replaces any variables it finds along the way. Since 
MyPanel Page was not processed, myString variable is not available to 
Velocity.

So here is what you can do. Let MyPanel extend from Panel instead and 
reuse MyPanel in your pages. (Note, autobinding is only available in 
Pages, so you need to add variables directly for Panels):

public class MyPanel extends Panel { // Extend from Panel
     public MyPanel() {
         addModel("myString", "loaded");
     }
}


With the above change it should work. You can now include MyPanel in a 
second Page for reuse.

Let us know if that works.

kind regards

bob

Re: Unexpected #parse() behavior

Posted by "florin.g" <fl...@bytenotes.com>.
Well,

I still have the problem. I updated now to 2.0.1 and still not working.
Could it be a configuration issue?

Here's what I do:

public class ContainerPage extends Page {
   public Panel panel = new Panel('mypanel', '/myPanel.htm');
}

public class MyPanel extends Page {
   public String myString = "loaded and parsed inside panel";
}

ContainerPage.htm
<html> .... $mypanel ...</html>

myPanel.htm:
$myString

If I load the page directly: /myPanel.htm, it works.

It must be so simple yet not working. Am I missing somthing?




florin.g wrote:
> 
> Great, great. You are so helpful always!
> 
> I was just so puzzled as to why the same thing happens once but not the
> other. I will look into it further.
> 
> The panels are what I'm looking for. Both template and backing code.
> Wonderful.
> 
> Where do I send a pizza? I mean it. I'm not a programmer really, just a as
> a hubby, but is there anything I can help with?
> 
> 
> sabob wrote:
>> 
>> Hi Florin,
>> 
>> florin.g wrote:
>>> 
>>> I'd like to include a page fragment using the velocity #parse()
>>> directive.
>>> So, I got my Page ready, my template page as well, and it works. 
>>> 
>>> Then, I do a second one and it does not. If I load the fragment in the
>>> browser it does work, /mypage.htm. Included via the #parse() method, it
>>> does
>>> not. The debug logging does not show that the page is rendered, and the
>>> $variables are not parsed, but displayed as simple text. 
>> 
>> 
>> Do you mean you want to nest Pages or just templates?
>> 
>> If you mean Pages that won't work because Velocity #parse includes the 
>> specified template only. The associated Page object is not processed 
>> by Velocity.
>> 
>> If you mean nested template fragments that should work e.g.:
>> 
>> public MyPage extends Page {
>>      public MyPage() {
>>          addModel("fragment1", "/fragment/frag1.htm");
>>          addModel("fragment2", "/fragment/frag2.htm");
>>      }
>> }
>> 
>> 
>> /mypage.htm
>>    ...
>>    #parse($fragment1)
>> 
>> /fragment/frag1.htm
>>    ...
>>    #parse($fragment2);
>> 
>> 
>> Thing is you will have to specify all fragment variables inside your 
>> MyPage class.
>> 
>> However I think what you are looking for is Panels.
>> 
>> 
>>> 
>>> On the other hand, I need more than the BorderPage idea. What I want is
>>> the
>>> ability to make "components", or "portlets" that can be included in
>>> various
>>> pages. For instance, I have a "user list" in at least three different
>>> pages
>>> for different audiences and I want to reduce the amount of coding and
>>> refactoring.
>> 
>> 
>> Yeah sounds like a job for Panels. Panels are like mini pages in that 
>> they have their own template and model. You can easily nest and reuse 
>> panels between Pages as well. Since Panel is just a regular Container 
>> you can add Controls to it as well.
>> 
>> Hope this helps.
>> 
>> kind regards
>> 
>> bob
>> 
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Unexpected--parse%28%29-behavior-tp2470163p2471598.html
Sent from the click-user mailing list archive at Nabble.com.


Re: Unexpected #parse() behavior

Posted by "florin.g" <fl...@bytenotes.com>.
Great, great. You are so helpful always!

I was just so puzzled as to why the same thing happens once but not the
other. I will look into it further.

The panels are what I'm looking for. Both template and backing code.
Wonderful.

Where do I send a pizza? I mean it. I'm not a programmer really, just a as a
hubby, but is there anything I can help with?


sabob wrote:
> 
> Hi Florin,
> 
> florin.g wrote:
>> 
>> I'd like to include a page fragment using the velocity #parse()
>> directive.
>> So, I got my Page ready, my template page as well, and it works. 
>> 
>> Then, I do a second one and it does not. If I load the fragment in the
>> browser it does work, /mypage.htm. Included via the #parse() method, it
>> does
>> not. The debug logging does not show that the page is rendered, and the
>> $variables are not parsed, but displayed as simple text. 
> 
> 
> Do you mean you want to nest Pages or just templates?
> 
> If you mean Pages that won't work because Velocity #parse includes the 
> specified template only. The associated Page object is not processed 
> by Velocity.
> 
> If you mean nested template fragments that should work e.g.:
> 
> public MyPage extends Page {
>      public MyPage() {
>          addModel("fragment1", "/fragment/frag1.htm");
>          addModel("fragment2", "/fragment/frag2.htm");
>      }
> }
> 
> 
> /mypage.htm
>    ...
>    #parse($fragment1)
> 
> /fragment/frag1.htm
>    ...
>    #parse($fragment2);
> 
> 
> Thing is you will have to specify all fragment variables inside your 
> MyPage class.
> 
> However I think what you are looking for is Panels.
> 
> 
>> 
>> On the other hand, I need more than the BorderPage idea. What I want is
>> the
>> ability to make "components", or "portlets" that can be included in
>> various
>> pages. For instance, I have a "user list" in at least three different
>> pages
>> for different audiences and I want to reduce the amount of coding and
>> refactoring.
> 
> 
> Yeah sounds like a job for Panels. Panels are like mini pages in that 
> they have their own template and model. You can easily nest and reuse 
> panels between Pages as well. Since Panel is just a regular Container 
> you can add Controls to it as well.
> 
> Hope this helps.
> 
> kind regards
> 
> bob
> 
> 

-- 
View this message in context: http://n2.nabble.com/Unexpected--parse%28%29-behavior-tp2470163p2470731.html
Sent from the click-user mailing list archive at Nabble.com.


Re: Unexpected #parse() behavior

Posted by Bob Schellink <sa...@gmail.com>.
Hi Florin,

florin.g wrote:
> 
> I'd like to include a page fragment using the velocity #parse() directive.
> So, I got my Page ready, my template page as well, and it works. 
> 
> Then, I do a second one and it does not. If I load the fragment in the
> browser it does work, /mypage.htm. Included via the #parse() method, it does
> not. The debug logging does not show that the page is rendered, and the
> $variables are not parsed, but displayed as simple text. 


Do you mean you want to nest Pages or just templates?

If you mean Pages that won't work because Velocity #parse includes the 
specified template only. The associated Page object is not processed 
by Velocity.

If you mean nested template fragments that should work e.g.:

public MyPage extends Page {
     public MyPage() {
         addModel("fragment1", "/fragment/frag1.htm");
         addModel("fragment2", "/fragment/frag2.htm");
     }
}


/mypage.htm
   ...
   #parse($fragment1)

/fragment/frag1.htm
   ...
   #parse($fragment2);


Thing is you will have to specify all fragment variables inside your 
MyPage class.

However I think what you are looking for is Panels.


> 
> On the other hand, I need more than the BorderPage idea. What I want is the
> ability to make "components", or "portlets" that can be included in various
> pages. For instance, I have a "user list" in at least three different pages
> for different audiences and I want to reduce the amount of coding and
> refactoring.


Yeah sounds like a job for Panels. Panels are like mini pages in that 
they have their own template and model. You can easily nest and reuse 
panels between Pages as well. Since Panel is just a regular Container 
you can add Controls to it as well.

Hope this helps.

kind regards

bob