amol bakre

Greenhorn
+ Follow
since May 21, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by amol bakre

And where did you find this code snippet and question? Always QuoteYourSources please.


noted, I found a similar question on one of the tests of enthuware.

I kind of figured why a '0' was printed and later a 10. What i cant get my head around is why the call to print() from contructor of Parent goes to print() of Child. Why is dynamic dispatch even being considered here as there we are not calling print() on any object from within the constructor!!

I changed the program to read:


and now the program outputs "Polyparent" both times.

So i'm guessing, the compiler has checked that print is a valid overridden method, object type is Child and the runtime has adhering to polymorphism called on the Child's print..
What if i had an init() method in both my classes <for some reason i did not want to use initialization blocks, but init() methods> then i will not be able to initialize my superclass to how i want that to be initialized,

But then i am thinking probably I would only override because i wanted to alter the behaviour in the parent, so this, what's happening is correct, i should just make a call to super.print() (from within Child.print()) if there was some importaint peice that needed to be executed.
Hi,

Yep, it was meant to look like that, sorry about the formatting, i did use the tab and space in the editor but the editor then dropped all of that i suppose, it was the editor not mee!!!. Have read the link you provided will use the code tags in future, and thanks for formatting the program.

Hi,

I have done SCJP2 like years ago (..back in 2001!!..i know) and thought to upgrade my certification to Java 7, although m not really taking the upgrade exam, thought i will give the OCA JP7 and then the OCP JP7, never hurt to go through the concepts and fundamentals again. Anyway, as a part of my prep for the certification i came across this question that i thought was interesting and kinda confusing and would welcome some explanations:
The program:
The question is what will the program output when compiled and run. The answer to the question was given as 0, 10.
I dont know if m just being thick..but i thought it should be PolyParent and then 10, why m thinking this is because when you would do a new PolyChild() it will first try to construct all the parent (super) classes so Object and then PolyParents , and when PolyParent() is being executed then at that time, PolyChild will not have been initialized, so how come a call to print is going to PolyChild's print?? Also, it's not like that print is a static member of PolyChild, its an instance member which should've become known after Static initializers and PolyParents construction??!!


Hi,

I needed to cache some values from the DB into the application as they are static values and used across the application. I am using struts2 and springs jdbc for DB access. I was wondering where should be the best place to do this, is there any facility in struts 2 or should i use springs to do this, tried to find something about spring caching, but looks complicated..lol..or should simply use an onload servlet make pure jdbc calls and cache the parameters / values, which i thought would not be the wisest choice..

Would appreciate suggestions, also where could i find something on spring caching that is simple to understand and write as the job required is pretty simple..

Regards,
Am
14 years ago
Hi,

Oh, i am not much aware of the css etc, javascript did not seem to work properly with struts2, just used script tag directly in the page and tried to refer to the elements but javascript does not recognize the struts2 elements, for example <s:textarea>.
I am not very good with css and javascript or jsp's, had only been writing servlets, ejb's, beans, now springs etc..
Can you help by maybe citing example..

Many thanks..
Regards,
Am
14 years ago
Hi,

Is it possible to change / set the attributes of struts2 UI component dynamically..As an example i will take the following example..

Suppose we have 10 text boxes on a page [<s:textarea>], out of which 5 are necessary and the rest are optional for a user to input data into.
So not to confuse the user i would want to just display 5 by default and give a button for example..lets say "More" which when clicked makes the other 5 visible on the form and the user can input data into these..
I tried to do exactly this but seems that there are problems with java script and the struts2 tags, opening a pop up window and asking the user to input to enter values in that window, take the values back to the parent form as hidden values seems a little cumbersome.

Can anybody let me know of how to achieve this kind of a functionality in Struts2 by changing the attributes, in our case for example disabled attribute or visible attribute (although, i think that this property is not available)..

Thanks a ton in advance..
Regards,
Am
14 years ago
Hi,

O many thanks..i was using JdbcTemplate and i used the query method passing it the SingleColumnRowMapper as you had mentioned in the last, worked well..and was quite easy too, have to nothing but just pass a new instance..

Actually i was using it to get a list so that i can throw that back to the struts2 jsp page (via action etc..) to be displayed in a dropdown list and that is the reason i was looking for just a list..and getting a list and letting struts do all the work seemed a simple way for me to do this..

Thanks a ton..

Regards,
Am
14 years ago
Hi There,

I am new to springs and needed help / opinion.

The thing that i am trying to do is to sue jdbcTemplate's queryForList method to return some data from the DB. This data i pass on to the webpage that expects a lists and takes care of the display etc.

The problem is that the queryForList method is returning to me data in the following form


whereas what i need is just the data. Ofourse i can extract data and stuff, but that i think is dirty and surely there must be some other way to get a List in return (no dao's etc).

Also note i have only one column in the result of my query, stumbled upon SingleColumnRowMapper etc, but did not figure out much how to use them to get a List in return.

Please suggest, preferrably with code example..
Would appreciate a quick response..

Thanks a lot in advance..
Am
14 years ago
O well maybe i am not very good with struts..
What i wanna do is use the same action class to open a jsp form page without having to execute the processing logic contained within the action class.

That is an action class when invoked should just return success and open a jsp form page. however this is the same action class that is invoked (to process and call other services, insert data) after some data entry is done on the jsp form page and submitted to the server..

which is why i though that if there was a way to read the action name then the processing logic in the action class could be bipassed and executed for the case when form is submitted to it.
any suggestions on how to do this thing the simplest and the most efficient way..
14 years ago
Hi,

How can i get the name of the action invoked in my action class so that i can control the behavior of my action class..

What would be the simplest way without having to implement and override etc..

O by the way, m working with Struts2
14 years ago
Hi..

Thanks for your reply....

that helped, although it did not work and i had to research a little more and found..that it had much to do with not having the constructors in my case as i was extending the JdbcDaoSupport Class and overriding methods defined there and giving no template errors..

Thanks..
Am
14 years ago
Hi,
I am very new to springs and not really sure if this has been posted earlier.
Anyway, i had to use springs to construct a new application. i was fiddling around with springs and struts 2 for sometime and finally i have gotten a lot of things ironed out. Coming to springs, i needed that it should use a datasource bound to a JNDI name on the application server. I looked around a bit but everywhere the examples contained how to configure a bean to be used as a datasource with all connection configuration in the application.xml..
Anyway finally i found some information on how to lookup / create datasource from JNDI, but that is giving an error..(gave hundreds of errors but now i am finally very close..is what i believe..lol)
I will mention below a sample of code, will appreciate if somebody could help resolve this problem of mine..thanks in advance..

<beans>
..
..
<bean id="DS_Bbytes" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/grovy_name" />
</bean>
...
...
<bean id="someDao" class="com.x.y.z.someDaoImpl" >
<constructor-arg><ref bean="td"/></constructor-arg>
</bean>
..
..
<bean id="td" class="com.x.y.z.TaskDAOImpl">
<property name="Datasource"><ref bean="DS_Bbytes"/></property>
</bean>
..
..
</beans>

somewhere in the TaskDAOImpl
..
..
jdbcTemplate = getJdbcTemplate();
..


The following error is thrown on startup, btw i am using Tomcat5.5 and oracle DB (9i rel2) (odbc14.jar)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Can't resolve reference to bean 'td' while setting property 'constructor argument'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'td' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Datasource' of bean class [com.x.y.z.TaskDAOImpl]: Bean property 'Datasource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'td' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Datasource' of bean class [com.vodafone.bbytes.spring.TaskDAOImpl]: Bean property 'Datasource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

org.springframework.beans.NotWritablePropertyException: Invalid property 'Datasource' of bean class [com.vodafone.bbytes.spring.TaskDAOImpl]: Bean property 'Datasource' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?

Is this problem due to kind of missing configuration on the tomcat server, for example something like <writable>false</writeable>
14 years ago
Hi,

I solved my problem, i played with the url, intentionally malformed it and then i got a message from the compiler and the valid / expected format..lol..
the format it said that should be used is : "//host:port/service_name"

is a little different, maybe something changed 1.4 onwards,..will find out..