Re: How to call a method in the backing bean from a JSF page
Check out http://struts.apache.org/shale. The documentation is pretty complete and there are nightly build and examples you can download. sean On 8/26/05, Rick Reumann <[EMAIL PROTECTED]> wrote: > I did it by just making the managedBean name the same as the jsp. So in your > case: > > >fooBar > > > > On 8/26/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > > This sounds like it may work for me. I never used Shale, so how do I map > > the backingbean from "fooBar" to "fooBar.jsp" as you mentioned below? in > > face-config.xml? > > > > thanks. > > > > > On 8/24/05, Saul Qunming Yuan < [EMAIL PROTECTED]> wrote: > > >> > > >> Thanks for your response. I guess I didn't make me clear here. My > > >> question > > >> is how to call a method in the backing bean from a JSF page without > > >> rendering out anything to the screen. > > > > > > > > > > > > I would suggest using Shale with JSF. Use the Shale jars and then have > > > your > > > backing bean implement a ViewController (I just extend > > > AbstractViewController), and then you'll have several nice methods you > can > > > override. One is called prerender(). So if you map this backingbean to > the > > > correct path, for example "fooBar", when " fooBar.jsp" is called the > > > prerender method is invoked. That's the ultra simplified explanation and > > > since I'm new to this, others (Craig) will probably elaborate more. It's > > > really useful though for exactly what you want. > > > > > > > > > > > > > > > -- > > > Rick > > > > > > > > > > > > > -- > Rick
Re: How to call a method in the backing bean from a JSF page
I did it by just making the managedBean name the same as the jsp. So in your case: fooBar On 8/26/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: This sounds like it may work for me. I never used Shale, so how do I mapthe backingbean from "fooBar" to "fooBar.jsp" as you mentioned below? inface-config.xml?thanks.> On 8/24/05, Saul Qunming Yuan < [EMAIL PROTECTED]> wrote:>>>> Thanks for your response. I guess I didn't make me clear here. My>> question>> is how to call a method in the backing bean from a JSF page without >> rendering out anything to the screen.>>>> I would suggest using Shale with JSF. Use the Shale jars and then have> your> backing bean implement a ViewController (I just extend > AbstractViewController), and then you'll have several nice methods you can> override. One is called prerender(). So if you map this backingbean to the> correct path, for example "fooBar", when " fooBar.jsp" is called the> prerender method is invoked. That's the ultra simplified explanation and> since I'm new to this, others (Craig) will probably elaborate more. It's> really useful though for exactly what you want. >>>>> --> Rick>-- Rick
Re: How to call a method in the backing bean from a JSF page
This sounds like it may work for me. I never used Shale, so how do I map the backingbean from "fooBar" to "fooBar.jsp" as you mentioned below? in face-config.xml? thanks. > On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: >> >> Thanks for your response. I guess I didn't make me clear here. My >> question >> is how to call a method in the backing bean from a JSF page without >> rendering out anything to the screen. > > > > I would suggest using Shale with JSF. Use the Shale jars and then have > your > backing bean implement a ViewController (I just extend > AbstractViewController), and then you'll have several nice methods you can > override. One is called prerender(). So if you map this backingbean to the > correct path, for example "fooBar", when "fooBar.jsp" is called the > prerender method is invoked. That's the ultra simplified explanation and > since I'm new to this, others (Craig) will probably elaborate more. It's > really useful though for exactly what you want. > > > > > -- > Rick >
Re: How to call a method in the backing bean from a JSF page
I agree with Rick. Shale is what you want if you want to do something before rendering. In fact, there is a prerender method in the ViewControllr interface for just such an occassion. sean On 8/25/05, Rick Reumann <[EMAIL PROTECTED]> wrote: > On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > > Thanks for your response. I guess I didn't make me clear here. My question > > is how to call a method in the backing bean from a JSF page without > > rendering out anything to the screen. > > > I would suggest using Shale with JSF. Use the Shale jars and then have your > backing bean implement a ViewController (I just extend > AbstractViewController), and then you'll have several nice methods you can > override. One is called prerender(). So if you map this backingbean to the > correct path, for example "fooBar", when "fooBar.jsp" is called the > prerender method is invoked. That's the ultra simplified explanation and > since I'm new to this, others (Craig) will probably elaborate more. It's > really useful though for exactly what you want. > > > > > -- > Rick
Re: How to call a method in the backing bean from a JSF page
On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: Thanks for your response. I guess I didn't make me clear here. My questionis how to call a method in the backing bean from a JSF page withoutrendering out anything to the screen. I would suggest using Shale with JSF. Use the Shale jars and then have your backing bean implement a ViewController (I just extend AbstractViewController), and then you'll have several nice methods you can override. One is called prerender(). So if you map this backingbean to the correct path, for example "fooBar", when "fooBar.jsp" is called the prerender method is invoked. That's the ultra simplified explanation and since I'm new to this, others (Craig) will probably elaborate more. It's really useful though for exactly what you want. -- Rick
Re: How to call a method in the backing bean from a JSF page
Hi, i think you are looking for somthing like a PhaseListener. You can configure such a Listener in faces.xml. make your listener to return javax.faces.event.PhaseId.RENDER_RESPONSE in getPhaseId() method and the beforePhase() method of your listener is invoked just before rendering. Saul Qunming Yuan wrote: > I see. The outputText way is actually what I did. So, is there a way to > call a method in the backing bean when/before loading a JSF page? > Something like a pre-render method before loading a JSF page? I can do > that in the backing bean methods that forward to the JSF page, but there > are many places that could forward to that JSF page. That's why I trying > to do it in the JSF page itself. > > thanks -- Don't answer to From: address! Mail to this account are droped if not recieved via mailinglist. To contact me direct create the mail address by concatenating my forename to my senders domain.
Re: How to call a method in the backing bean from a JSF page
but remember that getter may be called few times! i assume that in order to see your page user must click sth (ex. somme kind of menu) and i assume that u have action binded to that click that returs string maped to desired page. so just add call your method in that action. Słąwek Sobótka > Thanks for your reply, that makes sense. But won't h:commandLink render a > link and h:commandButton render a button in the page? I don't want to > display anything on the screen. My purpose is to initiate a call from the > JSF page to a method in the backing bean when the JSF page loads. I'm > returning an empty string from the method so nothing gets printed out from > . > > > - Original Message - > From: "Ken" <[EMAIL PROTECTED]> > To: "MyFaces Discussion" > Sent: Wednesday, August 24, 2005 9:53 PM > Subject: Re: How to call a method in the backing bean from a JSF page > > > > Try h:commandLink or h:commandButton. > > If your method returns a string that doesn't match any navigation-rule > > in your faces-confix.xml then the same page you came from will be > > rendered again. > > > > > > On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > >> > >> Hi, > >> > >> I'm wondering what's the correct way to call a method in the backing bean > >> from a JSF page. What I tried is to use >> value="#{theBackingBean.theMethod}" />, the backing bean method returns > >> an > >> empty string, so nothing gets printed out in the page. Which works, but I > >> am > >> not sure this is the correct way to do it. > >> > >> thanks, > >> Saul > >
Re: How to call a method in the backing bean from a JSF page
I am not sure if this is the best way, but one idea that could work is to create a PhaseListener that acts after the view is restored. In this phase listener, you could check if the view being restored is the view for which you want to call your backing bean method. Then, you could obtain a MessageBinding object for your backing bean expression and use that to call your method. Create YourPhaseListener and register it in faces-config.xml: ... com.yourcompany.YourPhaseListener public class YourPhaseListener implements PhaseListener { public void beforePhase(PhaseEvent event) { // Nothing to do } public void afterPhase(PhaseEvent event) { FacesContext facesContext = event.getFacesContext(); UIViewRoot viewRoot = facesContext.getViewRoot(); String idOfYourPage = ... if (viewRoot.getId().equals(idOfYourPage)) { Application application = facesContext.getApplication(); String methodExpression = ... Class[] params = ... MethodBinding methodBinding = application.getMessageBinding(methodExpression, params); methodBinding.invoke(facesContext, ...); } public PhaseId getPhaseId() { return PhaseId.RESTORE_VIEW; } } Disclaimer: I haven't tried this code so I don't know if it would work or even compile. -Ken On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > Thanks for your response. I guess I didn't make me clear here. My question > is how to call a method in the backing bean from a JSF page without > rendering out anything to the screen.
Re: How to call a method in the backing bean from a JSF page
Thanks for your response. I guess I didn't make me clear here. My question is how to call a method in the backing bean from a JSF page without rendering out anything to the screen. - Original Message - From: "Sean Schofield" <[EMAIL PROTECTED]> To: "MyFaces Discussion" Sent: Wednesday, August 24, 2005 10:04 PM Subject: Re: How to call a method in the backing bean from a JSF page The value attribute should be a *value* binding expression. It must bind to a *property*. So you do something like this ... value=#{theBackingBean.foo}" and in your backing bean you have public String getFoo() { ... } public void setFoo(String fooValue) { ... } sean On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: Hi, I'm wondering what's the correct way to call a method in the backing bean from a JSF page. What I tried is to use value="#{theBackingBean.theMethod}" />, the backing bean method returns an empty string, so nothing gets printed out in the page. Which works, but I am not sure this is the correct way to do it. thanks, Saul
Re: How to call a method in the backing bean from a JSF page
I see. The outputText way is actually what I did. So, is there a way to call a method in the backing bean when/before loading a JSF page? Something like a pre-render method before loading a JSF page? I can do that in the backing bean methods that forward to the JSF page, but there are many places that could forward to that JSF page. That's why I trying to do it in the JSF page itself. thanks - Original Message - From: "Ken" <[EMAIL PROTECTED]> To: "MyFaces Discussion" Sent: Wednesday, August 24, 2005 10:17 PM Subject: Re: How to call a method in the backing bean from a JSF page Yes, commandLink and commandButton will render an anchor tag. If you don't want to do this you can do work in your properies getter method when it gets called by outputText value and return an empty string. However, I don't believe there is any guarante as to call order. Putting your target outputText in the first line of your jsp file doesn't mean it will get called before other getter methods further down in the jsp file get called. On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: Thanks for your reply, that makes sense. But won't h:commandLink render a link and h:commandButton render a button in the page? I don't want to display anything on the screen. My purpose is to initiate a call from the JSF page to a method in the backing bean when the JSF page loads. I'm returning an empty string from the method so nothing gets printed out from . - Original Message - From: "Ken" <[EMAIL PROTECTED]> To: "MyFaces Discussion" Sent: Wednesday, August 24, 2005 9:53 PM Subject: Re: How to call a method in the backing bean from a JSF page > Try h:commandLink or h:commandButton. > If your method returns a string that doesn't match any navigation-rule > in your faces-confix.xml then the same page you came from will be > rendered again. > > > On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: >> >> Hi, >> >> I'm wondering what's the correct way to call a method in the backing >> bean >> from a JSF page. What I tried is to use >> value="#{theBackingBean.theMethod}" />, the backing bean method >> returns >> an >> empty string, so nothing gets printed out in the page. Which works, >> but I >> am >> not sure this is the correct way to do it. >> >> thanks, >> Saul
Re: How to call a method in the backing bean from a JSF page
Yes, commandLink and commandButton will render an anchor tag. If you don't want to do this you can do work in your properies getter method when it gets called by outputText value and return an empty string. However, I don't believe there is any guarante as to call order. Putting your target outputText in the first line of your jsp file doesn't mean it will get called before other getter methods further down in the jsp file get called. On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > Thanks for your reply, that makes sense. But won't h:commandLink render a > link and h:commandButton render a button in the page? I don't want to > display anything on the screen. My purpose is to initiate a call from the > JSF page to a method in the backing bean when the JSF page loads. I'm > returning an empty string from the method so nothing gets printed out from > . > > > - Original Message - > From: "Ken" <[EMAIL PROTECTED]> > To: "MyFaces Discussion" > Sent: Wednesday, August 24, 2005 9:53 PM > Subject: Re: How to call a method in the backing bean from a JSF page > > > > Try h:commandLink or h:commandButton. > > If your method returns a string that doesn't match any navigation-rule > > in your faces-confix.xml then the same page you came from will be > > rendered again. > > > > > > On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > >> > >> Hi, > >> > >> I'm wondering what's the correct way to call a method in the backing bean > >> from a JSF page. What I tried is to use >> value="#{theBackingBean.theMethod}" />, the backing bean method returns > >> an > >> empty string, so nothing gets printed out in the page. Which works, but I > >> am > >> not sure this is the correct way to do it. > >> > >> thanks, > >> Saul > >
Re: How to call a method in the backing bean from a JSF page
Thanks for your reply, that makes sense. But won't h:commandLink render a link and h:commandButton render a button in the page? I don't want to display anything on the screen. My purpose is to initiate a call from the JSF page to a method in the backing bean when the JSF page loads. I'm returning an empty string from the method so nothing gets printed out from . - Original Message - From: "Ken" <[EMAIL PROTECTED]> To: "MyFaces Discussion" Sent: Wednesday, August 24, 2005 9:53 PM Subject: Re: How to call a method in the backing bean from a JSF page Try h:commandLink or h:commandButton. If your method returns a string that doesn't match any navigation-rule in your faces-confix.xml then the same page you came from will be rendered again. On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: Hi, I'm wondering what's the correct way to call a method in the backing bean from a JSF page. What I tried is to use value="#{theBackingBean.theMethod}" />, the backing bean method returns an empty string, so nothing gets printed out in the page. Which works, but I am not sure this is the correct way to do it. thanks, Saul
Re: How to call a method in the backing bean from a JSF page
The value attribute should be a *value* binding expression. It must bind to a *property*. So you do something like this ... value=#{theBackingBean.foo}" and in your backing bean you have public String getFoo() { ... } public void setFoo(String fooValue) { ... } sean On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm wondering what's the correct way to call a method in the backing bean > from a JSF page. What I tried is to use value="#{theBackingBean.theMethod}" />, the backing bean method returns an > empty string, so nothing gets printed out in the page. Which works, but I am > not sure this is the correct way to do it. > > thanks, > Saul
Re: How to call a method in the backing bean from a JSF page
Try h:commandLink or h:commandButton. If your method returns a string that doesn't match any navigation-rule in your faces-confix.xml then the same page you came from will be rendered again. On 8/24/05, Saul Qunming Yuan <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm wondering what's the correct way to call a method in the backing bean > from a JSF page. What I tried is to use value="#{theBackingBean.theMethod}" />, the backing bean method returns an > empty string, so nothing gets printed out in the page. Which works, but I am > not sure this is the correct way to do it. > > thanks, > Saul
How to call a method in the backing bean from a JSF page
Hi, I'm wondering what's the correct way to call a method in the backing bean from a JSF page. What I tried is to use , the backing bean method returns an empty string, so nothing gets printed out in the page. Which works, but I am not sure this is the correct way to do it. thanks, Saul