Well, I've gotten the setter method working just fine, but have run into
another problem immediately.

 
It's really the same problem, but instead of being inside a JSP I'm inside a
regular Java method:

 

public void setPane(HtmlPanelTabbedPane component){

            FacesContext context = FacesContext.getCurrentInstance();

            Application app = context.getApplication();

            

            if (pane == null){

                  pane =
(HtmlPanelTabbedPane)app.createComponent(TABBEDPANE);

            }

            

            if (tab == null){

                  tab = (HtmlPanelTab)app.createComponent(PANELTAB);

            }

 

            numtimes ++;

            System.out.println("Numtimes = " + numtimes);

            tab.setLabel(Integer.toString(numtimes));

            

            System.out.println(tab.getLabel());

            

      }

 

Now, what I get on the console if I've refreshed 3 times is:

 

Numtimes = 3

3

 

But what displays on the tab header is "1".

 

Now, I realize this is happening because the tab itself is using the saved
version that has been restored.

 

To get around this, it seems to me like I will need to create a value
binding for the tab itself, but it's not immediately clear how to do this.

 

Now, I see the method in UIComponentBase:

 

setValueBinding(java.lang.String name,
javax.faces.el.ValueBinding binding)

 

but... I need to pass in a ValueBinding object, and looking at the javadoc
for the ValueBinding object, it's not at all clear what I need to do with
it.

 

I guess an alternative way to do this would be to completely recreate the
tabbed pane every time and add the children back in, but then I'm going to
lose the state of my child tabs, meaning if work has been done in more than
one tab and I have to refresh, all that work will be lost, so that's not a
realistic solution for me.

 

What I really need to be able to do is query my child tab in a setter method
and figure out whether I need to restore state or recreate it, which I can
handle on my own no problem... I just need to figure out how to
programmatically bind the tab so that I can get into its setter method.

 

Jeremy Sager

Data Communications Product Manager

Chesapeake System Solutions

410.356.6805 x120

[EMAIL PROTECTED]

 

 

-----Original Message-----

From: Martin Marinschek [mailto:[EMAIL PROTECTED] 

Sent: Monday, December 19, 2005 4:09 PM

To: MyFaces Discussion

Subject: Re: Component binding is not refreshed?

 

Hi Jeremy,

 

your conclusion is absolutely right. The getter of the method-binding

will only be called once - then the component is recreated from the

saved state, and will not be created by calling your getter.

 

You'll understand this if you think about the state saving feature of

JSF - if you would be able to provide a new component at every

request, how would the state saving ever work?

 

If you want to change your component, you'll need to provide a

_setter_ for the component, and do the modifications there or in an

action-method (which runs after the setter for the component has been

called, so you can access the actual JSF component there). The setter

will be called on every request!

 

regards,

 

Martin

 

On 12/19/05, Jeremy Sager <[EMAIL PROTECTED]> wrote:

> 

> 

> 

> Hey guys -

> 

> 

> 

> Thanks in advance for your help.

> 

> 

> 

> I have a panelTabbedPane that I am binding directly to a bean so that I

can

> create the pane programmatically.

> 

> 

> 

> Here is the tag definition:

> 

> 

> 

> <t:panelTabbedPane binding="#{editorPanelBean.pane}"/>

> 

> 

> 

> Now, in my bean, I have the getPane() method. I have included the entire

> class file here (don't worry, it's not big) except for the package and

> import declarations. The IEditorPanelTabBean list can be safely ignored,

> it's not being used.

> 

> 

> 

> 

> 

> /**

> 

>  * @jsf.bean name="editorPanelBean" scope="session"

> 

>  */

> 

> public class EditorPanelBean {

> 

> 

> 

>       private ArrayList<IEditorPanelTabBean> tabs = new

> ArrayList<IEditorPanelTabBean>();

> 

> 

> 

>       private String TABBEDPANE =

> "org.apache.myfaces.HtmlPanelTabbedPane";

> 

>       private String PANELTAB = "org.apache.myfaces.HtmlPanelTab";

> 

> 

> 

>       //private String TABBEDPANE =

> HtmlPanelTabbedPane.class.getName();

> 

>       //private String PANELTAB = HtmlPanelTab.class.getName();

> 

> 

> 

>       private UIComponent pane = null;

> 

>       private HtmlPanelTab tab = null;

> 

> 

> 

>       private int numtimes = 0;

> 

> 

> 

>       public UIComponent getPane (){

> 

>             FacesContext context = FacesContext.getCurrentInstance();

> 

>             Application app = context.getApplication();

> 

> 

> 

>             if (pane == null){

> 

>                   pane = app.createComponent(TABBEDPANE);

> 

>             }

> 

> 

> 

>             if (tab == null){

> 

>                   tab = (HtmlPanelTab)app.createComponent(PANELTAB);

> 

>             }

> 

> 

> 

>             numtimes ++;

> 

>             System.out.println("Numtimes = " + numtimes);

> 

>             tab.setLabel(Integer.toString(numtimes));

> 

> 

> 

>             pane.getChildren().add(tab);

> 

> 

> 

>             return pane;

> 

>       }

> 

> 

> 

> }

> 

> 

> 

> Now, as you can see, it should be printing out to the console the value of

> numtimes.

> 

> 

> 

> When the page first loads, everything goes as expected.  However, if I hit

> the refresh button in my browser, nothing prints out to the console, and

it

> never hits the method in Eclipse's debug mode (which it does on initial

> load).

> 

> 

> 

> I have another tag, for a table, whose data is backed by a bean on the

same

> page (not the same jsp, but they are both imported by another "container"

> page).

> 

> 

> 

> <h:dataTable value="#{todoHandler.todoListModel}" var="list"

> 

>                         first="#{todoHandler.firstRowIndex}"

> 

>                         rows="#{todoHandler.noOfRows}"

> 

>                         styleClass="view" rowClasses="tableRow">

> 

> 

> 

> 

> 

> Now, the method ToDoHandler.getNoOfRows also has a sysout, which DOES

print

> to the console every time I refresh the page, so I know it's not that I'm

> just getting some cached version or that my browser is bugging out.

> 

> 

> 

> They are both session level beans as you can see:

> 

> 

> 

> 

> 

>    <managed-bean>

> 

>       <managed-bean-name>todoHandler</managed-bean-name>

> 

>       <managed-bean-class>(name

> omitted).ToDoListHandler</managed-bean-class>

> 

>       <managed-bean-scope>session</managed-bean-scope>

> 

>    </managed-bean>

> 

> 

> 

> <managed-bean>

> 

>       <managed-bean-name>editorPanelBean</managed-bean-name>

> 

>       <managed-bean-class>(name

> omitted).EditorPanelBean</managed-bean-class>

> 

>       <managed-bean-scope>session</managed-bean-scope>

> 

>    </managed-bean>

> 

> 

> 

> 

> 

> So. what gives? Does the component binding not refresh when the page is

> reloaded, but the value binding does? I know this is a lot of information,

> but I'd rather give too much than too little, and I appreciate any help I

> can get as this has turned into a total blocker issue for me.

> 

> 

> 

> 

> Jeremy Sager

> 

> Data Communications Product Manager

> 

> Chesapeake System Solutions

> 

> 410.356.6805 x120

> 

> 

> [EMAIL PROTECTED]

> 

> 

 

 

--

 

http://www.irian.at

 

Your JSF powerhouse -

JSF Consulting, Development and

Courses in English and German

 

Professional Support for Apache MyFaces

 

 

 

Jeremy Sager

Data Communications Product Manager

Chesapeake System Solutions

410.356.6805 x120

[EMAIL PROTECTED]



Reply via email to