Getter method being called twice

Hi All,
I have a h:inputText which updates a h:dataTable as soon as the user types something into it (through the use of Ajax4JSF's a4j:support element). In this way I have something similar to a suggestionbox, but which modifies the table underneath rather than displaying a dropdownlist with possible values. My problem is that for some reason the getter method in the managed request-scoped bean to which the h:dataTable is bound, is being called twice everytime a letter is typed into the h:inputText. The first call seems to happen directly after the bean has been constructed, as the value to which the h:inputText is bound is still empty, and the second call after that, but with the correct value obtained from the h:inputText.
I searched the forums and found posts detailing similar problems, but I couldn't find an explanation of why it happens or a way to get rid of it. The common consensus seems to be to not have any processing intensive operations in the getter and to just accept that it will be called twice.
Is there really no way around this?
Thank you,
Ristretto

This is just the default behaviour of the JSF lifecycle. The first call checks if there is a default value or a value which is been set in the previous request. The second call gets the newly set value for display which is been set during the request processing. A way to get rid of the first call might be writing your own lifecycle implementation.

Similar Messages

  • Servlet doPost being called twice

    Hello all,
    I have a servlet that is being called twice. The servlet is used to direct the user to the next jsp. I have 4 JSPs that the user steps through to add a record to a database. The 1st JSP lists the records that they have and asks them to add, edit or delete. The servlet gets call to direct them to the next JSP that they enter the data (or update) on. It then calls a verification JSP so the user can verify the information before submitting it. If everything is fine they submit the data. This verification JSP calls the servlet that adds or updates the record in the database. The servlet then directs the user to a confirmation page that tells the user if the submit was successful or not.
    Here is how the flow is:
    servlet -->menu.jsp -->servlet -->add.jsp -->verification.jsp -->servlet -->confirmation.jsp
    Everything is fine until the verification.jsp submits to the servlet. That's where the doPost gets called twice.
    I have put System.outs in the servlet code to see how many times the doPost gets called. It gets called once for every JSP except the verification JSP. When the user submits the data, the servlet's doPost gets called twice therefore it tries to add the record twice.
    Has anyone had this problem before? How do I fix it?
    Any help would be greatly appreciated!!
    Tracey

    Here is the output of the JSP that when submitted, calls the doPost twice:
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <TITLE>PreaPaid Legal Banner Verification</TITLE>
    <script language="javascript">
    function new_window(url){
    link = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=650,height=450,left=50,top=50");
    </script>
    </HEAD>
    <BODY>
    <form name="myForm" action="/webapp/BannerTracker/BannerTrackingServlet" method="post">
    <H3><font face="Arial">Banner Tracking Verification</font></H3>
    <table BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=2 WIDTH=500><tr><td>
    <font face="Arial" size=2>Below are the choices that you made for your image, size of the image and page to direct people to
    when they click on your banner.
    <br><br>If this is not what you would like, click the "Back" button to return to the Banner Selection page.
    <br><br>You can click on the page link to view a sample of the age you have choosen.
    </font></td></tr></table>
    <P>
    <font face="Arial" size=2>
    <input type="hidden" name="cmd" value="doadd">
    <input type="hidden" name="banname" value="yahoo">
    <input type="hidden" name="banlogin" value="test">
    <input type="hidden" name="banid" value="1">
    <input type="hidden" name="bangname" value="difference">
    <input type="hidden" name="bangsize" value="468x60">
    <input type="hidden" name="banpage" value="go/test?:home">
    <input type="hidden" name="session" value="PPL2P6LcONLiT45pSszZEb1GJ4HvRc5jQMDNPM8wCJ0rCZesD38oEZ4mC3KvCp8mDp00">
    <input type="hidden" name="bangtype" value="gif">
    <input type="hidden" name="banurl" value="<A HREF="http://www.prepaidlegal.com/go/test?banid=1&Assoc=test"><img src="http://www.prepaidlegal.com/html/buttonsdifference468x60.gif" border=0></A>">
    <br><b>Banner name: </b>yahoo
    <br><br><b>Page to be directed: </b>Your PPL Home Page
    <br><br><b>Image selected: </b><img src=/html/buttons/difference468x60.gif >
    <br><br><b>Copy the URL below to the banner source code.</b>
    <br><br><img src="http://www.prepaidlegal.com/html/buttonsdifference468x60.gif " border=0>
    </font>
    <br><br>
    <a><img src="/html/buttons/track_back.gif" border=0 onClick="window.history.back();"></a>
    <input type=image src="/html/buttons/track_continue.gif" border=0 onClick="javascript:document.myForm.submit();">
    </form>
    </BODY>
    </HTML>
    Here is the doPost code from my servlet:
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    System.out.println("doPost called");
    String next = "";
    try
    Command cmd = lookupCommand(req.getParameter("cmd"));
    next = cmd.execute(req);
    } catch (CommandException ce) {
    req.setAttribute("javax.servlet.jsp.jspException", ce);
    next = error;
    } catch (SQLException se) {
    req.setAttribute("javax.servlet.jsp.jspException", se);
    next = error;
    HttpSession mysession = req.getSession(true);
    String session = String.valueOf(mysession.getAttribute("storedSession"));
    if (session.equalsIgnoreCase("null"))
    session = req.getParameter("session");
    try
    checkSession(session);
    } catch (IOException ioe) {
    System.err.println("Session exception: " + ioe.getMessage() + ".");
    next = expire;
    } else {
    try
    checkSession(session);
    } catch (IOException ioe) {
    System.err.println("Session exception: " + ioe.getMessage() + ".");
    next = expire;
    if ( session != null )
    mysession.setAttribute("storedSession", session);
    RequestDispatcher rd;
    rd = getServletContext().getRequestDispatcher(jspdir + next);
    rd.forward(req, res);
    </code>
    I hope this helps.
    Tracey

  • How to find the number of times method being called.....

    hi,
    can any one pls tell me how to find the number of times the method being called......herez the example....
    Refrence ref = new Refrence();
    for(int i = 0;i < arr.length; i++){
    if(somecondition){
    ref.getMethod();
    here i want to know how many times the getMethod() is calling...Is there any method to do this.. i have seen StrackTraceElement class..but not sure about that....pls tell me the solution....

    can any one pls tell me how to find the number of times the method being called......
    herez the example.... http://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal ? in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • HTTP-Post/Get method of calling the query service allows us to build URL

    Hi,
    I am new to webservices.i have requirement that, using a HTTP-Post/Get method of calling the query service that allows us to build an URL and if we call that url it wil populate XML object.i need query LDAP server for getting users manager details ,in request query we wil pass user details.thanks in advance..

    check same issue in java forum and this link:
    http://jakarta.apache.org/commons/httpclient/methods/post.html

  • Controller Is Being Called Twice - Why???

    I think this is going to be a complicated question to answer but I'll try to explain what's going on as best I can. The basic problem I'm having is that the controller class gets called twice for some reason (instead of once) and I have no idea why. I type in a URL in my browser that goes to a JSP page called �myJsp.jsp�. Basically all that page contains is this...
    <tiles:insert definition =�my.tile� flush=�true�/>In my tiles-defs.xml file I have the following listing...<definition
    name="my.tile"
    path="SomeOtherJsp.jsp"
    controllerClass="x.y.z.MyController">
    </definition>
    x.y.z.MyController.java makes some calls to a DAO to retrieve data. MyController.java then puts that data into the requestScope for the JSP below to access...
    SomeOtherJsp.jsp has nothing special in it although it DOES contain a link to myJsp.jsp (and, somehow, it's like this link is being clicked even though I'm not clicking it).
    <a href="myJsp.jsp?someParam=<c:out value="${requestScope.someValue}"/>">Click Here To Do Something</a>If anyone can help I'd greatly appreciate it. By the way, I spoke to someone else who mentioned that I should turn this kind of thing into a struts action instead of doing a deletion within a controller class. I am going to refactor my code to do this. However, I'm still curious to know the answer to my question. Maybe it will help me get a better understanding of exactly what's going on in the world of servlets. :)

    Hi Shiv, <br><br>
    Yes I have placed System.out.println...and a debug point ...<br>
    super.processRequest(pageContext, webBean);<br>
    OAApplicationModule am = pageContext.getApplicationModule(webBean); <br>
    // String personId="13477";<br>
    // Serializable[] parameters = { personId };<br>
    if (!pageContext.isFormSubmission()) {     <br>
    am.invokeMethod("createEmployeeRow", null);<br>
    }<br>
    //am.invokeMethod("initDetails",parameters);<br>
    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!IN Process Request"); <br>
    debug point is at String personID="13477"....<br><br>
    Thanks<br>Soujanya

  • Finalize() method being called multiple times for same object?

    I got a dilly of a pickle here.
    Looks like according to the Tomcat output log file that the finalize method of class User is being called MANY more times than is being constructed.
    Here is the User class:
    package com.db.multi;
    import java.io.*;
    import com.db.ui.*;
    import java.util.*;
    * @author DBriscoe
    public class User implements Serializable {
        private String userName = null;
        private int score = 0;
        private SocketImage img = null;
        private boolean gflag = false;
        private Calendar timeStamp = Calendar.getInstance();
        private static int counter = 0;
        /** Creates a new instance of User */
        public User() { counter++;     
        public User(String userName) {
            this.userName = userName;
            counter++;
        public void setGflag(boolean gflag) {
            this.gflag = gflag;
        public boolean getGflag() {
            return gflag;
        public void setScore(int score) {
            this.score = score;
        public int getScore() {
            return score;
        public void setUserName(String userName) {
            this.userName = userName;
        public String getUserName() {
            return userName;
        public void setImage(SocketImage img) {
            this.img = img;
        public SocketImage getImage() {
            return img;
        public void setTimeStamp(Calendar c) {
            this.timeStamp = c;
        public Calendar getTimeStamp() {
            return this.timeStamp;
        public boolean equals(Object obj) {
            try {
                if (obj instanceof User) {
                    User comp = (User)obj;
                    return comp.getUserName().equals(userName);
                } else {
                    return false;
            } catch (NullPointerException npe) {
                return false;
        public void finalize() {
            if (userName != null && !userName.startsWith("OUTOFDATE"))
                System.out.println("User " + userName + " destroyed. " + counter);
        }As you can see...
    Every time a User object is created, a static counter variable is incremented and then when an object is destroyed it appends the current value of that static member to the Tomcat log file (via System.out.println being executed on server side).
    Below is the log file from an example run in my webapp.
    Dustin
    User Queue Empty, Adding User: com.db.multi.User@1a5af9f
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    User Dustin destroyed. 0
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    User Dustin destroyed. 1
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    User Dustin destroyed. 2
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    User Dustin destroyed. 3
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    User Dustin destroyed. 4
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    User Dustin destroyed. 5
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    User Dustin destroyed. 6
    Joe
    USER QUEUE: false
    INSIDE METHOD: false
    AFTER METHOD: false
    User Dustin pulled from Queue, Game created: Joe
    User Already Placed: Dustin with Joe
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    User Dustin destroyed. 7
    INSIDE METHOD: false
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    User Dustin destroyed. 9
    User Joe destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    User Dustin destroyed. 9
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    INSIDE METHOD: true
    INSIDE METHOD: false
    USER QUEUE: true
    INSIDE METHOD: false
    INSIDE METHOD: false
    It really does seem to me like finalize is being called multiple times for the same object.
    That number should incremement for every instantiated User, and finalize can only be called once for each User object.
    I thought this was impossible?
    Any help is appreciated!

    Thanks...
    I am already thinking of ideas to limit the number of threads.
    Unfortunately there are two threads of execution in the servlet handler, one handles requests and the other parses the collection of User objects to check for out of date timestamps, and then eliminates them if they are out of date.
    The collection parsing thread is currently a javax.swing.Timer thread (Bad design I know...) so I believe that I can routinely check for timestamps in another way and fix that problem.
    Just found out too that Tomcat was throwing me a ConcurrentModificationException as well, which may help explain the slew of mysterious behavior from my servlet!
    The Timer thread has to go. I got to think of a better way to routinely weed out User objects from the collection.
    Or perhaps, maybe I can attempt to make it thread safe???
    Eg. make my User collection volatile?
    Any opinions on the best approach are well appreciated.

  • On Execute operation, the bean getter is being called multiple times

    Hi,
    I have a JCR data control, i am trying to write a method that returns predicate, but this method is being called multiple times, when executing the advanced search operation.
      public List<Predicate> getPredicates() {
      ArrayList<Predicate> predicates = new ArrayList<Predicate>();
       // predicates.add(new Predicate("jcr:content/idc:metadata/idc:xScope",Operator.EQUALS,"GLOBAL"));
      DCBindingContainer bc=(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
      JUCtrlListBinding attrBinding=(JUCtrlListBinding)  bc.findCtrlBinding("StateId");
      Object stateId= attrBinding.getSelectedValue();
      if(stateId instanceof Row){
      predicates.add(new Predicate("jcr:content/idc:metadata/idc:xState"
      , Operator.EQUALS
      ,((Row)stateId).getAttribute("StateId").toString()));
      attrBinding=(JUCtrlListBinding)  bc.findCtrlBinding("DistrictId");
      Object districtId=attrBinding.getSelectedValue();
      if(districtId instanceof Row){
          predicates.add(new Predicate("jcr:content/idc:metadata/idc:xDistrict",Operator.EQUALS,((Row)districtId).getAttribute("DistrictId").toString()));
        attrBinding=(JUCtrlListBinding)  bc.findCtrlBinding("Scope");
        Object scopeId=attrBinding.getSelectedValue();
        if(scopeId instanceof Row){
            predicates.add(new Predicate("jcr:content/idc:metadata/idc:xScope",Operator.EQUALS,((Row)scopeId).getAttribute("ScopeType")));
        AttributeBinding tempAttrBinding=(AttributeBinding)bc.findCtrlBinding("CreatedDate");
        Object createdDate=tempAttrBinding.getInputValue();
        if(createdDate!=null){
            predicates.add(new Predicate("jcr:content/jcr:created",Operator.EQUALS,createdDate.toString()));
        if (predicates.size()>0){
          return predicates;
      return Collections.emptyList();
      } The problem is while it's being called multiple times different list's are being returned which is causing the method not to work . The bean is in pageFlowScope .

    That is bc ADF life cicle... Is always executing 2 times...

  • LoginModule login() method being called multiple times

    I have a J2EE application that is deployed in Oracle 10g 10.1.2.0.2 that implements a cutom login module. The custom class (MyClassLoginModule) implements the LoginModule interface. Everything works great if the username and password entered by an end user are correct. However, it appears that if a user enters an incorrect password after failing authentication the container executes the MyClassLoginModule.login() method again. In some cases, it calls it serveral time each failing authentication.
    This wouldn't be a problem however, the username and password are also the end users workstation accounts. This behaviour is capable of locking their accounts in one failed attempt.
    Any help or insight would be greatly appreciated.

    We're using FORM based authentication. The problem is not with multiple requests, but appears to be an issue with the container. See the following for more info:
    LoginModule login method called twice on unsuccessful logins

  • ProcessAction for portlet being called twice

    I am creating jsr-168 portlets on sun studio 8 . the problem that i am facing is that ProcessAction method seems to be called twice. Yet when i actually deploy the portlet on sun portal server 6 . They run well (i.e the method is called only once) . Can any body explain this? is this a bug or some configuration error at my development simulation server ? please help.
    regards
    Kimi

    This is a known bug indeed. If I'm not mistaken a fix for it was released as part of Update Pack 3 for JSE 8. Please check whether the update is available on the Update Center. Tools->Update Center

  • Graphing: RollOverBoxItemRenderer being called twice

    i have an mx:AreaSeries, and an mx:LineSeries, and an
    itemRenderer in the mx:LineSeries, but for some reason, the
    RollOverBoxItemRenderer is being called on both the AreaSeries and
    the LineSeries - even though it's only in the LineSeries. any ideas
    as to why??

    i have an mx:AreaSeries, and an mx:LineSeries, and an
    itemRenderer in the mx:LineSeries, but for some reason, the
    RollOverBoxItemRenderer is being called on both the AreaSeries and
    the LineSeries - even though it's only in the LineSeries. any ideas
    as to why??

  • NeedHelp -- Process Request is being called twice ?

    Hi,<br>
    Process Request is called twice and row is intialized twice and row is inserting twice in table....<br>
    Thanks<br>
    soujanya

    Hi Shiv, <br><br>
    Yes I have placed System.out.println...and a debug point ...<br>
    super.processRequest(pageContext, webBean);<br>
    OAApplicationModule am = pageContext.getApplicationModule(webBean); <br>
    // String personId="13477";<br>
    // Serializable[] parameters = { personId };<br>
    if (!pageContext.isFormSubmission()) {     <br>
    am.invokeMethod("createEmployeeRow", null);<br>
    }<br>
    //am.invokeMethod("initDetails",parameters);<br>
    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!IN Process Request"); <br>
    debug point is at String personID="13477"....<br><br>
    Thanks<br>Soujanya

  • Unwanted behavior: Action method being called several times

    Hello,
    I have a managed bean that calls a session ejb which itself does a search. The problem is that it is supposed to retrieve a resultset ONCE and the displayed behavior is that it never stop doing so. It fetches the resultset N TIMES.
    Here is the managed bean and the method to look at is the performSearch method:
    package arcoiris;
    import java.util.ArrayList;
    import java.util.List;
    import javax.faces.model.SelectItem;
    public class SearchManagedBean {
        //Collected from search form
        private String keyword;
        private String country;
        private Integer[] postcode;
        private boolean commentExists;
        private Integer rating;
        private boolean websiteExists;
        //Used to populate form
        private List<SelectItem> availableCountries;
        private List<SelectItem> availablePostcodes;
        private List<SelectItem> availableRatings;
        //Retrieved from ejb tier
        private List<EstablishmentLocal> retrievedEstablishments;
        //Service locator
        private arcoiris.ServiceLocator serviceLocator;
        //Constructor
        public SearchManagedBean() {
            System.out.println("within constructor SearchManagedBean");
        //Getters and setters
        public String getKeyword() {
            return keyword;
        public void setKeyword(String keyword) {
            this.keyword = keyword;
        public String getCountry() {
            return country;
        public void setCountry(String country) {
            this.country = country;
        public boolean isCommentExists() {
            return commentExists;
        public void setCommentExists(boolean commentExists) {
            this.commentExists = commentExists;
        public Integer getRating() {
            return rating;
        public void setRating(Integer rating) {
            this.rating = rating;
        public boolean isWebsiteExists() {
            return websiteExists;
        public void setWebsiteExists(boolean websiteExists) {
            this.websiteExists = websiteExists;
        public List<SelectItem> getAvailableCountries() {
            List<SelectItem> countries = new ArrayList<SelectItem>();
            SelectItem si_1 = new SelectItem();
            SelectItem si_2 = new SelectItem();
            SelectItem si_3 = new SelectItem();
            si_1.setValue("2");
            si_1.setLabel("ecuador");
            si_2.setValue("1");
            si_2.setLabel("colombia");
            si_3.setValue("3");
            si_3.setLabel("peru");
            countries.add(si_1);
            countries.add(si_2);
            countries.add(si_3);
            return countries;
        public void setAvailableCountries(List<SelectItem> countries) {
            this.availableCountries = availableCountries;
        public List<SelectItem> getAvailablePostcodes() {
            List<SelectItem> postcodes = new ArrayList<SelectItem>();
            SelectItem si_1 = new SelectItem();
            SelectItem si_2 = new SelectItem();
            SelectItem si_3 = new SelectItem();
            si_1.setValue(new Integer(75001));
            si_1.setLabel("75001");
            si_2.setValue(new Integer(75002));
            si_2.setLabel("75002");
            si_3.setValue(new Integer(75003));
            si_3.setLabel("75003");
            postcodes.add(si_1);
            postcodes.add(si_2);
            postcodes.add(si_3);
            return postcodes;
        public void setAvailablePostcodes(List<SelectItem> availablePostcodes) {
            this.availablePostcodes = availablePostcodes;
        public List<SelectItem> getAvailableRatings() {
            List<SelectItem> ratings = new ArrayList<SelectItem>();
            SelectItem si_1 = new SelectItem();
            SelectItem si_2 = new SelectItem();
            SelectItem si_3 = new SelectItem();
            si_1.setValue(new Integer(1));
            si_1.setLabel("1");
            si_2.setValue(new Integer(2));
            si_2.setLabel("2");
            si_3.setValue(new Integer(3));
            si_3.setLabel("3");
            ratings.add(si_1);
            ratings.add(si_2);
            ratings.add(si_3);
            return ratings;
        public void setAvailableRatings(List<SelectItem> availableRatings) {
            this.availableRatings = availableRatings;
        public Integer[] getPostcode() {
            return postcode;
        public void setPostcode(Integer[] postcode) {
            this.postcode = postcode;
        public List<EstablishmentLocal> getRetrievedEstablishments() {
            return retrievedEstablishments;
        public void setRetrievedEstablishments(List<EstablishmentLocal> retrievedEstablishments) {
            this.retrievedEstablishments = retrievedEstablishments;
        //Business methods
        public String performSearch(){
            System.out.println("performSearchManagedBean begin");
            SearchRequestDTO searchRequestDto = new SearchRequestDTO(this.keyword,this.country,this.postcode,this.commentExists,this.rating, this.websiteExists);
            System.out.println("java bean "+this.keyword+" "+this.country+" "+this.postcode+" "+this.commentExists+" "+this.rating+" "+this.websiteExists);
            SearchSessionLocal searchSession = lookupSearchSessionBean();
            List<EstablishmentLocal> retrievedEstablishments = searchSession.performSearch(searchRequestDto);
            this.setRetrievedEstablishments(retrievedEstablishments);
            System.out.println("performSearchManagedBean end");
            return "success";
        private arcoiris.ServiceLocator getServiceLocator() {
            if (serviceLocator == null) {
                serviceLocator = new arcoiris.ServiceLocator();
            return serviceLocator;
        private arcoiris.SearchSessionLocal lookupSearchSessionBean() {
            try {
                return ((arcoiris.SearchSessionLocalHome) getServiceLocator().getLocalHome("java:comp/env/ejb/SearchSessionBean")).create();
            } catch(javax.naming.NamingException ne) {
                java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
                throw new RuntimeException(ne);
            } catch(javax.ejb.CreateException ce) {
                java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce);
                throw new RuntimeException(ce);
    }Here is the object request passed:
    package arcoiris;
    import java.io.Serializable;
    public class SearchRequestDTO implements Serializable {
        private String keyword;
        private String country;
        private Integer[] postcode;
        private boolean commentExists;
        private Integer rating;
        private boolean websiteExists;
        public SearchRequestDTO() {
        public SearchRequestDTO(String keyword, String country, Integer[] postcode, boolean commmentExists, Integer rating, boolean websiteExists){
            this.keyword=keyword;
            this.country= country;
            this.postcode = postcode;
            this.commentExists = commentExists;
            this.rating = rating;
            this.websiteExists = websiteExists;
        public String getKeyword() {
            return keyword;
        public void setKeyword(String keyword) {
            this.keyword = keyword;
        public String getCountry() {
            return country;
        public void setCountry(String country) {
            this.country = country;
        public Integer[] getPostcode() {
            return postcode;
        public void setPostcode(Integer[] postcode) {
            this.postcode = postcode;
        public boolean isCommentExists() {
            return commentExists;
        public void setCommentExists(boolean commmentExists) {
            this.commentExists = commmentExists;
        public Integer getRating() {
            return rating;
        public void setRating(Integer rating) {
            this.rating = rating;
        public boolean isWebsiteExists() {
            return websiteExists;
        public void setWebsiteExists(boolean websiteExists) {
            this.websiteExists = websiteExists;
    }and here is the session ejb:
    package arcoiris;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import javax.ejb.*;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    public class SearchSessionBean implements SessionBean, SearchSessionLocalBusiness {
        private SessionContext context;
        private arcoiris.ServiceLocator serviceLocator;
        // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
        // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
        // TODO Add business methods or web service operations
         * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
        public void setSessionContext(SessionContext aContext) {
            context = aContext;
         * @see javax.ejb.SessionBean#ejbActivate()
        public void ejbActivate() {
         * @see javax.ejb.SessionBean#ejbPassivate()
        public void ejbPassivate() {
         * @see javax.ejb.SessionBean#ejbRemove()
        public void ejbRemove() {
        // </editor-fold>
         * See section 7.10.3 of the EJB 2.0 specification
         * See section 7.11.3 of the EJB 2.1 specification
        public void ejbCreate() {
            // TODO implement ejbCreate if necessary, acquire resources
            // This method has access to the JNDI context so resource aquisition
            // spanning all methods can be performed here such as home interfaces
            // and data sources.
        // Add business logic below. (Right-click in editor and choose
        // "EJB Methods > Add Business Method" or "Web Service > Add Operation")
        public List<EstablishmentLocal> performSearch(SearchRequestDTO searchRequestDto) {
            System.out.println("within performSearch");
            List<EstablishmentLocal> establishments = new ArrayList<EstablishmentLocal>();
            try {
                Context ctx = new InitialContext();
                DataSource ds = (DataSource)ctx.lookup("java:/guia");
                Connection con = ds.getConnection();
                Statement stm = con.createStatement();
                String query = buildQueryFromSearchRequestDTO(searchRequestDto);
                ResultSet rs = stm.executeQuery(query);
                int rowCount = 0;
                while(rs.next()){
                    rowCount = rowCount + 1;
                    System.out.println("while");
                    try {
                        EstablishmentLocal establishment = lookupEstablishmentBean().findByEstablishmentId(rs.getInt("establishment_id"));
                        establishments.add(establishment);
                        System.out.println("est name "+establishment.getEstablishmentName());
                    } catch (FinderException ex) {
                        ex.printStackTrace();
                    } catch (SQLException ex) {
                        ex.printStackTrace();
                System.out.println("rowCount = "+rowCount);
                rs.close();
                stm.close();
                con.close();
            catch (SearchRequestMalformedException ex){
                ex.printStackTrace();
            }catch (NamingException ex) {
                ex.printStackTrace();
            }catch (SQLException ex){
                ex.printStackTrace();
            //TODO implement performSearch
            return null;
        private String buildQueryFromSearchRequestDTO(SearchRequestDTO searchRequestDto) throws SearchRequestMalformedException {
            StringBuffer sb = new StringBuffer();
            //Head of the query
            sb.append("SELECT ");
            sb.append("e.establishment_id, ");
            sb.append("e.establishment_name, ");
            sb.append("avg(r.rating) as avg_rating ");
            sb.append("FROM ");
            sb.append("establishment e, ");
            sb.append("rating r, ");
            sb.append("comment com, ");
            sb.append("establishment_country ec, ");
            sb.append("country_ref cou ");
            sb.append("where ");
            sb.append("e.establishment_id=ec.establishment_id and ");
            sb.append("ec.country_id=cou.country_id and ");
            sb.append("e.establishment_id=com.establishment_id and ");
            sb.append("r.establishment_id=e.establishment_id and ");
            //Conditional parts of the query
            //If user wants comment to be present
            if(searchRequestDto.isCommentExists()){
                sb.append("e.establishment_id=com.establishment_id and ");
            //If user has typed in a keyword
            if(!searchRequestDto.getKeyword().equals("") && !searchRequestDto.getKeyword().equals(" ")&& searchRequestDto.getKeyword()!=null){
                sb.append("e.establishment_name like '%"+ searchRequestDto.getKeyword() +"%' and ");
            //If user has choosen a country
            if(searchRequestDto.getCountry()!=null && !searchRequestDto.getCountry().equals("") && !searchRequestDto.getCountry().equals(" ")&& searchRequestDto.getCountry()!=null){
                sb.append("ec.country_id = " + searchRequestDto.getCountry() + " and ");
            //If user wants website to be present
            if(searchRequestDto.isWebsiteExists()){
                sb.append("e.establishment_website is not null and ");
    /* conditions
    si utilisateur a renseign� un premier code postal "e.establishment_postcode = 'postcode_one' --si racine
            si autre code postal "or e.establishment_postcode = 'postcode_two'
            ainsi de suite
    and--vient de si racine
            //Tail of the query
            sb.append("0=0 ");
            sb.append("group by e.establishment_id ");
            //If the user wants a minimum rating
            if(searchRequestDto.getRating() != null && searchRequestDto.getRating().intValue()!=0){
                sb.append("having avg(r.rating) >= " + searchRequestDto.getRating());
            sb.append(" ");
            sb.append("order by e.establishment_id ");
            System.out.println("****************************");
            System.out.println(sb);
            System.out.println("****************************");
            return sb.toString();
        private arcoiris.ServiceLocator getServiceLocator() {
            if (serviceLocator == null) {
                serviceLocator = new arcoiris.ServiceLocator();
            return serviceLocator;
        private EstablishmentLocalHome lookupEstablishmentBean() {
            try {
                return (arcoiris.EstablishmentLocalHome) getServiceLocator().getLocalHome("java:comp/env/ejb/EstablishmentBean");
            } catch(javax.naming.NamingException ne) {
                java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
                throw new RuntimeException(ne);
    }I just don't understand why it does so. The peformSearch should be executed ONCE only.
    Here is my face config file:
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE faces-config PUBLIC
      "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
      "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
        <managed-bean>
            <managed-bean-name>SearchManagedBean</managed-bean-name>
            <managed-bean-class>arcoiris.SearchManagedBean</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
        </managed-bean>
        <navigation-rule>
           <description></description>
            <from-view-id>/welcomeJSF.jsp</from-view-id>
            <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>index.jsp</to-view-id>
            </navigation-case>
        </navigation-rule>
    </faces-config>Can anyone help?
    Thanks in advance,
    Julien.

    Just reactivating my thread hoping someone will reply to it....
    Julien.

  • Getting methods to call each other (",)????

    Hi all i wonder if anyone can help me? I'm new to Java and am having a bit of difficulty in processing this program:
    i am required to produce a template called rectangle.java, then i have to produce a second file called rectangle2.java which contains only a 'main' method, this is supposed to act as the test harness for my rectangle class - how do i acomplish this?
    i understand that the two files must be in the same directory, but i am unsure of the structure each of the two files is to take, i think one of the files is providing the other file with raw data that is then manipulated through a method, but i am really not sure how to do this???
    Please help (",) ?????
    cheers

    class Rectangle{
         static double RectangleArea(double a,double b){
              return a * b;
    }class Rectangle2{
         public static void main (String args[]) {
              Rectangle r = new Rectangle();
              double area = r.RectangleArea(12,12);
              System.out.println(area);

  • Using rendered= stops action method being called on commandButton

    Help help help please.
    I have a managed-bean defined at "request" scope. This bean contains an encodedId field which is a string. This string is present in the form as a hidden field. On submit of the form, this setEncodedId is called on my bean, which then decodes the string and does setup of the bean.
    The problem I have is that if I use a commandButton with rendered="#{MyBean.renderNextButton}" and the result of isRenderNextButton() is dependent on encodedId from the submit, then the button IS correctly rendered, but the action tied to the button fails to be called and the same page reloads when the button is clicked.
    However, if I hardcode 'true' as the return value of isRenderNextButton() then the button renders and the action is called correctly.
    I've also noticed that isRenderNextButton() is called four or more times on each submit even through I've only got one button using this rendered expression.
    Any ideas anyone?

    Without spending lots of time investigating, could I
    write my own implementation of commandButton that
    could have the render state encoded in the state
    information I see encoded in the form?I can't understand the reason why you insist to hold the information in the component,
    while the only you should do is to use a session scope bean to hold it using the standard JSF mechanism.

  • DoGet called twice on Tomcat Startup

    Hi,
    I have a problem with my Servlet doGet/doPost method being called twice (sometimes three times) on Tomcat 5 startup with J2SE 1.4 and Java SE 6. This problem happens on both, Firefox and Internet Explorer.
    I only have one Servlet (called ServletFrontController) in my descriptor, since I decided to use the Front Controller Pattern. This Servlet extends from a "base Servlet" which has all the init configurations. My deployment descriptor looks like this (I also have mappings which I haven't included here):
        <servlet>
            <servlet-name>MainServlet</servlet-name>
            <servlet-class>com.myprogram.ServletFrontController</servlet-class>
            <init-param>
                <param-name>config</param-name>
                <param-value>application.properties</param-value>
            </init-param>
        </servlet>My doGet / doPost / doHead methods from the base Servlet just delegate to the ServletFrontController "main" method, like this:
    public final void doGet(HttpServletRequest request, HttpServletResponse response) {
            try {
                process(request, response);
            } catch (Exception e) {
                handleException(e, request, response);
    }Does anyone had this problem and know why this could happen?
    Martin

    All,
    See post: [http://forum.java.sun.com/thread.jspa?threadID=720175|http://forum.java.sun.com/thread.jspa?threadID=720175]
    Might help.
    - JFK

Maybe you are looking for

  • Upload videos

    How do I upload videos from iphone 4 to my computer? Uploaded pictures but can't upload video. Please help.

  • Change Apple ID

    For weeks now I have been trying to find a way to change my Apple ID. My old @mac.com account is now generating a large amount of junk mail. And from the support pages I see many people have the same issue. I would like to completely remove my @mac A

  • YouTube URL's in interactive PDF (InDesign CC)

    Hey guys, I'm wondering if there's a way yet to insert a youtube video URL in an InDesign document, so when exported as a pdf, will play within the pdf. The PDF will be viewed on desktop and mobile devices (including iOS). Right now, I'm finding issu

  • Dynamic where clause with loop statement

    Hi all, is it possible to use a dynamic where clause with a loop statement? Can you please advise me, how the syntax needs to be? Thanks for your suggestions, kind regards, Kathrin!

  • I just purchase a new TC from apple store. But why it is 4th Generation not the 5th one?

    As the title listed, Why my new purchased TC is not the latest 5th generation? Product Description TIME CAPSULE 2TB (4TH GENERATION)-GBR Thank you very much