You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ulrich Teichert <Ul...@gmx.net> on 2006/09/04 18:05:36 UTC

Direct usage of myfaces out of a Java program and save/restoreState issues

Hi,

suppose I want to create some UIComponents via Java, which are not listed
in any template (for instance, creating a variable number of tabs inside
a HtmlPanelTabbedPane).
These components will be added to an existing tabbed pane (generated
via a template from spring, to be exact).

After some self-inflicted pain, I got them to show up just fine and my
data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is displayed, but after a save/restore cycle through going onto another page
and coming back, nothing is there. I can see that I'm getting empty tabs
set during the process in my bean, but that's it.

Maybe I'm just trying something stupid? Or do I need to implement another interface as "Serializable" as well in my bean? I would also happy for
any hint where I should start debugging,

thanks for any help,
Uli
-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


"Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ulrich Teichert <Ul...@gmx.net>.
Hi,

> Just to throw something out for thought which may not provide any help...
> 
> Are your tabs really so dynamic that you can't simply create a
> facelets xhtml template file for each one and include them
> conditionally?  Or use the facelets c:forEach to generate them at
> page-build time?

The second method may be a candidate, yes. Being used to wingS, I feel
more at home with the method I tried, but when I'm not getting it to
work, I'll look into that.

Thanks,
Uli

-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Mike Kienenberger <mk...@gmail.com>.
Uli,

Just to throw something out for thought which may not provide any help...

Are your tabs really so dynamic that you can't simply create a
facelets xhtml template file for each one and include them
conditionally?  Or use the facelets c:forEach to generate them at
page-build time?

On 9/5/06, Ulrich Teichert <Ul...@gmx.net> wrote:
> Hi,
>
> > Could you provide us with a sampel code of how you create your
> > UIComponent?
>
> Sure, I should have done that from the start. I also forgot to list
> some vital version numbers - which proves that I couldn't really
> think anymore yesterday evening...
>
> Anyway, I am using java 1.5 in a Linux environment, tomcat 5.0.28,
> myfaces 1.1.5-SNAPSHOT, tomahawk-1.1.5-SNAPSHOT, spring 2.0RC1 and
> tons of other stuff which is probably not that important.
>
> I'm creating my HtmlPanelTabbedPane on the fly in the get-method of
> my bean, like this:
>
> public HtmlPanelTabbedPane getTabbedPane() {
>   if (_tabbedPane == null) {
>     _tabbedPane = new HtmlPanelTabbedPane();
>     _tab = new HtmlPanelTab();
>     _tab.setLabel("Blah");
>     _tab.setId("PanelTab");
>     _tabbedPane.getChildren().add(_tab);
>     Application app = FacesContext.getCurrentInstance().getApplication();
>     _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
>     _tree.setClientSideToggle(false);
>     _tree.setShowRootNode(true);
>     _tree.setValueBinding("value", app.createValueBinding("#{myBean.treeModel}"));
>     _tree.setVar("node");
>     ValueBinding binding = app.createValueBinding("#{node.description}");
>     HtmlOutputText text = new HtmlOutputText();
>     text.setValueBinding("value", binding);
>     _tree.getFacets().put("node", text);
>     _tab.getChildren().add(_tree);
>   }
>   return _tabbedPane;
> }
>
> As you can see, it's a stripped down example of what I want to do
> in the end, currently I'm just creating one tab, but you get the
> picture. There's a corresponding set-method, too.
>
> My template contains:
>
> <form jsfc="h:form" id="myMainForm">
>   <h:panelGrid columns="2">
>     <t:panelTabbedPane bgcolor="#CCFFFF" serverSideTabSwitch="true" binding="#{myBean.tabbedPane}">
>     </t:panelTabbedPane>
>     <h:panelGrid columns="1" binding="#{myBean.panelGrid}">
>     </h:panelGrid>
>   </h:panelGrid>
> </form>
>
> As you can see, I have a panel grid as second element in my outer panel
> grid, which is created roughly the same way:
>
> public HtmlPanelGrid getPanelGrid() {
>   if (_panelGrid == null) {
>   Application app = FacesContext.getCurrentInstance().getApplication();
>   _panelGrid = (HtmlPanelGrid)app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
>   _panelGrid.setColumns(1);
>   _panelGrid.setValueBinding("value", app.createValueBinding("#{myBean.panelGrid}"));
> ....
>   }
>   return _panelGrid;
> }
>
> But I don't think it's playing a vital role, I've just listed it here
> so that the template makes sense to you. I have some HtmlInput stuff
> in it, that's why I need the form.
>
> CU,
> Uli
>
> > Ulrich Teichert a écrit :
> > > Hi,
> > >
> > > suppose I want to create some UIComponents via Java, which are not
> > listed
> > > in any template (for instance, creating a variable number of tabs inside
> > > a HtmlPanelTabbedPane).
> > > These components will be added to an existing tabbed pane (generated
> > > via a template from spring, to be exact).
> > >
> > > After some self-inflicted pain, I got them to show up just fine and my
> > > data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is
> > displayed, but after a save/restore cycle through going onto another page
> > > and coming back, nothing is there. I can see that I'm getting empty tabs
> > > set during the process in my bean, but that's it.
> > >
> > > Maybe I'm just trying something stupid? Or do I need to implement
> > another interface as "Serializable" as well in my bean? I would also happy for
> > > any hint where I should start debugging,
> > >
> > > thanks for any help,
> > > Uli
> > >
>
> --
> Ulrich Teichert
> Stormweg 24
> 24539 Neumünster, Germany
>
>
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Martin Marinschek <ma...@gmail.com>.
I don't think that Shale is doing that - it would need a StateManager
to do this, and I don't think Shale comes with one.

regards,

Martin

On 9/7/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> On Tue, 2006-09-05 at 17:12 +0200, Ricardo Tercero Lozano wrote:
> > Forgot to say than If you really want to complete restore a previous
> > rendered view you must extend the NavigationHander functionality or
> > use a 'dialog' functionality like Shale dialogs
> > (http://shale.apache.org/features-dialog-manager.html) or sandbox
> > conversation components.
> Do you know if shale's dialog manager restores the right view when
> you come back to a certain view? So when the navigation is like
> view_a.xhtml -> view_b.xhtml -> view_a.xhtml, then would the dialog
> manager restore the uiViewRoot from the first step in the last step?
>
> AFAICS invokes the (myfaces) NavigationHandlerImpl a createView when
> you navigate to another view. If would be good to have the possibility
> to restore a view that previously was active. Probably this would
> additionally require a custom StateManager...
>
> Cheers,
> Martin
>
> >
> > Ricardo.
> >
> >
> > On 9/5/06, Ulrich Teichert <Ul...@gmx.net> wrote:
> >         Hi,
> >
> >         > Ulrich Teichert a écrit :
> >         > >
> >         > >
> >         > > Uh-oh. That's a bit hard - how do I know which property
> >         really is
> >         > required?
> >         > > I thought that when it's required and missing, I would get
> >         a "method not
> >         > > found" exception...
> >         > >
> >         > Sorry, was not clear. I meant, when you programmatically
> >         create a
> >         > Component X with application.createComponent("X"), ensure
> >         that all X
> >         > properties that are marked as required by the corresponding
> >         X taglib
> >         > have been set.
> >         > (for example, HtmlInputText as 2 required properties: id and
> >         value).
> >         > I never meant to add methods to your bean :) I just meant to
> >         ensure your
> >         > UIComponent getXXXX() {... } was doing all required
> >         initialisation steps
> >         > for every component it has created.
> >
> >         I think that should be the case. Else, I would expect some
> >         sort of trouble
> >         during the initial display stage, which is OK in my case.
> >         Well, it doesn't
> >         hurt to double check, so I'll gonna do that anyway.
> >
> >         > >> 4) it still fails with only 1 binding, and no nested
> >         panelGrid.
> >         > >>
> >         > >
> >         > > I've tried whithout the nested panelGrid, did not help
> >         either. I wasn't
> >         > > able to strip it down to one binding only and still
> >         perform something
> >         > > usefull. What did you wanted to test in that case?
> >         > >
> >         > Wanted to check there was no bug with embedded panelGrids
> >         and that there
> >         > was no problem with the fact your bean seems to have 2
> >         dependents on
> >         > each other components.
> >
> >         OK, I'll see if I can strip one component for testing.
> >
> >         > > CU,
> >         > > Uli
> >         > >
> >         > >
> >         > That's all i have in my mind as solution, quite poor :)
> >         Sorry!
> >
> >         I'm happy for all feedback I can get and you have been very
> >         helpfull.
> >         I appreciate that you took the time to look into this. It
> >         seems to me
> >         that not many people are using myfaces this way.
> >
> >         Not giving up yet,
> >         CU,
> >         Uli
> >         --
> >         Ulrich Teichert
> >         Stormweg 24
> >         24539 Neumünster, Germany
> >
> >
> >         Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu
> >         sparen!
> >         Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>
>
>
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Martin Grotzke <ma...@javakaffee.de>.
On Thu, 2006-09-07 at 12:50 -0700, Craig McClanahan wrote:
> On 9/7/06, Martin Grotzke <ma...@javakaffee.de> wrote:
>         Do you know if shale's dialog manager restores the right view
>         when
>         you come back to a certain view? So when the navigation is
>         like
>         view_a.xhtml -> view_b.xhtml -> view_a.xhtml, then would the
>         dialog
>         manager restore the uiViewRoot from the first step in the last
>         step? 
>         
>         AFAICS invokes the (myfaces) NavigationHandlerImpl a
>         createView when
>         you navigate to another view. If would be good to have the
>         possibility
>         to restore a view that previously was active. Probably this
>         would
>         additionally require a custom StateManager...
> 
> If I understand what you're saying, this would indeed require a custom
> State Manager (which Shale doesn't have ... it assumes the JSF
> implementation will take care of that level of details). 
> 
> That being said, let's see if we can drill down a little bit about
> what you mean by "restores the right view".  If you have defined
> something like a wizard dialog with next and previous buttons, Shale
> will create a new view each time navigation occurs ... but the *data*
> on that view can easily be the same as it was the last time this same
> view was visited, if you bind the fields there to something stored in
> session scope, or in the data object associated with this particular
> dialog. 
with restoring the right view i wanted to say that the uiViewRoot (the
component tree structure) shall be restored as it was when you accessed
this view the last time.
I do not have a wizard in mind, but switching between application
modules. E.g. when you're working with an application that allows to
manage companies and users, say you have two modules: user management
module and company management module. When you are on a certain user
related view (let's call it user_view1.xhtml), switch to a company
related view and then go back to user_view1.xhtml, the component tree
structure shall be restored as it was when you accessed this view the
last time.

When you're working with templates (jsp/xhtml) then this restoring
is not necessary as the component tree is created from the templates,
and data will be restored according to the current state of your backing
beans. When the backing bean is in session scope the view looks as it
looked when you accessed this view the last time. So when working with
templates everything is fine...

Only when you create your component tree in code, the question is how
to restore/recreate the component tree so that the structure is the
same as it was when you accessed the view the last time.

I hope this reveals a little bit what i wanted to say...

Cheers,
Martin





> 
> That seems like something much easier for an application developer to
> understand and take advantage of, rather than trying to define some
> sort of rule that says whether a new view should be created, or a
> previous historical view restored, when a particular transition
> happens. 
> 
> 
>         Cheers,
>         Martin
> 
> Craig
>  
> 
> 
>         >
>         > Ricardo.
>         >
>         >
>         > On 9/5/06, Ulrich Teichert <Ul...@gmx.net> wrote:
>         >         Hi,
>         >
>         >         > Ulrich Teichert a écrit : 
>         >         > >
>         >         > >
>         >         > > Uh-oh. That's a bit hard - how do I know which
>         property
>         >         really is
>         >         > required?
>         >         > > I thought that when it's required and missing, I
>         would get 
>         >         a "method not
>         >         > > found" exception...
>         >         > >
>         >         > Sorry, was not clear. I meant, when you
>         programmatically
>         >         create a
>         >         > Component X with application.createComponent("X"),
>         ensure
>         >         that all X
>         >         > properties that are marked as required by the
>         corresponding
>         >         X taglib
>         >         > have been set.
>         >         > (for example, HtmlInputText as 2 required
>         properties: id and
>         >         value).
>         >         > I never meant to add methods to your bean :) I
>         just meant to
>         >         ensure your
>         >         > UIComponent getXXXX() {... } was doing all
>         required 
>         >         initialisation steps
>         >         > for every component it has created.
>         >
>         >         I think that should be the case. Else, I would
>         expect some
>         >         sort of trouble
>         >         during the initial display stage, which is OK in my
>         case. 
>         >         Well, it doesn't
>         >         hurt to double check, so I'll gonna do that anyway.
>         >
>         >         > >> 4) it still fails with only 1 binding, and no
>         nested
>         >         panelGrid.
>         >         > >>
>         >         > >
>         >         > > I've tried whithout the nested panelGrid, did
>         not help
>         >         either. I wasn't
>         >         > > able to strip it down to one binding only and
>         still 
>         >         perform something
>         >         > > usefull. What did you wanted to test in that
>         case?
>         >         > >
>         >         > Wanted to check there was no bug with embedded
>         panelGrids
>         >         and that there 
>         >         > was no problem with the fact your bean seems to
>         have 2
>         >         dependents on
>         >         > each other components.
>         >
>         >         OK, I'll see if I can strip one component for
>         testing. 
>         >
>         >         > > CU,
>         >         > > Uli
>         >         > >
>         >         > >
>         >         > That's all i have in my mind as solution, quite
>         poor :)
>         >         Sorry!
>         >
>         >         I'm happy for all feedback I can get and you have
>         been very
>         >         helpfull.
>         >         I appreciate that you took the time to look into
>         this. It
>         >         seems to me
>         >         that not many people are using myfaces this way. 
>         >
>         >         Not giving up yet,
>         >         CU,
>         >         Uli
>         >         --
>         >         Ulrich Teichert
>         >         Stormweg 24
>         >         24539 Neumünster, Germany
>         >
>         >
>         >         Der GMX SmartSurfer hilft bis zu 70% Ihrer
>         Onlinekosten zu
>         >         sparen!
>         >         Ideal für Modem und ISDN:
>         http://www.gmx.net/de/go/smartsurfer
>         
>         
>         


Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Craig McClanahan <cr...@apache.org>.
On 9/7/06, Martin Grotzke <ma...@javakaffee.de> wrote:
>
> On Tue, 2006-09-05 at 17:12 +0200, Ricardo Tercero Lozano wrote:
> > Forgot to say than If you really want to complete restore a previous
> > rendered view you must extend the NavigationHander functionality or
> > use a 'dialog' functionality like Shale dialogs
> > (http://shale.apache.org/features-dialog-manager.html) or sandbox
> > conversation components.
> Do you know if shale's dialog manager restores the right view when
> you come back to a certain view? So when the navigation is like
> view_a.xhtml -> view_b.xhtml -> view_a.xhtml, then would the dialog
> manager restore the uiViewRoot from the first step in the last step?
>
> AFAICS invokes the (myfaces) NavigationHandlerImpl a createView when
> you navigate to another view. If would be good to have the possibility
> to restore a view that previously was active. Probably this would
> additionally require a custom StateManager...


If I understand what you're saying, this would indeed require a custom State
Manager (which Shale doesn't have ... it assumes the JSF implementation will
take care of that level of details).

That being said, let's see if we can drill down a little bit about what you
mean by "restores the right view".  If you have defined something like a
wizard dialog with next and previous buttons, Shale will create a new view
each time navigation occurs ... but the *data* on that view can easily be
the same as it was the last time this same view was visited, if you bind the
fields there to something stored in session scope, or in the data object
associated with this particular dialog.

That seems like something much easier for an application developer to
understand and take advantage of, rather than trying to define some sort of
rule that says whether a new view should be created, or a previous
historical view restored, when a particular transition happens.

Cheers,
> Martin


Craig


>
> > Ricardo.
> >
> >
> > On 9/5/06, Ulrich Teichert <Ul...@gmx.net> wrote:
> >         Hi,
> >
> >         > Ulrich Teichert a écrit :
> >         > >
> >         > >
> >         > > Uh-oh. That's a bit hard - how do I know which property
> >         really is
> >         > required?
> >         > > I thought that when it's required and missing, I would get
> >         a "method not
> >         > > found" exception...
> >         > >
> >         > Sorry, was not clear. I meant, when you programmatically
> >         create a
> >         > Component X with application.createComponent("X"), ensure
> >         that all X
> >         > properties that are marked as required by the corresponding
> >         X taglib
> >         > have been set.
> >         > (for example, HtmlInputText as 2 required properties: id and
> >         value).
> >         > I never meant to add methods to your bean :) I just meant to
> >         ensure your
> >         > UIComponent getXXXX() {... } was doing all required
> >         initialisation steps
> >         > for every component it has created.
> >
> >         I think that should be the case. Else, I would expect some
> >         sort of trouble
> >         during the initial display stage, which is OK in my case.
> >         Well, it doesn't
> >         hurt to double check, so I'll gonna do that anyway.
> >
> >         > >> 4) it still fails with only 1 binding, and no nested
> >         panelGrid.
> >         > >>
> >         > >
> >         > > I've tried whithout the nested panelGrid, did not help
> >         either. I wasn't
> >         > > able to strip it down to one binding only and still
> >         perform something
> >         > > usefull. What did you wanted to test in that case?
> >         > >
> >         > Wanted to check there was no bug with embedded panelGrids
> >         and that there
> >         > was no problem with the fact your bean seems to have 2
> >         dependents on
> >         > each other components.
> >
> >         OK, I'll see if I can strip one component for testing.
> >
> >         > > CU,
> >         > > Uli
> >         > >
> >         > >
> >         > That's all i have in my mind as solution, quite poor :)
> >         Sorry!
> >
> >         I'm happy for all feedback I can get and you have been very
> >         helpfull.
> >         I appreciate that you took the time to look into this. It
> >         seems to me
> >         that not many people are using myfaces this way.
> >
> >         Not giving up yet,
> >         CU,
> >         Uli
> >         --
> >         Ulrich Teichert
> >         Stormweg 24
> >         24539 Neumünster, Germany
> >
> >
> >         Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu
> >         sparen!
> >         Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>
>
>
>

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Martin Grotzke <ma...@javakaffee.de>.
On Tue, 2006-09-05 at 17:12 +0200, Ricardo Tercero Lozano wrote:
> Forgot to say than If you really want to complete restore a previous
> rendered view you must extend the NavigationHander functionality or
> use a 'dialog' functionality like Shale dialogs
> (http://shale.apache.org/features-dialog-manager.html) or sandbox
> conversation components.
Do you know if shale's dialog manager restores the right view when
you come back to a certain view? So when the navigation is like
view_a.xhtml -> view_b.xhtml -> view_a.xhtml, then would the dialog
manager restore the uiViewRoot from the first step in the last step?

AFAICS invokes the (myfaces) NavigationHandlerImpl a createView when
you navigate to another view. If would be good to have the possibility
to restore a view that previously was active. Probably this would
additionally require a custom StateManager...

Cheers,
Martin

> 
> Ricardo.
> 
> 
> On 9/5/06, Ulrich Teichert <Ul...@gmx.net> wrote:
>         Hi,
>         
>         > Ulrich Teichert a écrit :
>         > > 
>         > >
>         > > Uh-oh. That's a bit hard - how do I know which property
>         really is
>         > required?
>         > > I thought that when it's required and missing, I would get
>         a "method not
>         > > found" exception... 
>         > >
>         > Sorry, was not clear. I meant, when you programmatically
>         create a
>         > Component X with application.createComponent("X"), ensure
>         that all X
>         > properties that are marked as required by the corresponding
>         X taglib 
>         > have been set.
>         > (for example, HtmlInputText as 2 required properties: id and
>         value).
>         > I never meant to add methods to your bean :) I just meant to
>         ensure your
>         > UIComponent getXXXX() {... } was doing all required
>         initialisation steps 
>         > for every component it has created.
>         
>         I think that should be the case. Else, I would expect some
>         sort of trouble
>         during the initial display stage, which is OK in my case.
>         Well, it doesn't
>         hurt to double check, so I'll gonna do that anyway. 
>         
>         > >> 4) it still fails with only 1 binding, and no nested
>         panelGrid.
>         > >>
>         > >
>         > > I've tried whithout the nested panelGrid, did not help
>         either. I wasn't
>         > > able to strip it down to one binding only and still
>         perform something 
>         > > usefull. What did you wanted to test in that case?
>         > >
>         > Wanted to check there was no bug with embedded panelGrids
>         and that there
>         > was no problem with the fact your bean seems to have 2
>         dependents on 
>         > each other components.
>         
>         OK, I'll see if I can strip one component for testing.
>         
>         > > CU,
>         > > Uli
>         > >
>         > >
>         > That's all i have in my mind as solution, quite poor :)
>         Sorry! 
>         
>         I'm happy for all feedback I can get and you have been very
>         helpfull.
>         I appreciate that you took the time to look into this. It
>         seems to me
>         that not many people are using myfaces this way.
>         
>         Not giving up yet, 
>         CU,
>         Uli
>         --
>         Ulrich Teichert
>         Stormweg 24
>         24539 Neumünster, Germany
>         
>         
>         Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu
>         sparen!
>         Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer


Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ricardo Tercero Lozano <rt...@gmail.com>.
Forgot to say than If you really want to complete restore a previous
rendered view you must extend the NavigationHander functionality or use a
'dialog' functionality like Shale dialogs (
http://shale.apache.org/features-dialog-manager.html) or sandbox
conversation components.

Ricardo.


On 9/5/06, Ulrich Teichert <Ul...@gmx.net> wrote:
>
> Hi,
>
> > Ulrich Teichert a écrit :
> > >
> > >
> > > Uh-oh. That's a bit hard - how do I know which property really is
> > required?
> > > I thought that when it's required and missing, I would get a "method
> not
> > > found" exception...
> > >
> > Sorry, was not clear. I meant, when you programmatically create a
> > Component X with application.createComponent("X"), ensure that all X
> > properties that are marked as required by the corresponding X taglib
> > have been set.
> > (for example, HtmlInputText as 2 required properties: id and value).
> > I never meant to add methods to your bean :) I just meant to ensure your
> > UIComponent getXXXX() {... } was doing all required initialisation steps
> > for every component it has created.
>
> I think that should be the case. Else, I would expect some sort of trouble
> during the initial display stage, which is OK in my case. Well, it doesn't
> hurt to double check, so I'll gonna do that anyway.
>
> > >> 4) it still fails with only 1 binding, and no nested panelGrid.
> > >>
> > >
> > > I've tried whithout the nested panelGrid, did not help either. I
> wasn't
> > > able to strip it down to one binding only and still perform something
> > > usefull. What did you wanted to test in that case?
> > >
> > Wanted to check there was no bug with embedded panelGrids and that there
> > was no problem with the fact your bean seems to have 2 dependents on
> > each other components.
>
> OK, I'll see if I can strip one component for testing.
>
> > > CU,
> > > Uli
> > >
> > >
> > That's all i have in my mind as solution, quite poor :) Sorry!
>
> I'm happy for all feedback I can get and you have been very helpfull.
> I appreciate that you took the time to look into this. It seems to me
> that not many people are using myfaces this way.
>
> Not giving up yet,
> CU,
> Uli
> --
> Ulrich Teichert
> Stormweg 24
> 24539 Neumünster, Germany
>
>
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ulrich Teichert <Ul...@gmx.net>.
Hi,

> Ulrich Teichert a écrit :
> >
> >
> > Uh-oh. That's a bit hard - how do I know which property really is
> required?
> > I thought that when it's required and missing, I would get a "method not
> > found" exception...
> >   
> Sorry, was not clear. I meant, when you programmatically create a
> Component X with application.createComponent("X"), ensure that all X
> properties that are marked as required by the corresponding X taglib
> have been set.
> (for example, HtmlInputText as 2 required properties: id and value).
> I never meant to add methods to your bean :) I just meant to ensure your
> UIComponent getXXXX() {... } was doing all required initialisation steps
> for every component it has created.

I think that should be the case. Else, I would expect some sort of trouble
during the initial display stage, which is OK in my case. Well, it doesn't
hurt to double check, so I'll gonna do that anyway.

> >> 4) it still fails with only 1 binding, and no nested panelGrid.
> >>     
> >
> > I've tried whithout the nested panelGrid, did not help either. I wasn't
> > able to strip it down to one binding only and still perform something
> > usefull. What did you wanted to test in that case?
> >   
> Wanted to check there was no bug with embedded panelGrids and that there
> was no problem with the fact your bean seems to have 2 dependents on
> each other components.

OK, I'll see if I can strip one component for testing.

> > CU,
> > Uli
> >   
> >
> That's all i have in my mind as solution, quite poor :) Sorry!

I'm happy for all feedback I can get and you have been very helpfull.
I appreciate that you took the time to look into this. It seems to me
that not many people are using myfaces this way.

Not giving up yet,
CU,
Uli
-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Aleksei Valikov <va...@gmx.net>.
Hi Ulrich,

I create and compone a lot of components programmatically. I've written library 
that creates JSF-based editors base on the XML Schema of the document.

Editors are composed from a large number of JSF components (inputs, command 
links and buttons) and so on.

I use a lot of dynamic value and method bindings to allow user input change the 
underlying document. You'll see a typical example of what I'm doing in the end 
of the mail.

As for me, correct state management with JSF was SO compilcated that I've 
desided to drop it for now and implement dirty and easy solution.

In JSF, you save structure and state of components separately. State is what you 
components put into these arrays. Structure is saved as tree of component classes.

When you restore the state you first re-create a tree of components (i.e. 
instantiate classes) and the provide them with the state.

This is very very very inconvenient for my case.

1. I have a lot of dynamic bindings via anonymous classes. They simply aren't 
serializable! And even if I invent a way to make them serializable, this would 
take SO much time to restore all these dynamic bindings.

2. Simply restoring component tree from component classes tree is a huge 
overhead. I may have hundreds of components on a single page, and I don't want 
them to be serialized/deserialized on each request. This is too slow.

So I have finally decided to do a dirty hack. I simply save one UIViewRoot per 
view ID in the session. Basta. No serialization/deserialization, simply get 
attribute from session.

Yes it is a dirty hack. If you access the same page concurrently, you will have 
problems. But I don't see another solution right now. I'm simply limiting users 
to have one browser window per application, that's it.

Bye.
/lexi

ps. Code example. This creates a label for the complex component, with text, 
pop-up context menu (copy and paste) add and remove buttons.


help = HelpUtils.createHelpLink("sd.structure." + getHelpTopicId(),
		getHelpSubTopicId());
label = TemplatedPanelUtils.createTemplatedPanel(getTemplateName(),
		getFragmentId());

text = FacesUtils.createOutputText(getEditor().getMessageId());
text.setValueBinding("styleClass", new LabelStyleClassValueBinding(
				getEditor()));

final UIComponent copy = CommandUtils.createLink("copy",
		new ClipboardMethodBinding() {
			protected Object invokeInternal(Clipboard clipboard) {
				clipboard.copy(getModel());
				return "Success.";
			}
		});

final UIComponent paste = CommandUtils.createLink("paste",
		new ClipboardMethodBinding() {
			protected Object invokeInternal(Clipboard clipboard) {
				clipboard.paste(getModel());
				return "Success.";
			}
		});

paste.setValueBinding("rendered", new ClipboardValueBinding() {
	protected Object getInternal(Clipboard clipboard) {
		return Boolean.valueOf(clipboard.isPastePossible(getModel()));
	}
});

final HtmlCommandLink refresh = CommandUtils.createLink(
		Messages.REFRESH, null);

contextMenu = FacesUtils.createPopupBox(FacesUtils
		.createContextMenuGraphicImage(), new UIComponent[] { copy,
		paste, refresh });
contextMenu.setStyleClass("hijack-contextMenu");
contextMenu.setStyleClassBox("hijack-contextMenu-box");

label.getFacets().put("contextMenu", contextMenu);

final VoidMethodBinding addAction = new VoidMethodBinding() {
	protected void execute() {
		getModel().addValue();
	}
};

addButton = AjaxCommandUtils.createAddImageLink(addAction);

final VoidMethodBinding removeAction = new VoidMethodBinding() {
protected void execute() {
		getModel().removeValue();
	}
};

removeButton = AjaxCommandUtils.createRemoveImageLink(removeAction);
label.getFacets().put("text", text);
label.getFacets().put("help", help);
label.getFacets().put("contextMenu", contextMenu);
label.getFacets().put("add", addButton);
label.getFacets().put("remove", removeButton);
label.getFacets().put("validity", getEditor().getValidity());
update();
return label;



Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ulrich Teichert <Ul...@gmx.net>.
Hi Ricardo,

thanks for your detailed explanation. I will have to experiment a bit
with a PhaseListener to get it working, so please don't be upset when I'll
be quiet for some time,

again, thanks for your time,
CU,
Uli

-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ricardo Tercero Lozano <rt...@gmail.com>.
The only time frame where views are stored is between a RENDER_RESPONSE end
(the view is serialized) and the RESTORE_VIEW of next request. At the end of
that request there is a new RENDER_RESPONSE phase and a new view is created,
so you are *almost* right. Views are stored but not used at all except for
the 'back button' issue. If you press the back button one or some times, the
view restored after submit in RESTORE_VIEW phase is not the last view
stored, but the corresponding to that submit (the right view to restore is
located by a 'jsf_sequence' hidden parameter).

Savestate stores an object in view in time between RENDER_RESPONSE and next
RESTORE_VIEW. This is the way an object is *maintained* between requests.

So answering your questions, yes, navigating to a view ( as a consequence of
JSF navigation) doesn´t restore its previous state, creates a new one.

Ricardo.

On 9/5/06, Ulrich Teichert <Ul...@gmx.net> wrote:
>
> Hi,
>
> > I think you have a concept mistake. When you come back from one page to
> > another, a complete faces cycle is executed. Thus, the RENDER_VIEW IS
> > executed and a new view is created. You can think the previous stored
> page
> > is restored, but that's not true. If you use x:savestate you can store
> > from
> > a single attribute to a complete view (mostly data values) but in
> restore
> > view phase a complete new view is created (a new component tree). Then,
> > you
> > must recreate the dynamic components or store it and restore manually
> > (savestate or another custom component storage).
>
> Ah, that would explain the behaviour. So, every time I leave a view, that
> one is destroyed *completely* and re-entering it does not lead to calls to
> restoreState, right? I am a bit confused, because when leaving the view
> I can see calls to saveState and that means that this data will not be
> used then.
>
> Thanks,
> Uli
> --
> Ulrich Teichert
> Stormweg 24
> 24539 Neumünster, Germany
>
>
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ulrich Teichert <Ul...@gmx.net>.
Hi,

> I think you have a concept mistake. When you come back from one page to
> another, a complete faces cycle is executed. Thus, the RENDER_VIEW IS
> executed and a new view is created. You can think the previous stored page
> is restored, but that's not true. If you use x:savestate you can store
> from
> a single attribute to a complete view (mostly data values) but in restore
> view phase a complete new view is created (a new component tree). Then,
> you
> must recreate the dynamic components or store it and restore manually
> (savestate or another custom component storage).

Ah, that would explain the behaviour. So, every time I leave a view, that
one is destroyed *completely* and re-entering it does not lead to calls to
restoreState, right? I am a bit confused, because when leaving the view
I can see calls to saveState and that means that this data will not be
used then.

Thanks,
Uli
-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ricardo Tercero Lozano <rt...@gmail.com>.
I think you have a concept mistake. When you come back from one page to
another, a complete faces cycle is executed. Thus, the RENDER_VIEW IS
executed and a new view is created. You can think the previous stored page
is restored, but that's not true. If you use x:savestate you can store from
a single attribute to a complete view (mostly data values) but in restore
view phase a complete new view is created (a new component tree). Then, you
must recreate the dynamic components or store it and restore manually
(savestate or another custom component storage).

Ricardo.


On 9/5/06, David Delbecq <de...@oma.be> wrote:
>
> Ulrich Teichert a écrit :
> >
> >
> > Uh-oh. That's a bit hard - how do I know which property really is
> required?
> > I thought that when it's required and missing, I would get a "method not
> > found" exception...
> >
> Sorry, was not clear. I meant, when you programmatically create a
> Component X with application.createComponent("X"), ensure that all X
> properties that are marked as required by the corresponding X taglib
> have been set.
> (for example, HtmlInputText as 2 required properties: id and value).
> I never meant to add methods to your bean :) I just meant to ensure your
> UIComponent getXXXX() {... } was doing all required initialisation steps
> for every component it has created.
> >
> >> 4) it still fails with only 1 binding, and no nested panelGrid.
> >>
> >
> > I've tried whithout the nested panelGrid, did not help either. I wasn't
> > able to strip it down to one binding only and still perform something
> > usefull. What did you wanted to test in that case?
> >
> Wanted to check there was no bug with embedded panelGrids and that there
> was no problem with the fact your bean seems to have 2 dependents on
> each other components.
> > CU,
> > Uli
> >
> >
> That's all i have in my mind as solution, quite poor :) Sorry!
>

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by David Delbecq <de...@oma.be>.
Ulrich Teichert a écrit :
>
>
> Uh-oh. That's a bit hard - how do I know which property really is required?
> I thought that when it's required and missing, I would get a "method not
> found" exception...
>   
Sorry, was not clear. I meant, when you programmatically create a
Component X with application.createComponent("X"), ensure that all X
properties that are marked as required by the corresponding X taglib
have been set.
(for example, HtmlInputText as 2 required properties: id and value).
I never meant to add methods to your bean :) I just meant to ensure your
UIComponent getXXXX() {... } was doing all required initialisation steps
for every component it has created.
>   
>> 4) it still fails with only 1 binding, and no nested panelGrid.
>>     
>
> I've tried whithout the nested panelGrid, did not help either. I wasn't
> able to strip it down to one binding only and still perform something
> usefull. What did you wanted to test in that case?
>   
Wanted to check there was no bug with embedded panelGrids and that there
was no problem with the fact your bean seems to have 2 dependents on
each other components.
> CU,
> Uli
>   
>
That's all i have in my mind as solution, quite poor :) Sorry!

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ulrich Teichert <Ul...@gmx.net>.
Hi,

first, thanks for your suggestions, I really appreciate your help.
Sorry that it took so long trying out most of the stuff:

> Did you ensure that you
> 1) set all the Ids of your programmatically created components

I did not, but now I am setting all IDs - eventhough it did not help.

> 2) have a setPanelGrid (used for the binding after page reload i think,
> i have never used the binding attribute however, my experience is
> limited to composite components)

Yeah, got that before

> 3) set all required properties for corresponding tags (that is if tag
> for component X requires property y, ensure there is a setValue(Y,...)
> in your code)

Uh-oh. That's a bit hard - how do I know which property really is required?
I thought that when it's required and missing, I would get a "method not
found" exception...

> 4) it still fails with only 1 binding, and no nested panelGrid.

I've tried whithout the nested panelGrid, did not help either. I wasn't
able to strip it down to one binding only and still perform something
usefull. What did you wanted to test in that case?

CU,
Uli

> Ulrich Teichert a écrit :
> > Hi,
> >
> >   
> >> This is i think your mistake:
> >>
> >>     _tabbedPane = new HtmlPanelTabbedPane();
> >>     _tab = new HtmlPanelTab();
> >>
> >> Never construct an UIComponent directly. It's lifecycle has to be
> >> managed by the JSF engine for things to work properly. If you need to
> >> create compoment using java code, use the application, like this:
> >>
> >> Application application =
> >> FacesContext.getCurrentInstance().getApplication();
> >> _tabbedPane =
> >>
> (HtmlPanelTabbedPane)application.createComponent(HtmlPanelTabbedPane.COMPONENT_TYPE);
> >>     
> >
> > OK, makes sense, esp. because I already did that in other places.
> > So, I changed the code to:
> >
> > public HtmlPanelTabbedPane getTabbedPane() {
> >   if (_tabbedPane == null) {
> >     Application app =
> FacesContext.getCurrentInstance().getApplication();
> >     _tabbedPane =
> (HtmlPanelTabbedPane)app.createComponent(HtmlPanelTabbedPane.COMPONENT_TYPE);
> >     _tab =
> (HtmlPanelTab)app.createComponent(HtmlPanelTab.COMPONENT_TYPE);
> >     _tab.setLabel("Blah");
> >     _tab.setId("PanelTab");
> >     _tabbedPane.getChildren().add(_tab);
> >     _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
> > ....
> >
> > But the behaviour did not change :-( Anything else suspicious?
> >
> > TIA,
> > Uli
> >
> >   
> >> Ulrich Teichert a écrit :
> >>     
> >>> Hi,
> >>>
> >>>   
> >>>       
> >>>> Could you provide us with a sampel code of how you create your
> >>>> UIComponent?
> >>>>     
> >>>>         
> >>> Sure, I should have done that from the start. I also forgot to list
> >>> some vital version numbers - which proves that I couldn't really
> >>> think anymore yesterday evening...
> >>>
> >>> Anyway, I am using java 1.5 in a Linux environment, tomcat 5.0.28,
> >>> myfaces 1.1.5-SNAPSHOT, tomahawk-1.1.5-SNAPSHOT, spring 2.0RC1 and
> >>> tons of other stuff which is probably not that important.
> >>>
> >>> I'm creating my HtmlPanelTabbedPane on the fly in the get-method of
> >>> my bean, like this:
> >>>
> >>> public HtmlPanelTabbedPane getTabbedPane() {
> >>>   if (_tabbedPane == null) {
> >>>     _tabbedPane = new HtmlPanelTabbedPane();
> >>>     _tab = new HtmlPanelTab();
> >>>     _tab.setLabel("Blah");
> >>>     _tab.setId("PanelTab");
> >>>     _tabbedPane.getChildren().add(_tab);
> >>>     Application app =
> >>>       
> >> FacesContext.getCurrentInstance().getApplication();
> >>     
> >>>     _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
> >>>     _tree.setClientSideToggle(false);
> >>>     _tree.setShowRootNode(true);
> >>>     _tree.setValueBinding("value",
> >>>       
> >> app.createValueBinding("#{myBean.treeModel}"));
> >>     
> >>>     _tree.setVar("node");
> >>>     ValueBinding binding =
> >>>       
> >> app.createValueBinding("#{node.description}");
> >>     
> >>>     HtmlOutputText text = new HtmlOutputText();
> >>>     text.setValueBinding("value", binding);
> >>>     _tree.getFacets().put("node", text);
> >>>     _tab.getChildren().add(_tree);
> >>>   }
> >>>   return _tabbedPane;
> >>> }
> >>>
> >>> As you can see, it's a stripped down example of what I want to do
> >>> in the end, currently I'm just creating one tab, but you get the
> >>> picture. There's a corresponding set-method, too.
> >>>
> >>> My template contains:
> >>>
> >>> <form jsfc="h:form" id="myMainForm">
> >>>   <h:panelGrid columns="2">
> >>>     <t:panelTabbedPane bgcolor="#CCFFFF" serverSideTabSwitch="true"
> >>>       
> >> binding="#{myBean.tabbedPane}">
> >>     
> >>>     </t:panelTabbedPane>
> >>>     <h:panelGrid columns="1" binding="#{myBean.panelGrid}">
> >>>     </h:panelGrid>
> >>>   </h:panelGrid>
> >>> </form>
> >>>
> >>> As you can see, I have a panel grid as second element in my outer
> panel
> >>> grid, which is created roughly the same way:
> >>>
> >>> public HtmlPanelGrid getPanelGrid() {
> >>>   if (_panelGrid == null) {
> >>>   Application app =
> FacesContext.getCurrentInstance().getApplication();
> >>>   _panelGrid =
> >>>       
> >> (HtmlPanelGrid)app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
> >>     
> >>>   _panelGrid.setColumns(1);
> >>>   _panelGrid.setValueBinding("value",
> >>>       
> >> app.createValueBinding("#{myBean.panelGrid}"));
> >>     
> >>> ....
> >>>   }
> >>>   return _panelGrid;
> >>> }
> >>>
> >>> But I don't think it's playing a vital role, I've just listed it here
> >>> so that the template makes sense to you. I have some HtmlInput stuff
> >>> in it, that's why I need the form.
> >>>
> >>> CU,
> >>> Uli
> >>>
> >>>   
> >>>       
> >>>> Ulrich Teichert a écrit :
> >>>>     
> >>>>         
> >>>>> Hi,
> >>>>>
> >>>>> suppose I want to create some UIComponents via Java, which are not
> >>>>>       
> >>>>>           
> >>>> listed
> >>>>     
> >>>>         
> >>>>> in any template (for instance, creating a variable number of tabs
> >>>>>           
> >> inside
> >>     
> >>>>> a HtmlPanelTabbedPane).
> >>>>> These components will be added to an existing tabbed pane (generated
> >>>>> via a template from spring, to be exact).
> >>>>>
> >>>>> After some self-inflicted pain, I got them to show up just fine and
> my
> >>>>> data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is
> >>>>>       
> >>>>>           
> >>>> displayed, but after a save/restore cycle through going onto another
> >>>>         
> >> page
> >>     
> >>>>     
> >>>>         
> >>>>> and coming back, nothing is there. I can see that I'm getting empty
> >>>>>           
> >> tabs
> >>     
> >>>>> set during the process in my bean, but that's it.
> >>>>>
> >>>>> Maybe I'm just trying something stupid? Or do I need to implement
> >>>>>       
> >>>>>           
> >>>> another interface as "Serializable" as well in my bean? I would also
> >>>>         
> >> happy for
> >>     
> >>>>     
> >>>>         
> >>>>> any hint where I should start debugging,
> >>>>>
> >>>>> thanks for any help,
> >>>>> Uli
> >>>>>   
> >>>>>       
> >>>>>           
> >>>   
> >>>       
> >
> >   

-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


"Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by David Delbecq <de...@oma.be>.
Did you ensure that you
1) set all the Ids of your programmatically created components
2) have a setPanelGrid (used for the binding after page reload i think,
i have never used the binding attribute however, my experience is
limited to composite components)
3) set all required properties for corresponding tags (that is if tag
for component X requires property y, ensure there is a setValue(Y,...)
in your code)
4) it still fails with only 1 binding, and no nested panelGrid.

Ulrich Teichert a écrit :
> Hi,
>
>   
>> This is i think your mistake:
>>
>>     _tabbedPane = new HtmlPanelTabbedPane();
>>     _tab = new HtmlPanelTab();
>>
>> Never construct an UIComponent directly. It's lifecycle has to be
>> managed by the JSF engine for things to work properly. If you need to
>> create compoment using java code, use the application, like this:
>>
>> Application application =
>> FacesContext.getCurrentInstance().getApplication();
>> _tabbedPane =
>> (HtmlPanelTabbedPane)application.createComponent(HtmlPanelTabbedPane.COMPONENT_TYPE);
>>     
>
> OK, makes sense, esp. because I already did that in other places.
> So, I changed the code to:
>
> public HtmlPanelTabbedPane getTabbedPane() {
>   if (_tabbedPane == null) {
>     Application app = FacesContext.getCurrentInstance().getApplication();
>     _tabbedPane = (HtmlPanelTabbedPane)app.createComponent(HtmlPanelTabbedPane.COMPONENT_TYPE);
>     _tab = (HtmlPanelTab)app.createComponent(HtmlPanelTab.COMPONENT_TYPE);
>     _tab.setLabel("Blah");
>     _tab.setId("PanelTab");
>     _tabbedPane.getChildren().add(_tab);
>     _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
> ....
>
> But the behaviour did not change :-( Anything else suspicious?
>
> TIA,
> Uli
>
>   
>> Ulrich Teichert a écrit :
>>     
>>> Hi,
>>>
>>>   
>>>       
>>>> Could you provide us with a sampel code of how you create your
>>>> UIComponent?
>>>>     
>>>>         
>>> Sure, I should have done that from the start. I also forgot to list
>>> some vital version numbers - which proves that I couldn't really
>>> think anymore yesterday evening...
>>>
>>> Anyway, I am using java 1.5 in a Linux environment, tomcat 5.0.28,
>>> myfaces 1.1.5-SNAPSHOT, tomahawk-1.1.5-SNAPSHOT, spring 2.0RC1 and
>>> tons of other stuff which is probably not that important.
>>>
>>> I'm creating my HtmlPanelTabbedPane on the fly in the get-method of
>>> my bean, like this:
>>>
>>> public HtmlPanelTabbedPane getTabbedPane() {
>>>   if (_tabbedPane == null) {
>>>     _tabbedPane = new HtmlPanelTabbedPane();
>>>     _tab = new HtmlPanelTab();
>>>     _tab.setLabel("Blah");
>>>     _tab.setId("PanelTab");
>>>     _tabbedPane.getChildren().add(_tab);
>>>     Application app =
>>>       
>> FacesContext.getCurrentInstance().getApplication();
>>     
>>>     _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
>>>     _tree.setClientSideToggle(false);
>>>     _tree.setShowRootNode(true);
>>>     _tree.setValueBinding("value",
>>>       
>> app.createValueBinding("#{myBean.treeModel}"));
>>     
>>>     _tree.setVar("node");
>>>     ValueBinding binding =
>>>       
>> app.createValueBinding("#{node.description}");
>>     
>>>     HtmlOutputText text = new HtmlOutputText();
>>>     text.setValueBinding("value", binding);
>>>     _tree.getFacets().put("node", text);
>>>     _tab.getChildren().add(_tree);
>>>   }
>>>   return _tabbedPane;
>>> }
>>>
>>> As you can see, it's a stripped down example of what I want to do
>>> in the end, currently I'm just creating one tab, but you get the
>>> picture. There's a corresponding set-method, too.
>>>
>>> My template contains:
>>>
>>> <form jsfc="h:form" id="myMainForm">
>>>   <h:panelGrid columns="2">
>>>     <t:panelTabbedPane bgcolor="#CCFFFF" serverSideTabSwitch="true"
>>>       
>> binding="#{myBean.tabbedPane}">
>>     
>>>     </t:panelTabbedPane>
>>>     <h:panelGrid columns="1" binding="#{myBean.panelGrid}">
>>>     </h:panelGrid>
>>>   </h:panelGrid>
>>> </form>
>>>
>>> As you can see, I have a panel grid as second element in my outer panel
>>> grid, which is created roughly the same way:
>>>
>>> public HtmlPanelGrid getPanelGrid() {
>>>   if (_panelGrid == null) {
>>>   Application app = FacesContext.getCurrentInstance().getApplication();
>>>   _panelGrid =
>>>       
>> (HtmlPanelGrid)app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
>>     
>>>   _panelGrid.setColumns(1);
>>>   _panelGrid.setValueBinding("value",
>>>       
>> app.createValueBinding("#{myBean.panelGrid}"));
>>     
>>> ....
>>>   }
>>>   return _panelGrid;
>>> }
>>>
>>> But I don't think it's playing a vital role, I've just listed it here
>>> so that the template makes sense to you. I have some HtmlInput stuff
>>> in it, that's why I need the form.
>>>
>>> CU,
>>> Uli
>>>
>>>   
>>>       
>>>> Ulrich Teichert a écrit :
>>>>     
>>>>         
>>>>> Hi,
>>>>>
>>>>> suppose I want to create some UIComponents via Java, which are not
>>>>>       
>>>>>           
>>>> listed
>>>>     
>>>>         
>>>>> in any template (for instance, creating a variable number of tabs
>>>>>           
>> inside
>>     
>>>>> a HtmlPanelTabbedPane).
>>>>> These components will be added to an existing tabbed pane (generated
>>>>> via a template from spring, to be exact).
>>>>>
>>>>> After some self-inflicted pain, I got them to show up just fine and my
>>>>> data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is
>>>>>       
>>>>>           
>>>> displayed, but after a save/restore cycle through going onto another
>>>>         
>> page
>>     
>>>>     
>>>>         
>>>>> and coming back, nothing is there. I can see that I'm getting empty
>>>>>           
>> tabs
>>     
>>>>> set during the process in my bean, but that's it.
>>>>>
>>>>> Maybe I'm just trying something stupid? Or do I need to implement
>>>>>       
>>>>>           
>>>> another interface as "Serializable" as well in my bean? I would also
>>>>         
>> happy for
>>     
>>>>     
>>>>         
>>>>> any hint where I should start debugging,
>>>>>
>>>>> thanks for any help,
>>>>> Uli
>>>>>   
>>>>>       
>>>>>           
>>>   
>>>       
>
>   


Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ulrich Teichert <Ul...@gmx.net>.
Hi,

> This is i think your mistake:
> 
>     _tabbedPane = new HtmlPanelTabbedPane();
>     _tab = new HtmlPanelTab();
> 
> Never construct an UIComponent directly. It's lifecycle has to be
> managed by the JSF engine for things to work properly. If you need to
> create compoment using java code, use the application, like this:
> 
> Application application =
> FacesContext.getCurrentInstance().getApplication();
> _tabbedPane =
> (HtmlPanelTabbedPane)application.createComponent(HtmlPanelTabbedPane.COMPONENT_TYPE);

OK, makes sense, esp. because I already did that in other places.
So, I changed the code to:

public HtmlPanelTabbedPane getTabbedPane() {
  if (_tabbedPane == null) {
    Application app = FacesContext.getCurrentInstance().getApplication();
    _tabbedPane = (HtmlPanelTabbedPane)app.createComponent(HtmlPanelTabbedPane.COMPONENT_TYPE);
    _tab = (HtmlPanelTab)app.createComponent(HtmlPanelTab.COMPONENT_TYPE);
    _tab.setLabel("Blah");
    _tab.setId("PanelTab");
    _tabbedPane.getChildren().add(_tab);
    _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
....

But the behaviour did not change :-( Anything else suspicious?

TIA,
Uli

> Ulrich Teichert a écrit :
> > Hi,
> >
> >   
> >> Could you provide us with a sampel code of how you create your
> >> UIComponent?
> >>     
> >
> > Sure, I should have done that from the start. I also forgot to list
> > some vital version numbers - which proves that I couldn't really
> > think anymore yesterday evening...
> >
> > Anyway, I am using java 1.5 in a Linux environment, tomcat 5.0.28,
> > myfaces 1.1.5-SNAPSHOT, tomahawk-1.1.5-SNAPSHOT, spring 2.0RC1 and
> > tons of other stuff which is probably not that important.
> >
> > I'm creating my HtmlPanelTabbedPane on the fly in the get-method of
> > my bean, like this:
> >
> > public HtmlPanelTabbedPane getTabbedPane() {
> >   if (_tabbedPane == null) {
> >     _tabbedPane = new HtmlPanelTabbedPane();
> >     _tab = new HtmlPanelTab();
> >     _tab.setLabel("Blah");
> >     _tab.setId("PanelTab");
> >     _tabbedPane.getChildren().add(_tab);
> >     Application app =
> FacesContext.getCurrentInstance().getApplication();
> >     _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
> >     _tree.setClientSideToggle(false);
> >     _tree.setShowRootNode(true);
> >     _tree.setValueBinding("value",
> app.createValueBinding("#{myBean.treeModel}"));
> >     _tree.setVar("node");
> >     ValueBinding binding =
> app.createValueBinding("#{node.description}");
> >     HtmlOutputText text = new HtmlOutputText();
> >     text.setValueBinding("value", binding);
> >     _tree.getFacets().put("node", text);
> >     _tab.getChildren().add(_tree);
> >   }
> >   return _tabbedPane;
> > }
> >
> > As you can see, it's a stripped down example of what I want to do
> > in the end, currently I'm just creating one tab, but you get the
> > picture. There's a corresponding set-method, too.
> >
> > My template contains:
> >
> > <form jsfc="h:form" id="myMainForm">
> >   <h:panelGrid columns="2">
> >     <t:panelTabbedPane bgcolor="#CCFFFF" serverSideTabSwitch="true"
> binding="#{myBean.tabbedPane}">
> >     </t:panelTabbedPane>
> >     <h:panelGrid columns="1" binding="#{myBean.panelGrid}">
> >     </h:panelGrid>
> >   </h:panelGrid>
> > </form>
> >
> > As you can see, I have a panel grid as second element in my outer panel
> > grid, which is created roughly the same way:
> >
> > public HtmlPanelGrid getPanelGrid() {
> >   if (_panelGrid == null) {
> >   Application app = FacesContext.getCurrentInstance().getApplication();
> >   _panelGrid =
> (HtmlPanelGrid)app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
> >   _panelGrid.setColumns(1);
> >   _panelGrid.setValueBinding("value",
> app.createValueBinding("#{myBean.panelGrid}"));
> > ....
> >   }
> >   return _panelGrid;
> > }
> >
> > But I don't think it's playing a vital role, I've just listed it here
> > so that the template makes sense to you. I have some HtmlInput stuff
> > in it, that's why I need the form.
> >
> > CU,
> > Uli
> >
> >   
> >> Ulrich Teichert a écrit :
> >>     
> >>> Hi,
> >>>
> >>> suppose I want to create some UIComponents via Java, which are not
> >>>       
> >> listed
> >>     
> >>> in any template (for instance, creating a variable number of tabs
> inside
> >>> a HtmlPanelTabbedPane).
> >>> These components will be added to an existing tabbed pane (generated
> >>> via a template from spring, to be exact).
> >>>
> >>> After some self-inflicted pain, I got them to show up just fine and my
> >>> data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is
> >>>       
> >> displayed, but after a save/restore cycle through going onto another
> page
> >>     
> >>> and coming back, nothing is there. I can see that I'm getting empty
> tabs
> >>> set during the process in my bean, but that's it.
> >>>
> >>> Maybe I'm just trying something stupid? Or do I need to implement
> >>>       
> >> another interface as "Serializable" as well in my bean? I would also
> happy for
> >>     
> >>> any hint where I should start debugging,
> >>>
> >>> thanks for any help,
> >>> Uli
> >>>   
> >>>       
> >
> >   

-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by David Delbecq <de...@oma.be>.
This is i think your mistake:

    _tabbedPane = new HtmlPanelTabbedPane();
    _tab = new HtmlPanelTab();

Never construct an UIComponent directly. It's lifecycle has to be
managed by the JSF engine for things to work properly. If you need to
create compoment using java code, use the application, like this:

Application application =
FacesContext.getCurrentInstance().getApplication();
_tabbedPane =
(HtmlPanelTabbedPane)application.createComponent(HtmlPanelTabbedPane.COMPONENT_TYPE);


Ulrich Teichert a écrit :
> Hi,
>
>   
>> Could you provide us with a sampel code of how you create your
>> UIComponent?
>>     
>
> Sure, I should have done that from the start. I also forgot to list
> some vital version numbers - which proves that I couldn't really
> think anymore yesterday evening...
>
> Anyway, I am using java 1.5 in a Linux environment, tomcat 5.0.28,
> myfaces 1.1.5-SNAPSHOT, tomahawk-1.1.5-SNAPSHOT, spring 2.0RC1 and
> tons of other stuff which is probably not that important.
>
> I'm creating my HtmlPanelTabbedPane on the fly in the get-method of
> my bean, like this:
>
> public HtmlPanelTabbedPane getTabbedPane() {
>   if (_tabbedPane == null) {
>     _tabbedPane = new HtmlPanelTabbedPane();
>     _tab = new HtmlPanelTab();
>     _tab.setLabel("Blah");
>     _tab.setId("PanelTab");
>     _tabbedPane.getChildren().add(_tab);
>     Application app = FacesContext.getCurrentInstance().getApplication();
>     _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
>     _tree.setClientSideToggle(false);
>     _tree.setShowRootNode(true);
>     _tree.setValueBinding("value", app.createValueBinding("#{myBean.treeModel}"));
>     _tree.setVar("node");
>     ValueBinding binding = app.createValueBinding("#{node.description}");
>     HtmlOutputText text = new HtmlOutputText();
>     text.setValueBinding("value", binding);
>     _tree.getFacets().put("node", text);
>     _tab.getChildren().add(_tree);
>   }
>   return _tabbedPane;
> }
>
> As you can see, it's a stripped down example of what I want to do
> in the end, currently I'm just creating one tab, but you get the
> picture. There's a corresponding set-method, too.
>
> My template contains:
>
> <form jsfc="h:form" id="myMainForm">
>   <h:panelGrid columns="2">
>     <t:panelTabbedPane bgcolor="#CCFFFF" serverSideTabSwitch="true" binding="#{myBean.tabbedPane}">
>     </t:panelTabbedPane>
>     <h:panelGrid columns="1" binding="#{myBean.panelGrid}">
>     </h:panelGrid>
>   </h:panelGrid>
> </form>
>
> As you can see, I have a panel grid as second element in my outer panel
> grid, which is created roughly the same way:
>
> public HtmlPanelGrid getPanelGrid() {
>   if (_panelGrid == null) {
>   Application app = FacesContext.getCurrentInstance().getApplication();
>   _panelGrid = (HtmlPanelGrid)app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
>   _panelGrid.setColumns(1);
>   _panelGrid.setValueBinding("value", app.createValueBinding("#{myBean.panelGrid}"));
> ....
>   }
>   return _panelGrid;
> }
>
> But I don't think it's playing a vital role, I've just listed it here
> so that the template makes sense to you. I have some HtmlInput stuff
> in it, that's why I need the form.
>
> CU,
> Uli
>
>   
>> Ulrich Teichert a écrit :
>>     
>>> Hi,
>>>
>>> suppose I want to create some UIComponents via Java, which are not
>>>       
>> listed
>>     
>>> in any template (for instance, creating a variable number of tabs inside
>>> a HtmlPanelTabbedPane).
>>> These components will be added to an existing tabbed pane (generated
>>> via a template from spring, to be exact).
>>>
>>> After some self-inflicted pain, I got them to show up just fine and my
>>> data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is
>>>       
>> displayed, but after a save/restore cycle through going onto another page
>>     
>>> and coming back, nothing is there. I can see that I'm getting empty tabs
>>> set during the process in my bean, but that's it.
>>>
>>> Maybe I'm just trying something stupid? Or do I need to implement
>>>       
>> another interface as "Serializable" as well in my bean? I would also happy for
>>     
>>> any hint where I should start debugging,
>>>
>>> thanks for any help,
>>> Uli
>>>   
>>>       
>
>   


Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by Ulrich Teichert <Ul...@gmx.net>.
Hi,

> Could you provide us with a sampel code of how you create your
> UIComponent?

Sure, I should have done that from the start. I also forgot to list
some vital version numbers - which proves that I couldn't really
think anymore yesterday evening...

Anyway, I am using java 1.5 in a Linux environment, tomcat 5.0.28,
myfaces 1.1.5-SNAPSHOT, tomahawk-1.1.5-SNAPSHOT, spring 2.0RC1 and
tons of other stuff which is probably not that important.

I'm creating my HtmlPanelTabbedPane on the fly in the get-method of
my bean, like this:

public HtmlPanelTabbedPane getTabbedPane() {
  if (_tabbedPane == null) {
    _tabbedPane = new HtmlPanelTabbedPane();
    _tab = new HtmlPanelTab();
    _tab.setLabel("Blah");
    _tab.setId("PanelTab");
    _tabbedPane.getChildren().add(_tab);
    Application app = FacesContext.getCurrentInstance().getApplication();
    _tree = (HtmlTree)app.createComponent(HtmlTree.COMPONENT_TYPE);
    _tree.setClientSideToggle(false);
    _tree.setShowRootNode(true);
    _tree.setValueBinding("value", app.createValueBinding("#{myBean.treeModel}"));
    _tree.setVar("node");
    ValueBinding binding = app.createValueBinding("#{node.description}");
    HtmlOutputText text = new HtmlOutputText();
    text.setValueBinding("value", binding);
    _tree.getFacets().put("node", text);
    _tab.getChildren().add(_tree);
  }
  return _tabbedPane;
}

As you can see, it's a stripped down example of what I want to do
in the end, currently I'm just creating one tab, but you get the
picture. There's a corresponding set-method, too.

My template contains:

<form jsfc="h:form" id="myMainForm">
  <h:panelGrid columns="2">
    <t:panelTabbedPane bgcolor="#CCFFFF" serverSideTabSwitch="true" binding="#{myBean.tabbedPane}">
    </t:panelTabbedPane>
    <h:panelGrid columns="1" binding="#{myBean.panelGrid}">
    </h:panelGrid>
  </h:panelGrid>
</form>

As you can see, I have a panel grid as second element in my outer panel
grid, which is created roughly the same way:

public HtmlPanelGrid getPanelGrid() {
  if (_panelGrid == null) {
  Application app = FacesContext.getCurrentInstance().getApplication();
  _panelGrid = (HtmlPanelGrid)app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
  _panelGrid.setColumns(1);
  _panelGrid.setValueBinding("value", app.createValueBinding("#{myBean.panelGrid}"));
....
  }
  return _panelGrid;
}

But I don't think it's playing a vital role, I've just listed it here
so that the template makes sense to you. I have some HtmlInput stuff
in it, that's why I need the form.

CU,
Uli

> Ulrich Teichert a écrit :
> > Hi,
> >
> > suppose I want to create some UIComponents via Java, which are not
> listed
> > in any template (for instance, creating a variable number of tabs inside
> > a HtmlPanelTabbedPane).
> > These components will be added to an existing tabbed pane (generated
> > via a template from spring, to be exact).
> >
> > After some self-inflicted pain, I got them to show up just fine and my
> > data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is
> displayed, but after a save/restore cycle through going onto another page
> > and coming back, nothing is there. I can see that I'm getting empty tabs
> > set during the process in my bean, but that's it.
> >
> > Maybe I'm just trying something stupid? Or do I need to implement
> another interface as "Serializable" as well in my bean? I would also happy for
> > any hint where I should start debugging,
> >
> > thanks for any help,
> > Uli
> >   

-- 
Ulrich Teichert
Stormweg 24
24539 Neumünster, Germany


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

Re: Direct usage of myfaces out of a Java program and save/restoreState issues

Posted by delbd <de...@oma.be>.
Could you provide us with a sampel code of how you create your UIComponent?
Ulrich Teichert a écrit :
> Hi,
>
> suppose I want to create some UIComponents via Java, which are not listed
> in any template (for instance, creating a variable number of tabs inside
> a HtmlPanelTabbedPane).
> These components will be added to an existing tabbed pane (generated
> via a template from spring, to be exact).
>
> After some self-inflicted pain, I got them to show up just fine and my
> data inside the tabs (org.apache.myfaces.custom.tree2.HtmlTree) is displayed, but after a save/restore cycle through going onto another page
> and coming back, nothing is there. I can see that I'm getting empty tabs
> set during the process in my bean, but that's it.
>
> Maybe I'm just trying something stupid? Or do I need to implement another interface as "Serializable" as well in my bean? I would also happy for
> any hint where I should start debugging,
>
> thanks for any help,
> Uli
>