Hi Bruno,

The problem in your counter sample is that you are setting the rendered
property in the requestScope. This means that the button will be rendered
for the ajax request executed by your "Show counter button" commandButton,
but afterwards (in any following request) its rendered property again is
false. Thus it will not be executed by any following request and this is the
reason it doesn't work. However it is not removed from the HTML page,
because your ajax actions only render the counter.

You can change this behavior by e.g. setting the rendered property in
sessionScope. Then it works perfectly - I just tried it myself!

Regards,
Jakob

2010/5/18 Bruno Aranda <[email protected]>

> Mmh, forget the sample code for the page... copy paste error, this is the
> one:
>
> ?xml version="1.0" encoding="ISO-8859-1" ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";
>  xmlns:h="http://java.sun.com/jsf/html";
>  xmlns:f="http://java.sun.com/jsf/core";
>  xmlns:ui="http://java.sun.com/jsf/facelets";
>  xmlns:testComposite="http://java.sun.com/jsf/composite/testComposite";
>  >
> <h:head>
> </h:head>
> <h:body>
>    <h:outputStylesheet name="basic.css"/>
>     <h1>Counter example</h1>
>    <h:messages/>
>
>      <h:form prependId="false">
>
>            <h:outputText id="counter" value="Counter:
> #{counterBean.count}"/>
>
>            <hr/>
>
>            <h:commandButton value="Show counter button">
>                <f:ajax event="click" render="controlPanel"/>
>                <f:setPropertyActionListener value="#{true}"
> target="#{requestScope.renderPanel}"/>
>            </h:commandButton>
>
>            <h:panelGroup id="controlPanel">
>                <h:commandButton value="Increment"
> rendered="#{requestScope.renderPanel}"
>                                 actionListener="#{counterBean.increment}">
>                    <f:ajax event="click" render="counter"/>
>                </h:commandButton>
>                <h:commandButton value="Increment (Visible)"
>                                 actionListener="#{counterBean.increment}">
>                    <f:ajax event="click" render="counter"/>
>                </h:commandButton>
>            </h:panelGroup>
>
>        </h:form>
> </h:body>
> </html>
>
> Cheers,
>
> Bruno
>
> On 18 May 2010 12:00, Bruno Aranda <[email protected]> wrote:
>
> > Hi again,
> >
> > I have been trying to identify where my problem is. I have come with this
> > little example. I have a counter that is incremented using a button. If
> the
> > button has been rendered by a PPR, the actionListener is not invoked,
> > whereas if the button was rendered from the start everything works fine.
> >
> > You can see what I mean here (temporarely, I will stop the server at some
> > point):
> >
> > http://elmoska.com:8080/test-webapp/ajaxAndListener.jsf
> >
> > This is the sample code:
> >
> > <?xml version="1.0" encoding="ISO-8859-1" ?>
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> >         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> > <html xmlns="http://www.w3.org/1999/xhtml";
> >  xmlns:h="http://java.sun.com/jsf/html";
> >  xmlns:f="http://java.sun.com/jsf/core";
> >  xmlns:ui="http://java.sun.com/jsf/facelets";
> >  xmlns:testComposite="http://java.sun.com/jsf/composite/testComposite";
> >  >
> > <h:head>
> > </h:head>
> > <h:body>
> >     <h:outputStylesheet name="basic.css"/>
> >     <h1>Myfaces Examples</h1>
> >     <h:messages/>
> >
> >     <h:form id="form">
> >         <testComposite:compositeCar car="#{carBean.cars[0]}"
> > owner="#{carBean.owner1}"/>
> >
> >     </h:form>
> > </h:body>
> > </html>
> >
> > And the backing bean:
> >
> > package org.apache.myfaces.counter;
> >
> > import javax.faces.bean.ManagedBean;
> > import javax.faces.bean.SessionScoped;
> > import javax.faces.event.ActionEvent;
> > import javax.faces.model.SelectItem;
> > import java.io.Serializable;
> > import java.util.ArrayList;
> > import java.util.List;
> >
> > @ManagedBean
> > @SessionScoped
> > public class CounterBean implements Serializable
> > {
> >     private int count;
> >
> >     public int getCount() {
> >         return count;
> >     }
> >
> >     public void setCount(int count) {
> >         this.count = count;
> >     }
> >
> >     public void increment(ActionEvent actionEvent) {
> >         count++;
> >     }
> > }
> >
> > Is this expected? I don't really know what is expected and what is don't
> > these days :)
> >
> > Can provide a svn patch for the test-webapp sample project if needed...
> but
> > is basically adding the code above and registering the bean via enabling
> the
> > scan context-param or adding it to the faces-config...
> >
> > Thanks,
> >
> > Bruno
> >
> >
> >
> > On 14 May 2010 18:13, Jakob Korherr <[email protected]> wrote:
> >
> >> You're welcome!
> >>
> >> OK, great. If you have a way to reproduce it, I can take a look at it.
> >>
> >> Regards,
> >> Jakob
> >>
> >> 2010/5/14 Bruno Aranda <[email protected]>
> >>
> >> > I guess that would work too for that example, but for some reason
> >> c:forEach
> >> > is not working for me at the moment (using JSP/EL 2.2). I will
> >> investigate
> >> > that later...
> >> >
> >> > Bruno
> >> >
> >> > On 13 May 2010 17:52, Mark Struberg <[email protected]> wrote:
> >> >
> >> > > Maybe I'm on the completely wrong track, but does it work with
> >> c:forEach?
> >> > >
> >> > > LieGrue,
> >> > > strub
> >> > >
> >> > > --- On Thu, 5/13/10, Jakob Korherr <[email protected]> wrote:
> >> > >
> >> > > > From: Jakob Korherr <[email protected]>
> >> > > > Subject: Re: Problem with composite component inside ui:repeat
> >> > > > To: "MyFaces Discussion" <[email protected]>
> >> > > > Date: Thursday, May 13, 2010, 4:08 PM
> >> > > > Hi Bruno,
> >> > > >
> >> > > > This sounds like a bug. I will investigate it!
> >> > > >
> >> > > > Regards,
> >> > > > Jakob
> >> > > >
> >> > > > 2010/5/13 Bruno Aranda <[email protected]>
> >> > > >
> >> > > > > Hi,
> >> > > > >
> >> > > > > I am having some problems to understand this case:
> >> > > > >
> >> > > > > I have a composite component inside a ui:repeat.
> >> > > > Something like this:
> >> > > > >
> >> > > > >  <ui:repeat value="#{testController.objects}"
> >> > > > var="obj">
> >> > > > >
> >> > > >     <myComposite:myComp />
> >> > > > >  </ui:repeat>
> >> > > > >
> >> > > > > And the implementation of the component contains
> >> > > > this:
> >> > > > >
> >> > > > > <composite:implementation>
> >> > > > >    <h:commandButton value="Say something"
> >> > > > actionListener="#{cc.sayHello}">
> >> > > > > <composite:implementation>
> >> > > > >
> >> > > > > And I have the corresponding faces component with the
> >> > > > "sayHEllo"
> >> > > > > actionListener method.
> >> > > > >
> >> > > > > However, I get an exception saying that "cc.sayHello"
> >> > > > cannot be executed
> >> > > > > because "cc" is null for that request.
> >> > > > >
> >> > > > > Everything works as expected outside the ui:repeat, so
> >> > > > it seems that for
> >> > > > > some reason the "cc" is lost after the first request?
> >> > > > Or is this expected
> >> > > > > and I am doing something wrong?
> >> > > > >
> >> > > > > Thanks!
> >> > > > >
> >> > > > > Bruno
> >> > > > >
> >> > > >
> >> > > >
> >> > > >
> >> > > > --
> >> > > > Jakob Korherr
> >> > > >
> >> > > > blog: http://www.jakobk.com
> >> > > > twitter: http://twitter.com/jakobkorherr
> >> > > > work: http://www.irian.at
> >> > > >
> >> > >
> >> > >
> >> > >
> >> > >
> >> >
> >>
> >>
> >>
> >> --
> >> Jakob Korherr
> >>
> >> blog: http://www.jakobk.com
> >> twitter: http://twitter.com/jakobkorherr
> >> work: http://www.irian.at
> >>
> >
> >
>



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Reply via email to