• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

To map backing bean from a selected drop-down value

 
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I've a requirement to map the backing bean class from the object that is selected from the drop-down in my jsf page. How can i do this?
Eg. I've chosen Person from the drop down - I should retrieve a class called Person.java.

Kindly help me with the same..

Thanks in advance
 
Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is what I tried with the Animal and Person bean.







Hope this helps
Thanks
 
N Deepu
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You mean to say u're calling person and animal class from the enum class?
 
Vijay Tidake
Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,

As per your question ,you want the instance of a class,that is selected in dropdown right?

Thanks


 
N Deepu
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to call the class from the object that is selected. In your example, If I select Person, I should call the Person class and perform the corresponding functionality there.

Thanks

 
N Deepu
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,

I was trying to execute what you've replied here. But it is not mapping the value change listener class on change of the option even though I've given
"Onchange = submit()"
 
Saloon Keeper
Posts: 28410
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a problem with definitions here, "Ns". You're not looking to "retrieve" or "call" a class. What you want to do is retrieve an instance of a class.

Beyond that there are several other difficulties.

First of all, you cannot specify a complex (class) object as the key part of a SelectItem. The SelectItem is rendered as HTML, and HTML is text-only, so if you provide a binary object as the key, it will be converted to a String, and by default, that string will be a meaningless sequence of characters of little or no practical use. A better approach is to put all your objects in a Map where each entry has a text key, use that key to instantiate the SelectItem, then have the action handler use that key to retrieve the actual object from the Map.

Secondly, you can't just "submit()". You need proper AJAX support if you want to be able to be notified when a selectOneMenu's selected value has changed.

 
N Deepu
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks. I'll try what you said..
 
N Deepu
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again Tim,

I follwed what you said. I've a Hashmap which has "Key-Label to be displayed" and "Value-The backing bean name". I'm able to retrieve the corresponding name after I select from the drop down. The value received is in the string format. How do I now create an instance of this and call the corresponding class?

Eg. I selected Address, getPropertiesMap().get(event.getNewValue() is giving me the fully qualified name - com.backingbean.Address which is now in string format.

Thanks in Advance
 
Greenhorn
Posts: 10
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ns deep wrote:Hi again Tim,

I follwed what you said. I've a Hashmap which has "Key-Label to be displayed" and "Value-The backing bean name". I'm able to retrieve the corresponding name after I select from the drop down. The value received is in the string format. How do I now create an instance of this and call the corresponding class?

Eg. I selected Address, getPropertiesMap().get(event.getNewValue() is giving me the fully qualified name - com.backingbean.Address which is now in string format.

Thanks in Advance





Should look something like this. (Haven't tested it)
 
N Deepu
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm not getting the answer required. This is bugging me since 3 days. Kindly help me.


This is the exception I'm getting

java.lang.ClassNotFoundException: instance
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.infosys.reuse.Bean.UserBean.valueChanged(UserBean.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)
at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:140)
at javax.faces.event.ValueChangeEvent.processListener(ValueChangeEvent.java:130)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:746)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1161)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
 
Tim Holloway
Saloon Keeper
Posts: 28410
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The server is looking for the following file in your WAR:

/WEB-INF/classes/instance.class

using the Class.forName("instance") as its directive.

I don't think you really wanted to do that, since class names shouldn't begin with lower-case letters and use of the default package is discouraged.
 
Tom mmeke
Greenhorn
Posts: 10
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Every reference to ResourceLoader is static ?
2. Why are you first getting the KeySet, then iterate over the KeySet, to finally request the value from the properties map for each key ?
Why not just iterate the PropertiesMap from the beginning ?
3. Class.forname() expects a classname as parameter (duh), something like 'com.yourpackage.ResourceLoader', and not just the variable you gave an instance of a class ...

Besides, like Tim told you before, you can't expect JSF to give you an entire object as selected value.
Use my previous example, and change valueChanged to this.


Still not sure what your actually trying to achieve with this snippet.
Nevertheless, there is something seriously wrong with your code.
 
N Deepu
Greenhorn
Posts: 28
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply both of you.

This is what I changed and I'm now able to call the method of the Object being selected.

 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic