Whether private getter methods is Evil?

Hi!
I was wondering whether it is bad or good to use private getter methods in a class rather than directly accessing private fields?
For instance, I have a getter method for each Swig component used in my program:
    private JButton run;
    private JButton getRun() {
         if (run != null) {
              return run;
        run = new JButton("Run");
        run.setToolTipText("Run");
        run.setIcon(new ImageIcon(ResourceHelper.getImageResource("run.png")));
        run.setEnabled(false);
        run.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                MessageDialog.showPleaseWait(TestRunnerUI.this,
                    "creating logger", new Runnable() {
                        public void run() {
// bla bla bla
        return run;
    }And so for each swing component....
But for example I have such a method:
    private void disconnect() {
        mRunner = null;
        mLogger = null;       
        log.log(Logger.INFO, "disconnected");
        tree.setModel(defaultModel);
        tree.setEnabled(true);
        save.setEnabled(false);
        saveAs.setEnabled(false);
        load.setEnabled(false);
        options.setEnabled(false);
        run.setEnabled(false);
        breakTests.setEnabled(false);
        connect.setEnabled(true);
        disconnect.setEnabled(false);
    }which changes properties of a lot of components...
I don't know whether I should use there private getter methods or not. From the design perspective it seems I should but it also adds some overhead I suppose...

I use accessor methods when writing persistent
classes and javabeans. The key is not to use them by
default, only when required. IMO this does not
violate encapsulation, it hides implementation. Agree. Inside the bean itself you shouldn't use it's accessors either.
The
main benefit being that should you need to refactor
the way a value is retrieved or set you have
localized the changes. Holub will tell you that if
you are using an accessor method to retrieve a value
from an object, in order to do some computation on
that value, you should move the computation into the
object's class instead (hence "getter and setter
methods are evil").Summarized, the public accessors are evil when the code behind does not only return/set the encapsulated value. Solution: refactor, split and rename them to "createSomething", "lookupSomething", "buildSomething", or so.
In this case the topicstarter was talking about private getters tho.

Similar Messages

  • HttpURLConnection and HEAD/GET methods

    I am attempting to validate whether an HTML page exists or not.
    I have found that, for about 7% of the pages checked, HEAD and GET methods return different response codes.
    I have structured my code such:
    1) make initial check using HEAD method
    2) for non valid (200) response codes, recheck the page using the GET method.
    In this case about 75% of the pages that failed using the HEAD method will work when using the GET method.
    So, I guess my questions are:
    1) Does anybody know why HEAD/GET return different response codes?
    2) Does anybody know a better way to check if a page exists?
    Here is the sample program I am using with a few URLs that exhibit this behaviour:
    import java.io.IOException;
    import java.net.HttpURLConnection;
    import java.net.InetAddress;
    import java.net.URL;
    import java.net.UnknownHostException;
    public class Internet
         private final static String DEFAULT_LOCAL_HOST = "127.0.0.1";
         private URL url;
         private HttpURLConnection http;
         private int responseCode;
         private String responseMessage;
         public Internet(URL url)
              this.url = url;
         public boolean isValid()
              try
                   //  Make first attempt using a HEAD request
                   http = (HttpURLConnection)url.openConnection();
                   http.setRequestMethod( "HEAD" );
                   http.connect();
                   System.out.println( "head: " + http.getResponseCode()
                   + " : " + http.getResponseMessage() );
                   //  GET seems to do a better job, try again
                   if ( http.getResponseCode() != HttpURLConnection.HTTP_OK)
                        http = (HttpURLConnection)url.openConnection();
                        http.setRequestMethod( "GET" );
                        http.connect();
                        System.out.println( "get:  " + http.getResponseCode() );
                   responseCode = http.getResponseCode();
                   responseMessage = http.getResponseMessage();
                   if (http.getResponseCode() == HttpURLConnection.HTTP_OK)
                        return true;
                   else
                        System.out.println( http.getResponseMessage() );
                        return false;
              catch (IOException e)
                   responseCode = -1;
                   responseMessage = e.getMessage();
                   System.out.println( e );
                   return false;
         public static void main(String[] args)
              throws Exception
              URL url = new URL( "http://www.trca.on.ca" );
              Internet internet = new Internet( url );
              System.out.println( internet.isValid() );
              url = new URL( "http://school.discovery.com/sciencefaircentral" );
              internet = new Internet( url );
              System.out.println( internet.isValid() );
              url = new URL( "http://www.amazon.com" );
              internet = new Internet( url );
              System.out.println( internet.isValid() );
    }

    Using my sample program:
    1) about 3K of data is transferred
    2) it runs in about 8 seconds
    Using InputStream in = http.getInputStream():
    1) about 73K of data is transferred
    2) it runs in about 15 seconds
    Using the getInputStream() method causes the entire file to be transmitted (even though I don't use any read() methods). I don't care about the data.
    I want the check to be as fast as possible which is why I use the HEAD method. It doesn't transfer the contents of the file. But why in some cases does it show a response code other than 200?

  • Abstract class with set and get methods

    hi
    how to write set and get methods(plain methods) in an abstartc class
    ex: setUsername(String)
    String getUsername()
    and one class is extending this abstract class and same methods existing in that sub class also..... how to write......plz provide some ideas
    am new to programming....
    asap
    thnx in advance

    yes... as i told u.... i am new to coding......
    and my problem is ..... i have 2 classes one is abstract class without abstract methods.. and another class is extending abstract class.....
    in abstract class i have 2 methods...one is setusername(string) and getusername() ..... how to write these two methods.... in abstract class i have private variables username...... when user logins ..... i need to catch the user name and i need to validate with my oracle database and i need to identify the role of that user and based on role of that user i need to direct him to appropriate jsp page.......
    for that now i am writing business process classes..... the above mentioned two classes are from business process.....
    could u help me now
    thnx in advance

  • Can't get my class's getter method to work properly.

    Hello, I am new to Java programming, although I come from C and C++. This is my first post. I am working on a basic Library application that can Checkout and Return books. Eventually I would like to add the ability to read from and write to an XML file containing data for every book.
    My problem right now is that I cannot get my getter method within my Book class to work properly. When I call getData() from within main, and pass the appropriate arguments, instead of filling the variables with that object's data, it leaves them blank! Please help me.
    Here is my method within the Book class, the person and id_num are private.
    /* Gets general Book Instance Data and fills parameters with it */
         public void getData(String n, int num, String c, String d)
              n = this.person;
              num = this.id_num;
              c = this.checkout_date_string;
              d = this.due_date_string;
         }Here is how I am attempting to use it in main:
    String name = "";
    int number = 0;
    String checkout = "";
    String due = "";
    Book book1;
    /*Sets person = John Smith and id_num = 10763*/
    book1 = new Book("John Smith", 10763);
    /*Gets Checkout (todays) date and sets a due date in 2 weeks*/
    book1.Checkout();
    book1.getData(name, number, checkout, due);
    System.out.println("Book1:\n Checkout Date: " + checkout +
                             "\n Due Date: " + due + "\n Is it late: " + book1.isLate() +
                             "\n Person who checked it out: " + name + "\n ID number: " + number +
                             "\n ");Then, Here is the Output:
    Book1:
    Checkout Date:
    Due Date:
    Is it late: false
    Person who checked it out:
    ID number: 0
    Edited by: 987158 on Feb 9, 2013 11:52 AM

    >
    Well I went ahead and made separate methods to return each value. I suppose that will work just as well, especially since now I don't have to declare a bunch of strings and int's to hold the data and pass to the method.
    >
    Well this would never work anyway
    public void getData(String n, int num, String c, String d)None of those can be changed within the method. Strings are immutable and 'int' is passed by value. Each of those parameters will have the same value after the method exits as they did before it was called.
    Your book class should be using 'setters' to set the value of its instance variables.

  • No getter method for property user of bean Problem

    Hi everyone,
    I am new to this struts. I have a samll application to check login. When I run my application I get this message in my server console
    No getter method for property user of bean org.apache.struts.taglib.html.BEAN
    I saw the previous forum for the same topic. I have checked my property names start with appropriate cases. Here is my code
    %@ page language="java" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <html>
    <head><title>Login</title></head>
    <body>
    <html:form action="submit.do">
    <table width="100%" border="0" height=75%>
    <tr>
    <td align="right" >UserName: </td>
    <td><html:text property="user"/></td>
    <tr>
    <tr>
    <td align="right" >Password: </td>
    <td><html:text property="password"/></td>
    </tr>
    <tr>
    <td colspan=2 align="center"><html:submit/></td>
    </tr>
    <tr>
    <td colspan=2 align="center"><html:errors/></td>
    </tr>
    </table>
    </html:form>
    </body>
    </html>
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.*;
    import java.util.*;
    * @author skannan
    * To change this generated comment edit the template variable "typecomment":
    * Window>Preferences>Java>Templates.
    * To enable and disable the creation of type comments go to
    * Window>Preferences>Java>Code Generation.
    public class LoginForm extends ActionForm
    private String user = null;
    private String password = null;
    /* user */
    public String getUser()
    return (this.user);
    public void setUser(String user)
    this.user = user;
    /* password */
    public String getPassword()
    return (this.password);
    public void setPassword(String password)
    this.password = password;
    public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
    // Log the forms data
    servlet.log("Lastname:" + user);
    servlet.log("Address:" + password);
    // Check for mandatory data
    ActionErrors errors = new ActionErrors();
    if (user == null || user.equals("")) {
    errors.add("User", new ActionError("error.user"));
    if (password == null || password.equals("")) {
    errors.add("Password", new ActionError("error.password"));
    return errors;
    I am missing anything in my config files. Please I need help.
    Thanks!

    I did check my struts-config file
    Here is the part of my file
    <!-- ========== Form Bean Definitions ================= -->
    <form-beans>
    <form-bean name="loginForm"
    type="kannan.struts.trailer.checkin.LoginForm"/>
    <form-bean name="checkInForm"
    type="kannan.struts.trailer.checkin.CheckInForm"/>
    </form-beans>
    <!-- ========== Action Mapping Definitions ============ -->
    <action-mappings>
    <action path="/submit"
    type="kannan.struts.trailer.checkin.LoginAction"
    name="loginForm"
    input="/login.jsp"
    scope="request">
    <forward name="success" path="/checkIn.jsp"/>
    <forward name="failure" path="/login.jsp"/>
    </action>
    Still I am getting the error

  • MVC Problem with getter method of table attribute in model class

    Hi,
    I am on 620 SP34. I am writing a bsp application with mvc. One of the model classes has an attribute of type table. I use this attribute in a htmlb-tableview and '//MODEL/ZMY_TAB' for data binding. If I try to activate a getter method for this attribute, the application dumps with exception <i>BSP exception: Structure component with name "ZMY_TAB" does not exist</i>. I find the SAP source, that raising this exception (see below). The source code looks like: <i>"I don't support getter methods for tables in attribute path"</i>! The setter method works fine, so I am at a loss. Has anyone of you wrote a getter method for an table attribute in bsp-mvc? Have I to consider anything special?
    Thanks,
    Carsten
    Main Program CL_BSP_MODEL==================CP
    Source code of CL_BSP_MODEL==================CM00Z
    METHOD IF_BSP_MODEL_BINDING~GET_ATTRIBUTE_DATA_REF
           * check if attribute exists for binding!                                   
             if exists_attribute( l_name ) is initial.                                
               return.                                                                
             endif.                                                                               
    * setter or getter defined? Not supported for DATA REF requests            
             if get_getter( attribute_name = l_name ) is not initial.                 
               raise exception type cx_bsp_inv_component                              
                 exporting name = l_name.                                             
             endif.                                                   

    You have two options:
    1. Make your attributes public. It should work fine.
    2. If you need to process the attribute values before it is used, you can make the attribute private but will need three methods
    GET_T_ZMY_TAB that returns the table
    SET_T_ZMY_TAB that sets the values
    GET_M_T_ZMY_TAB that returns DDIC information about the attribute. The same holds good for structures(Change to GET_S_ and GET_M_S_ ) and simple attributes(Change to GET_ and GET_M_).
    The set and get methods are kind of documented at http://help.sap.com/saphelp_nw04/helpdata/en/fb/fbb84c20df274aa52a0b0833769057/content.htm but there is no mention of the GET_M_ methods. I could not find one single document on the Model part MVC.
    Once I added the GET_M_XYZ methods to my attributes, my BSPs started to work fine.
    Cheers
    Sreekanth

  • I can't over give my variable to the return in the get Method!

    Hello Java Cracks
    At the moment I am working with JDOM. I am able to get access to the XML File with JDOM, but when I want to send, the value of a variable, which I get from the XML File it is not possible. When I try to send the variable to the get Method (getDtdVersion), the value I over give is always �null�. Please help me, and say what the problem is?
    I also post you the second class, where I want to use the variable I over give.
    Here is my code:
    Class 1, I take the String from this class. See the arrow
    package FahrplanXML;
    import java.io.File;
    import java.io.IOException;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    import org.jdom.Attribute;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    import org.xml.sax.InputSource;
    public class FileAuswahl {
    private File filenames;
    private String scheduledtdversion;
    public void ablauf() throws JDOMException, IOException {
    FileAuswaehlen();
    saxwer();
    grundoberflaeche xmloberflaeche = new grundoberflaeche();
    xmloberflaeche.grundoberflaechen();
    public void FileAuswaehlen() {
    JFileChooser datei = new JFileChooser();
    datei.setFileFilter(new FileFilter()
    @Override public boolean accept (File f)
    return f.isDirectory() ||
    f.getName().toLowerCase().endsWith(".xml");
    @Override public String getDescription()
    return "XML-Files";
    int state = datei.showOpenDialog(null);
    if (state == JFileChooser.APPROVE_OPTION )
    filenames = datei.getSelectedFile();
    System.out.println (filenames);
    if (filenames != null)
    try {
    System.out.print(filenames);
    saxwer();
    } catch (JDOMException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    else
    System.out.println("Kein File ausgew�hlt");
    else
    System.out.println("Auswahl abgebrochen");
    System.exit(0);
    //Ausgew�hlter Dateiname an saxwer �bergeben
    public File getNames() {
    System.out.println (filenames);
    return this.filenames;
    public void saxwer() throws JDOMException, IOException {
    //FileAuswahl filename = new FileAuswahl();
    File files = getNames();
    System.out.println (files);
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(files);
    Element schedulemessage = doc.getRootElement();
    //Root Element auslesen
    String sch_msg_dtdversion = schedulemessage.getAttributeValue ("DtdVersion"); // <---
    scheduledtdversion = sch_msg_dtdversion;
    new grundoberflaeche().grundoberflaechen();
    public String getDtdVersion() {
    System.out.println (scheduledtdversion);
    return this.scheduledtdversion;
    Now, you will see the class in which I pass the String. See also arrow...
    package FahrplanXML;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.text.Caret;
    import org.jdom.Attribute;
    import org.jdom.JDOMException;
    public class grundoberflaeche {
    // Layout f�r Laender vorbereiten
    static void addComponent (Container cont,
    GridBagLayout diversemoegl,
    Component laenderdetails,
    int x, int y,
    int width, int height,
    double weightx, double weighty )
    GridBagConstraints grundoberflaechen = new GridBagConstraints();
    grundoberflaechen.fill = GridBagConstraints.BOTH;
    grundoberflaechen.gridx = x; grundoberflaechen.gridy = y;
    grundoberflaechen.gridwidth = width; grundoberflaechen.gridheight = height;
    grundoberflaechen.weightx = weightx; grundoberflaechen.weighty = weighty;
    diversemoegl.setConstraints(laenderdetails, grundoberflaechen);
    cont.add(laenderdetails);
    //Ausw�hlen des XML Files
    public void XMLAuswaehlen() {
    JFrame xmlauswahl = new JFrame("Fahrplan ausw�hlen");
    xmlauswahl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container laenderdetails = xmlauswahl.getContentPane();
    GridBagLayout diversemoegl = new GridBagLayout();
    laenderdetails.setLayout(diversemoegl);
    JButton dateiauswahl = new JButton ("Datei ausw�hlen");
    addComponent(laenderdetails,diversemoegl,dateiauswahl,1,1,1,1,1,1);
    ActionListener ersterdateiauswaehler = new ActionListener()
    public void actionPerformed( ActionEvent e)
    try {
    new FileAuswahl().ablauf();
    } catch (JDOMException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    dateiauswahl.addActionListener(ersterdateiauswaehler);
    xmlauswahl.setSize(150,70);
    xmlauswahl.setVisible(true);
    //Layout machen
    public void grundoberflaechen() {
    JFrame fahrplan = new JFrame("Fahrplanauswahldetails");
    fahrplan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container laenderdetails = fahrplan.getContentPane();
    GridBagLayout diversemoegl = new GridBagLayout();
    laenderdetails.setLayout(diversemoegl);
    //Klassenobjekt aufbauen
    FileAuswahl fileauswahl = new FileAuswahl();
    // Labelsbauen und einbauen in den Fahrpl�nen
    String dtdversion = fileauswahl.getDtdVersion(); // <---
    System.out.println(dtdversion);
    JTextField DtdVersion = new JTextField(1);
    DtdVersion.setText(dtdversion);
    JTextField fahrplanzeit = new JTextField(1);
    fahrplanzeit.setText("123");
    JTextField fahrplanzeita = new JTextField(1);
    fahrplanzeita.setText("piips");
    //JButton oesterreich = new JButton("�sterreich");
    //JButton italien = new JButton("Italien");
    //JButton frankreich = new JButton("Frankreich");
    //JButton spanien = new JButton("Spanien");
    addComponent(laenderdetails,diversemoegl,new JLabel("Fahrplandetails"),0,0,1,1,0,0);
    addComponent(laenderdetails,diversemoegl,DtdVersion,1,0,1,1,0,0);
    addComponent(laenderdetails,diversemoegl,fahrplanzeit,2,0,1,1,0,0);
    addComponent(laenderdetails,diversemoegl,fahrplanzeita,3,0,1,1,0,0);
    // Action Listener f�r Dateiauswahl
    // Action Listener f�r das Speichern der Datei
    //addComponent(laenderdetails,diversemoegl,frankreich,2,1,1,1,0,0);
    //addComponent(laenderdetails,diversemoegl,spanien,3,1,1,1,0,0);
    fahrplan.setSize(600,750);
    fahrplan.setVisible(true);
    Thank you very much for your help....
    Your Java Learner

    I suspect you are setting the scheduledtdversion member in one instance of your FileAuswahl class, but are creating yet another instance of that class and printing the member of that instance, which is null. I notice you are creating a new FileAuswahl instance each time something happens, rather than reusing the same instance.
    FileAuswahl fileauswahl = new FileAuswahl();Ok, new object here. Not the same one that you previously set the scheduledtdversion member in
    String dtdversion = fileauswahl.getDtdVersion();It's null of course, for the reason above.

  • Why do we need private static method or member class

    Dear java gurus,
    I have a question about the use of private and static key words together in a method or inner class.
    If we want to hide the method, private is enough. a private static method is sure not intended to be called outside the class. So the only usage I could see is that this private static method is to be called by another static method. For inner class, I see the definition of Entry inner class in java.util.Hashtable, it is static private. I don't know why not just define it as private. Could the static key word do anything better.
    Could anybody help me to clear this.
    Thanks,

    What don't you get? Private does one thing, andstatic does >something completely different.
    If you want to listen to music, installing an airconditioner doesn't help>
    Hi, if the private keyword is the airconditioner, do
    you think you could get music from the static keyword
    (it acts as the CD player) in the following codes:You're making no sense and you're trying to stretch the analogy too far.
    Private does one thing. If you want that thing, use private.
    Static does something completely different and unrelated. If you want that thing, use static.
    If you want both things, use private static.
    What do you not understand? How can you claim that you understand that they are different, and then ask, "Why do we need static if we have private"? That question makes no sense if you actually do understand that they're different.

  • Private static method

    How do I get access to a private static method of a class?
    I can't just call it by object.privatemethod() , right?

    unless your call is made within the body of the
    class, you cannot call it, otherwise just call it via
    a static ref of the class
    ObjectName.privateMethod()
    (not)
    ObjectInstance.privateMethod()...where "ObjectName" is the name of the class.
    Or you can just call it with privateMethod(), but that tends so suggest "this.privateMethod()" so I'd go with qualifying it with the class name, to be clear.

  • Cant make get method work

    package nim;
    import java.util.Random;
    public class Row {
        private static final int MAX = 21; //max number of stars in row
        private int howmany;
        /** Creates a new instance of Row with 1 to MAX stars*/
        public Row() {
            howmany = 1 + (new Random().nextInt(MAX));
        /**Creates a new instance of Row with n stars
         * @param n number of stars in the row
         *        if n is greater than MAX, n is set to MAX
         *        if n is less than n is set to 1
        public Row (int n) {
            if (n <=0 ) howmany = 1;
            else if (n > MAX) howmany = MAX;
            else howmany = n;
                System.out.println(howmany);
        /**Getter
         * @return number of stars currently in the row
        public int getHowmany() {
            return howmany;
        /**Setter
         * @param howmany number of stars in row
        public void setHowmany(int n) {
           if (n <0 ) howmany = 0;
            else if (n > MAX) howmany = MAX;
            else howmany = n;
    }i have this and im trying to just use the get method but i cant figure out for the life of me how to make this work, the code i came up with is
    package nim;
    public class testtt
    public static void main (String[]args)
         Row a = new Row(5);
         System.out.println(a.getHowmany);
    }and i keep getting the error testtt.java:11: cannot find symbol
    symbol  : variable getHowmany
    location: class nim.Row
         System.out.println(a.getHowmany);does anyone know how to make this work? im getting ready to pull my hair out

    you have missed the brackets of the function call
         System.out.println(a.getHowmany);
         System.out.println(a.getHowmany());

  • ManagedBean getter Method called multiple times

    Hi,
    i have notice that the get method is called so often if i initialize a List.
    Maybe you see a solution?
    ManagedBean
    @ManagedBean(name = "videoBean")
    @SessionScoped
    public class VideoManagedBean extends GeneralManagedBean {
            @PostConstruct
            private void init() {
                this.newVideos = videoSessionBean.getNewVideos();
            public List<VideoEntity> getNewVideos() {
                System.out.println("---------getNewVideos--------------");
                return newVideos;
    }Xhtml
        <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:c="http://java.sun.com/jsp/jstl/core"
              xmlns:p="http://primefaces.prime.com.tr/ui">
            <h:head>
                <meta http-equiv="content-type"
                      content="application/xhtml+xml;charset=utf-8" />
            </h:head>
            <h:body>
                <ui:composition template="/WEB-INF/template/mainTemplate.xhtml">
                    <ui:define name="content">
                        <h:form>
                            <p:dataTable var="vid" dynamic="true" value="#{videoBean.newVideos}">
                            </p:dataTable>
                        </h:form>
                    </ui:define>
                </ui:composition>
            </h:body>
        </html>The logfile shows:
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------
        INFO: ---------getNewVideos--------------Is that normal? I never read about this problem

    Whoa there, jumping to conclusions calling this a problem right from the start.
    Yes its expected behavior. The getter can get called from several JSF lifecycle phases. I suggest you study what they are, otherwise you'll run into plenty more of these head scratching moments.

  • Getter method for Generic type in BinarySearchTree

    Hi, I had to write an implementation of a BinarySearchTree for an assignment.
    I have the two classes, one 'BinarySearchTree' which basicly just points to the root, and the node that does most of the work:
    public class BinaryNode<K extends Comparable<K>,V>
         public K _key;
         public V _val;
         private BinaryNode _left;
         private BinaryNode _right;
         public V getVal() //getter
              return _val;
    }In my BinarySearchTree class I use this getter method like so:
    V nodeValue;
    nodeValue = (V) oldNode.getVal();The thing I don't understand is why I have to cast the value returned? If I don't it won't compile!
    It is working fine as is, but my lecturer is always saying to avoid casts.
    Thanks,
    Austin.

    Your BinaryNode class looks OK.
    Could you post a small piece of code I can compile and run and results in the compile error you described? (Don't post the entire thing!)
    Thanks.

  • Need HELP with error!! Property has no getter method

    I am trying to display data info for each user by getting the user value which is already in the session but I keep getting this error.
    Exception: Error looking up property "info" in object type "test.info". Cause: Property 'info' has no getter method
    //info.java
    public class info {
    public info(){
      public Collection getinfo(String user) throws SQLException {
                    ArrayList list = new ArrayList();        
    String sql = "SELECT ADDR where USER= ?";
                    try {//connect statement
    pstmt = con.prepareStatement(sql);
    pstmt.setString(1, user);
    rs = pstmt.executeQuery();
    while(rs.next()) {
                    Infobean tsel = new Infobean(rs.getString("ADDR"));
    list.add(tsel);
                            return list;
    //Infobean.java
    public class Infobean
    private String ADDR;
    private String user;
    public Infobean(){
    public Infobean(String ADDR, String user){
    setAddr(Infobean);
    setUser(user);
    public String getAddr(){
    return ADDR;
    public String getUser(){
    return user;
    public void setAddr(String ADDR){
    this.ADDR = ADDR;
    public void setUser(String user){
    this.user= user;
    //.jsp file
    <jsp:useBean id="test" class="info" scope="request"/>
    <display:table name="test.info"/>

    sorry =\
    "package test;
    public class info();".
    test is the package.

  • Private final method

    When can we use private final method. Could you please give some detail explanation
    Thanks

    Did you look at the output? No, I did never execute the code, and I didn't even
    look at the code that much (as you can see from my
    previous post)Sorry. I was posting while you were continuing to reply.
    I found that if I put this in B I get a compile error.
    public static void main(String[] args){
        A b = new B();
        System.out.println(b);
        System.out.println(b.isFoo());//this surprises me
    A.java:27: isFoo() has private access in A
        System.out.println(b.isFoo());//this surprises meWhich is still puzzling to me somehow. What happened to B isFoo in this case? I didn't think that referencing by the supertype would have worked like this.

  • Oracle.jbo.AttrValException: JBO-27019: Get method for attribute

    Hi Guys,
    I am trying to add a new column to Oracle quoting.It has already been customized by some consultant few years back. I followed the note 392728.1 on metalink and also have the documentation by the previous consultant but getting the error oracle.jbo.AttrValException: JBO-27019: Get method for attribute Draft in HeaderVO could not be resolved after adding my column, when I try to print the quote.
    Here are the steps I took
    1) added a column to the query (at the end) in HeaderVO.xml
    2) added the below code in the HeaderVO.xml
    <ViewAttribute
    Name="DRAFT"
    IsQueriable="false"
    IsPersistent="false"
    Precision="100"
    Type="java.lang.String"
    AliasName="DRAFT"
    ColumnType="VARCHAR2"
    Expression="DRAFT"
    SQLType="VARCHAR" >
    <DesignTime>
    <Attr Name="_DisplaySize" Value="100" />
    </DesignTime>
    </ViewAttribute>
    3). Modify HeaderVORowImpl.java file to add setters and getters for the newly added view attribute. For example,
    a) case 67: //
    setDRAFT((String)obj);
    return;
    b) case 67:
    return getDRAFT();
    c) ublic void setDRAFT(String s)
    setAttributeInternal(67, s);
    public String getDRAFT()
    return (String)getAttributeInternal(67);
    d) protected static final int DRAFT = 67;
    Everything is dont exactly as per the manual but not sure why I am getting this issue. Any help will be appreciated.

    a) case 67: //
    setDraft((String)obj);
    return;
    b) case 67:
    return getDraft();
    c)public void setDraft(String s){
    setAttributeInternal(67, s);
    public String getDraft(){
    return (String)getAttributeInternal(67);
    d) protected static final int DRAFT = 67;
    can u change it as explained above.. setDRAFT should be setDraft.. and getDRAFT should be getDraft..
    and make sure that the index.. number is exactly matching with the attribute order in the VO

Maybe you are looking for