Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Not able to see details of objects in struts iterator in JSP

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have followed a tutorial(struts2,spring and hibernate integration)(set of code snippets) on a website and tried to develop below example according to my needs but I am not able to see appropriated details in view(JSP).

Even after referring to original resource and many other resources I am not able to figure out the issue.

I have copied/attached code snippets and screen-shot of view(JSP) below :

Commentor.java(Hibernate Entity Class)



CommentorAction.java(Struts Action Class)



CommentorBoImpl(Service class implementing interface CommentorBo)



CommentorDAOImpl(DAO class implementing CommentorDAO interface)



Commentor.hbm.xml(Hibernate mapping file)



commentor.jsp(Struts view page(same page is being returned on either adding or listing the commentors))





attached below(first screen-shot) is screen-shot when I am trying to access the application first time(without adding a commentor).

second screen-shot is of page which used to appear after you have entered details and hit submit button.It can be seen that action url has been changed(from listCommentor.action to addCommentor.action).

But I am not able to see the list of commentors which are already been added.

I can see that arraylist is not empty from logs and can confirm that details are being inserted in database properly but not able to display over JSP(commentor.jsp)

Could you please give me an idea..

Also please let me know in case I would have to add other config files(struts,spring) to problem posted.






listCommentor.png
[Thumbnail for listCommentor.png]
Page showing list of commentors and providing fields to add a new commentor
addCommentor.png
[Thumbnail for addCommentor.png]
Second view(same JSP) which appears after hitting submit button on adding details to field
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are these methods being invoked? The name should be in Camel Case (i.e. getCommentorList() )
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response..

Do I have to define these setter and getter for list in my entity class?

 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your entity class is Commentor, right? Why would you declare a getter for a list of Commentor in Commentor?
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see in logs that these methods are not being invoked in my action class(CommentorAction.java)..



Apart from above I can sniff that commentorList.size() is throwing a null pointer exception while execution of commentor.jsp:


2014-06-11 19:59:27,744 [ACTIVE] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)' DEBUG ognl.OgnlValueStack - Caught an exception while evaluating expression 'commentorList.size()>0' against value stack
java.lang.NullPointerException: target is null for method size
at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1367)
at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.ASTChain.getValueBody(ASTChain.java:141)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.ASTGreater.getValueBody(ASTGreater.java:50)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.Ognl.getValue(Ognl.java:494)
at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:255)
at com.opensymphony.xwork2.ognl.OgnlValueStack.getValue(OgnlValueStack.java:358)
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValue(OgnlValueStack.java:347)
at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValueWhenExpressionIsNotNull(OgnlValueStack.java:322)
at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:308)
at org.apache.struts2.components.Component.findValue(Component.java:357)
at org.apache.struts2.components.If.start(If.java:86)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
at jsp_servlet.__commentor._jsp__tag4(__commentor.java:307)
at jsp_servlet.__commentor._jspService(__commentor.java:112)

 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said in my previous post, your method names should be in Camel Case. I even provided you with what the method name should be.
Struts uses reflection to discover properties at run time. If you don't follow the JavaBeans Specification standards on accessor naming, Struts will not be able to find your properties.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

I got it working finally.... ...thanks
But with one glitch ....when I am refreshing the page and even if there is no record in database,automatically last inserted row is displayed..not sure why?
and why I haven't got any error when my setters/getters were not in camel case.
Thanks for your help so far
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ankit Tripathi wrote:
when I am refreshing the page and even if there is no record in database,automatically last inserted row is displayed..not sure why?


How is it displaying the "last inserted row" if "there is no record in database"?
When you "refresh" the page, you are making a request to the server. That executes an action...

Ankit Tripathi wrote:
why I haven't got any error when my setters/getters were not in camel case.


Struts eats a lot of errors that some think would give better feedback to a developer: see this article
Make sure you turn on devmode so you get all the feedback that Struts can give (and make sure you turn it off in production!)
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic