Java constructor

Hi!
My program is ok but I have problem with my second constructor without
parameter. How do I write this constructor? toString method is ok and can reache first constructor but not the second constructor. and how do I call it in my main method.
class ComplexNumber
     private double re;
     private double imag;
    public ComplexNumber ( double  real, double imaginary )
          re=real;
          imag=imaginary;
     public ComplexNumber()
       re=  ;
       imag= ;
    public double getReal(  )
          return re;
    public double getImaginary( )
           return imag;
    public  ComplexNumber  add ( ComplexNumber x )
          ComplexNumber  newComplex = new ComplexNumber();
          ComplexNumber  MyComplex =  this;        
          newComplex.re = MyComplex.re+x.re;
          newComplex.imag = MyComplex.imag+x.imag;
          return  newComplex;      
    public static final ComplexNumber  add ( ComplexNumber x, ComplexNumber y )
          ComplexNumber  newComplex = new ComplexNumber();
          newComplex.re = x.re+y.re;
          newComplex.imag = x.imag+y.imag;
          return  newComplex;
    public static final ComplexNumber  sub ( ComplexNumber x, ComplexNumber y )
       ComplexNumber  newComplex = new ComplexNumber();
          newComplex.re = x.re-y.re;
          newComplex.imag = x.imag-y.imag;
          return  newComplex;
    public static final ComplexNumber  mult  ( ComplexNumber x, ComplexNumber y )
         ComplexNumber  newComplex = new ComplexNumber();
         newComplex.re  = x.re * y.re - x.imag* y.imag;
         newComplex.imag= x.re * y.imag + x.imag * y.re;
         return newComplex;
  /*      public static final ComplexNumber  div ( ComplexNumber x, ComplexNumber y)
    public String toString()
          if(imag< 0)
              return re+" - " +(-imag)+"  i ";
          if(imag== 0)
              return re+ " ";
          if(re== 0)
              return imag+"  i "; 
          return re+" + " +imag+"  i ";
   public static void main(String[]args     )
          ComplexNumber com1 = new ComplexNumber(5,-6);
          ComplexNumber com2 = new ComplexNumber(-3,4);
          ComplexNumber myCom = new ComplexNumber();
        System.out.println("         COMPLEX NUMBERS              "); 
    System.out.println("--------------------------------------");
        System.out.println(" Complex number   1:    "+ com1);
        System.out.println(" Complex number   2:   "+ com2);
        System.out.println("======================================");
        System.out.println();
        System.out.println(" Complex nbr1 + nbr2:   "+ add(com1,com2));
        System.out.println();
        System.out.println(" Complex nbr1 - nbr2:   "+ sub(com1, com2));
        System.out.println();
        System.out.println(" Complex nbr1 * nbr2:   "+ mult(com1, com2));
        System.out.println();
    //System.out.println(" Complex nbr1 / nbr2:   "+ divide(com1, com2));
    System.out.println();
    System.out.println("======================================");
        System.out.println(" Complex nbr1 + nbr2:   "+ com1.add(com2));
        System.out.println(myCom.getReal());
        System.out.println(myCom.getImaginary());
 

Now my constructor is ok but How can I count different
complex nbrs with this constructor. I mean in main metod.
     public ComplexNumber()
      re=4;
      imag=5;
public  ComplexNumber  add ( )
          ComplexNumber  newComplex1 = new ComplexNumber();
          ComplexNumber  newComplex2 = new ComplexNumber();
          ComplexNumber  newComplex3 = new ComplexNumber();
          newComplex1.re = newComplex2.getReal()+newComplex3.getReal();
          newComplex1.imag= newComplex2.getImaginary( )+newComplex3.getImaginary( );
          return  newComplex1;      
// main method
System.out.println(" Complex nbr1 + nbr2:   "+myCom);

Similar Messages

  • Calling Java Constructor from Oracle Stored Procedure

    Hi all,
    I have come across a situation where on insert into one Oracle database instance, a trigger will be fired which will call a procedure which in turn calls a Java constructor with 2 string arguments(The Java class is loaded into another instance of Oracle using Loadjava).
    (Note: I don't want to call a static method from the Oracle procedure)
    I have seen some examples where in using links, on insertion into a table another table of another instance can also be updated.
    for ex: "INSERT INTO testuser.sal_audit@mainlink VALUES (?, ?, ?)" where "mainlink" is a DB link between the 2 instances.
    Similarly is it possble to call the Java constructor loaded in another instance?
    I have tried in this way. It's not working.
    create or replace procedure pr_Cust_object(FeData varchar2,szDummy varchar2) as
    LANGUAGE JAVA NAME
    'CustomObject@mainLink(java.lang.String, java.lang.String)';
    end pr_Cust_object;
    Expecting help at the earliest--ASAP.
    Thanks and Regards,
    Narendra S K

    I don't know how to do that, but I would be interested in knowing how long each insert/update/delete (which ever the trigger fires on) takes.
    And the logic for rollbacks is probably really interesting.

  • Problems with java constructor: "inconsistent data types" in SQL query

    Hi,
    I tried to define a type "point3d" with some member functions, implemented in java, in my database. Therefor I implemented a class Point3dj.java as you can see it below and loaded it with "loadjava -user ... -resolve -verbose Point3dj.java" into the database.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    package spatial.objects;
    import java.sql.*;
    public class Point3dj implements java.sql.SQLData {
    public double x;
    public double y;
    public double z;
    public void readSQL(SQLInput in, String type)
    throws SQLException {
    x = in.readDouble();
    y = in.readDouble();
    z = in.readDouble();
    public void writeSQL(SQLOutput out)
    throws SQLException {
    out.writeDouble(x);
    out.writeDouble(y);
    out.writeDouble(z);
    public String getSQLTypeName() throws SQLException {
    return "Point3dj";
    public Point3dj(double x, double y, double z)
    this.x = x;
    this.y = y;
    this.z = z;
    public static Point3dj create(double x, double y, double z)
    return new Point3dj(x,y,z);
    public double getNumber()
         return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
    public static double getStaticNumber(double px, double py, double pz)
         return Math.sqrt(px*px+py*py+pz*pz);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Additionally, I created the corresponding type in SQL by
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CREATE OR REPLACE TYPE point3dj AS OBJECT EXTERNAL NAME
    'spatial.objects.Point3dj' LANGUAGE JAVA USING SQLDATA (
    x FLOAT EXTERNAL NAME 'x',
    y FLOAT EXTERNAL NAME 'y',
    z FLOAT EXTERNAL NAME 'z',
    MEMBER FUNCTION getNumber RETURN FLOAT
    EXTERNAL NAME 'getNumber() return double',
    STATIC FUNCTION getStaticNumber(xp FLOAT, yp FLOAT, zp FLOAT) RETURN FLOAT
    EXTERNAL NAME 'getStaticNumber(double, double, double) return double')
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    After that I tried some SQL commands:
    create table pointsj of point3dj;
    insert into pointsj values (point3dj(2,1,1));
    SELECT x, a.getnumber() FROM pointsj a;Now, the problem:
    Everything works fine, if I delete the constructor
    public Point3dj(double x, double y, double z)
    this.x = x;
    this.y = y;
    this.z = z;
    in the java class, or if I replace it with a constructor that has no input arguments.
    But with this few code lines in the java file, I get an error when executing the SQL command
    SELECT x, a.getnumber() FROM pointsj a;The Error is:
    "ORA-00932: inconsistent data types: an IN argument at position 1 that is an instance of an Oracle type convertible to an instance of a user defined Java class expected, an Oracle type that could not be converted to a java class received"
    I think, there are some problems with the input argument of the constructor, but why? I don't need the constructor in SQL, but it is used by a routine of another java class, so I can't just delete it.
    Can anybody help me? I would be very glad about that since I already tried a lot and also search in forums and so on, but wasn't successful up to new.
    Thanks!

    Dear Avi,
    This makes sense when it is a short code sample (and i think i've done that across various posts), but sometime this is too long to copy/paste, in these cases, i refer to the freely available code samples, as i did above on this forum; here is the quote.
    Look at examples of VARRAY and Nested TABLES of scalar types in the code samples of my book (chapter 8) http://books.elsevier.com/us//digitalpress/us/subindex.asp?maintarget=companions/defaultindividual.asp&isbn=9781555583293&country=United+States&srccode=&ref=&subcode=&head=&pdf=&basiccode=&txtSearch=&SearchField=&operator=&order=&community=digitalpress
    As you can see, i was not even asking people to buy the book, just telling them where to grab the code samples.
    I appreciate your input on this and as always, your contribution to the forum, Kuassi

  • Java constructors

    Right you prob saw me having problems with this earlier. I think i am making progress. I think i have created two constructors within a class, and for one of these constructors i have initialised a time object to 3.45.
    What i am stuck on is outputting this object, you will see in my main what i have attempted to do and you might be able to advise me. This also might sound really stupid but i am learning, but do you need a main in java?? Just wondering because when i compiled my constructors without a main, the process was completed.
    Anyway, heres what i have done:
    import javax.swing.JOptionPane;
    public class Time
    public int hour;
    public int minute;
    public boolean isMorning;
    public Time(){
    hour = 1;
    minute = 0;
    isMorning = true;
    public Time(int hr, int min, boolean bool){
    hour = hr;
    minute = min;
    isMorning = bool;
    public void Time(int hr, int min, boolean bool){
    Time setTime = new Time(3, 45, false);
    public static void main (String[]args)
    System.out.println(setTime.Time());
    }

    That was fun...
    package forums;
    import javax.swing.JOptionPane;
    import java.util.Calendar;
    // see: http://forum.java.sun.com/post!reply.jspa?messageID=10019378
    // see also: http://forum.java.sun.com/thread.jspa?threadID=726758&messageID=4187127
    // especially 24*60*60*1000 won't work because of leap years, days, and seconds.
    public class Time
      public final int hour;
      public final int minute;
      public final boolean isMorning;
      public Time(int hour, int minute, boolean isMorning) {
        this.hour = hour;
        this.minute = minute;
        this.isMorning = isMorning;
      public Time(long ms) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(ms);
        int hr = cal.get(Calendar.HOUR_OF_DAY);
        this.isMorning = (hr <= 12);
        if (!isMorning) hr-=12;
        this.hour = hr;
        this.minute = cal.get(Calendar.MINUTE);
      public Time() {
        this(System.currentTimeMillis());
      public String toString() {
        return String.format("%d:%02d %s", this.hour, this.minute, (this.isMorning?"AM":"PM"));
      public static void main(String... args)  {
        System.out.println( "1:32 AM = " + new Time(1,32,false) );
        System.out.println( "now     = " + new Time() );
        System.out.println( "3:02 PM = " + new Time(1197781366609L) );
      private static void debug(String msg) {
        System.out.println("DEBUG: "+msg);
    }Cheers. Keith.

  • Java constructor overload error

    I just tried a simple java program and it works on Linux but fails on Mac. Here is the code:
    package TestProject;
    public class Main {
               * @param args
              public static void main(String[] args) {
      // TODO Auto-generated method stub
                  int x =5;
                  int y = 6;
                  double a=5.0;
                  double b=6.0;
                  testout to1 = new testout(x,y);
                  testout to2 = new testout(a, b);
                  System.out.println(to1.getIntResult());
                  System.out.println(to2.getDoubleResult());
    package TestProject;
    public class testout {
        private int a=0, b=0;
        private double c=0.0, d=0.0;
        public void testout(int x, int y)
            a = x;
            b = y;
        public testout(double x, double y)
            c = x;
            d = y;
        public double getDoubleResult()
            return c + d;
        public int getIntResult()
            return a + b;
    As you see I have a constructor to pass either two ints or two doubles. When I run the program on Linux I get the expected result. When I run on Mac, the getIntResult returns zero. I debugged the program and the int constructor is using the double instead. I verified on both netbeans and eclipse.
    Looks like a bug but maybe I am doing something stupid.....

    Not being a Java developer, only have taken one semester of Java, and not having slept in a Holiday Inn recently, I couldn't tell you if it is a bug or not, but since an int can be freely cast to a double, maybe the Mac OS X JRE is finding the double, double constructor and saying to itself, "self, I can make those ints into doubles, so let's just use this double, double signature. la la la alaalla lla alllaaaaalllaa la al."
    If you can find documentation in the Java implementation that directs you use the best constructor vice any appropriate constructor, file a bug report.
    I would imagine you should always use the best match, not just one that works.

  • The rules of Java constructors

    A constructor with no parameters will automatically call super(). If I extend an object with a parametered constructor, I need to manually enter that constructor into my subclass constructor "super(a, b)".
    What then of non extended objects? In this non-extended object if I make a constructor that takes parameters doesn't it automatically make calls to super(). It has to to construct an Object object no?
    I haven't read anything regarding this specific behaviour. I was hoping someone could confirm or deny my suspicions.

    jverd wrote:
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.If that would have been a question I wonder how many responds will provide the correct answer.

  • Manipulating C++ Objects in Java Through JNI

    Hi,
    I have some existing C++ classes objects that I would like to access through Java methods. However, if I use a java method to create an instance of a C++ object, and then I want to edit the state of that C++ object through java, how do I reference the correct C++ object.
    For example, if I have a C++ object called Ball, with two variables x and y representing its position and a constructor as well as set methods to set x and y. I then make a java class Ball with the same variables, constructor, and setter methods. But when the java constructor is called, I want the C++ version to be created, and when the java setter methods are called, I want the x and y of the correct C++ Ball instance to change.
    Is this is possible, and if so what are the steps needed?
    Thank you

    See example with C++ structure in
    http://www.sharewareplaza.com/Java-Platform-Invoke-API-Demo-version-download_49212.html

  • Constructor of derived-class has to call constructor  of super-class?

    In java, constructor of derived-class has to call constructor of super-class? there is no way to omit this step?

    Correct. If you do not explicitly call the constructor, a call to the no-arg c'tor, super(), is automatically inserted.
    It would be a mess to have it any other way. You'd be creating objects that are not completely initialized. They'd be in an invalid state.
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Instantiation access to other java classes

    Hello,
    I have a public Java file in my package.
    I want to grant access to only classes of my choice to instantiate my class, irrespective of any package(my constructor is public itself).
    Is there any way?
    eg:
    I have MyJava.java in com.abc;
    I want to give access only to 2 classes even though other classes exist in the same package:
    YourJava1.java in com.abc; (there are other classes in this package)
    YourJava2.java in com.xyz; (there are other classes in this package)
    Thanks.

    Hi,
    I'm not sure about your depths in java knowledge... however, I'm gonna try to help you based on my knowledge...
    whenever "public" modifier will be used any case( doesn't matter if it is Class, method or attributes), it will be visible from any package level. That is the Rule. If you make your constructor as public, then it always be accessible for any class regardless the package level. Otherwise, it would defeat the purpose of "public" modifier.
    Its depends on your business logic why you are trying to do this scenario. But, there are couple of ways to solve the problem...
    Make "MyJava.java"constructor as "protected" AND move whichever class needs to have handle on it into the same package(in this case: "YourJava1.java" and "YourJava2.java"). Thats how only those classes will be able to instantiate "MyJava.java". you may have multiple constructor and one of them can be "public" so that this object also can be accessed from outside of the package...
    Another option might be - make "MyJava.java" as an Interface or an abstract class. So that you can implement it whichever class needs it. This is how you can restrict it someway...
    Hope it helps...

  • Access Java object from Javascript

    Hi
    I'm trying to invoke a Java object from Javascript (scriptengine and all that).
    I want to add scripting features to a GeneXus Java generated app... and I have very basic skills on java too. Sorry for that ;o).
    This is the java code to pass "params" to the scriptengine:
    engine.put("remoteHandle",remoteHandle);
    engine.put("context", context); The remoteHandle (int) and context (com.genexus.ModelContext) pass trough all the gx-java generated programs.
    This javascript works fine:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle).execute( ) ;The remoteHandle conversion is ok (javascript-number to int). The context is optional.
    But if I want to pass context:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle, context).execute( ) ;Fails with this:
    "javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Java constructor for 'uftestjs' with arguments 'number,javax.script.SimpleScriptContext' not found."
    Obviously, no conversion is possible with context (javax.script.SimpleScriptContext to com.genexus.ModelContext).
    There is some way to reference de original context, by the object Id??? or something like that???
    Thanks in advance for any replies!!!
    Greetings from Chile. (I hope you can understand my english!)

    Hi
    Well, since this topic is about java programming I think the place is right here.
    (I use some tricks to embed java statements in genexus objects...)
    I will try to get some help at Artech (GX) on how to build something... to get the conversion needed.
    But they are not focussed on support this kind of questions.
    Anyway, I want to know: do I can to reference an object by the objId?
    I want to code something like this:
    com.genexus.ModelContext context =
                     (com.genexus.ModelContex)getTheObjectFromTheJVM(theObjectId);(powered by google translator, ha!)

  • Calling more than a Java method from C++

    Hi everyone,
    I haven't found any example with infomation about calling a second Java method from C++,after creating a VM from C++ also.
    Here is the code I'm testing:
    JNIEnv *env;
    JavaVM *jvm;
    JDK1_1InitArgs vm_args;
    jint res;
    jclass cls;
    jmethodID mid;
    jobject jobj;
    char classpath[1024];
    vm_args.version = 0x00010001;
    JNI_GetDefaultJavaVMInitArgs(&vm_args);
    sprintf(classpath, "%s%c%s",
    vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
    vm_args.classpath = classpath;
    res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
    if (res < 0) {
    fprintf(stderr, "Can't create Java VM\n");
    exit(1);
    cls = env->FindClass("Consola");
    if (cls == 0) {
    fprintf(stderr, "Can't find Prog class\n");
    exit(2);
    mid = env->GetMethodID(cls, "<init>", "()V");
    if (mid == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(3);
    jobj = env->NewObject(cls, mid);
    if (jobj == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(4);
    jmethodID mid2 = env->GetMethodID(cls, "isVisible", "()Z");
    if (mid2 == 0) {
    fprintf(stderr, "Can't find Prog.main\n");
    exit(5);
    jboolean b = env->CallBooleanMethod(cls, mid);
    All works fine till the last line.
    Folowing message appears in screen running the last code line:
    Runtime error!
    Program: s:\client\mcc_cyg\debg\debug\debgnt.exe
    abnormal program termination
    What to do ?
    Thanks in advance.
    Ignasi Villagrasa.

    There should be examples of this in the JNI tutorial.
    Also suggest a book: essential JNI by Rob Gordon
    Briefly, what you need is a reference to the JVM. (I assume you have this - either because it was given to you when your C code started the JVM, or because it was passed as an argument to your native method.)
    With the reference, you can look up a class, and look up a method, and call the method.
    What about an object reference?
    o You can call a method on an object which was passed to your native method.
    o You can ask one object for a reference to another object.
    o You can call a java constructor, which will return a reference.

  • Calling java method from c function

    Hi,
    I have been through some forums and tutorials, but nothing helps me yet.
    Here's my problem : I want to access java funtion from c function.
    <code java>
    public class MyClass {
    public int oneMethod() {
    return 5;
    </code java>
    <code c++>
    void main(int argc, char *argv[]) {
    // creation of JVM -> no problem
    cls = (env)->FindClass("MyClass");
    if (cls != 0) {
    // it finds the class
    mid = (env)->GetMethodID(cls, "oneMethod", "()I");
    if (mid != 0) {
    // it finds the method
    intReturn = (env)->CallIntMethod(cls, mid);
    printf("Result of oneMethod: %d \n", initReturn);
    </code c++>
    the initReturn gives me 0, and not 5. So what do you think the mistake is ?
    Should I pass by the GetClassObject() funtion, but in this case, what object would I pass in reference since I'm using a call from c to java.
    Thanks a lot for your response, and Happy new Year to all the comunity.

    1. You are - apparently - trying to call a method of a java object.
    2. But you are instead making the call on a class.
    3. You can do one of the following:
    o Pass a reference to the object as you call C.
    o Call some other java method (maybe static) that gets you a reference to a java object.
    o Use JNI to call a java constructor to create a java object.
    o Change your code to get the class object and call a static method.

  • Why are Constructor not inherited?

    Hello,
    how come Java Constructors are not inherited by subclasses? Consider:
    ClassA
    ClassA(someParameters)
    ClassB extends ClassA
    How come do I need to declare a Constructor in ClassB that will accept "someParameters"? Why don't my ClassB simply inherites its parent Constructor?
    Thanks for any insights :-)
    PA.

    Hi,
    Straight from the Java Language Specs:
    2.12 Constructors
    A constructor is used in the creation of an object that is an instance of a class. The constructor declaration looks like a method declaration that has no result type. Constructors are invoked by class instance creation expressions, by the conversions and concatenations caused by the string concatenation operator +, and by explicit constructor invocations from other constructors; they are never invoked by method invocation expressions.
    Constructor declarations are not members. They are never inherited and therefore are not subject to hiding or overriding.
    If a constructor body does not begin with an explicit constructor invocation and the constructor being declared is not part of the primordial class Object, then the constructor body is implicitly assumed by the compiler to begin with a superclass constructor invocation "super();", an invocation of the constructor of the direct superclass that takes no arguments.
    If a class declares no constructors then a default constructor, which takes no arguments, is automatically provided. If the class being declared is Object, then the default constructor has an empty body. Otherwise, the default constructor takes no arguments and simply invokes the superclass constructor with no arguments. If the class is declared public, then the default constructor is implicitly given the access modifier public. Otherwise, the default constructor has the default access implied by no access modifier.
    A class can be designed to prevent code outside the class declaration from creating instances of the class by declaring at least one constructor, in order to prevent the creation of an implicit constructor, and declaring all constructors to be private.
    This should answer your question and then some.
    Try reading the JLS yourself to get answers as to why ... then come back here and get help with how.
    http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html
    Regards,
    Manfred.

  • How to set default value for drop down box in jsf

    Hi,
    Can anyone help me to set the default value in drop down box using <af:selectManyChoice> ?
    As I know there is an unselectedLabel attribute in <af:selectOneChoice> but not valid attribute for <af:selectManyChoice>.
    Any help must be appreciated.
    Regards,
    AK

    Hi Frank
    My entity type is a List in managed bean. I have set the entityType in the constructor of the managed bean. I have attached my code here.
    TPSearchCriteriaBean.java****************************************
    /** Constructor */
    public TPSearchCriteriaBean() {
    super();
    entityType=new ArrayList<String>();
    entityType.add(UIConstants.LIST_ITEM_ALL);
    authorizationType=new ArrayList<String>();
    authorizationType.add(UIConstants.LIST_ITEM_ALL);
    companyType=new ArrayList<String>();
    companyType.add(UIConstants.LIST_ITEM_ALL);
    mrgStatus=new ArrayList<String>();
    mrgStatus.add(UIConstants.LIST_ITEM_ALL);
    legalStatus=new ArrayList<String>();
    setEntityType(entityType);
    setAuthorizationType(authorizationType);
    setCompanyType(companyType);
    setMrgStatus(mrgStatus);
    country = "0";
    //address = new AddressBean();
    UIConstants.java***********************************************************
    public static final String LIST_ITEM_DEFAULT = "select";
    public static final String LIST_ITEM_ALL = "0";
    LOVManager.java*****************************************************************
    public List<SelectItem> getLovList(String lovType, boolean requiredOption_SELECT, boolean requiredOption_ALL)
    log.debug("LOV loading for " + lovType + ": START");
    List<SelectItem> lovList = new ArrayList<SelectItem>();
    //check validity of lov loading request
    validLov:
    for (int i = 0; i < lovTypeArray.length; i++)
    if (lovTypeArray.equals(lovType))
    break validLov;
    log.debug("ERROR: LOV Type not valid.");
    return lovList;
    //First select is replaced by ALL here
    //<-- Select --> should be an option
    if (requiredOption_SELECT)
    lovList.add(new SelectItem(UIConstants.LIST_ITEM_DEFAULT, "--Select--"));
    LOVDao dao = new LOVDao();
    dao.loadLOVValues(lovType, lovList);
    log.debug("LOV Loading successful!");
    //<ALL> should be an option
    if (requiredOption_ALL)
    lovList.add(new SelectItem( UIConstants.LIST_ITEM_ALL, "ALL"));
    return lovList;
    Kindly help me.
    Regards,
    AK

  • How to send a request from a page to another

    Hello,
    I've started a project an I would like to do the following.
    I have :
    -a datasource included in my project
    -a page customer_list.jsp with a list (and data binding a datasource table)
    -a page customer_search.jsp with a text field(where i write my sql request) and a ok button
    -a link (page navigation) between ok button and customer_list.jsp
    I would like, when I clic on the ok button, to go to the customer_list page with datas in the list that result from my sql request.
    What I think :
    -in the ok buton event, create a requestBean object and .... (don't know how to specify it a request, but i'm searching)
    -return "customer_list"
    -in the customer_list.java constructor : recover the requestBean Object (how to do ?) and bind the result to the list.
    I think it's not a good way to do, this is my first project and I don't know yet how to do a good work with JSC2.
    Can you tell me where are the "bugs" with what I want to do ?
    Thanks for your answers
    Nicolas

    I've found !
    let's see my ok button code :
    public String b4_action() {
            String sql = e1.getText().toString();
            try
            getSessionBean1().getCustomerRowSet().setCommand(sql);
            getSessionBean1().getCustomerRowSet().execute();
            catch(SQLException e)
                System.err.println(e);
            return "customer_list";
        }I hope this will help someone else ...
    Nicolas

Maybe you are looking for