• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Get FormBean's property in JSP page.

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using Struts 1.1 in this topic. I have a very simple page with only 1 input field for age. I assign it to DynaActionForm with request scope. Then I create a simple Action class that does nothing but forwarding to the landing page, which is a jsp page. At landing page, I want to display different messages based on the age field in Formbean. At landing page, I am trying to get the value of age field from the FormBean and assign it to a java variable so I can perform logic in jsp page, meaning using <% %> scriplet. Here is the pseudocode of landing page
########################################
<% Get Age field and assign to java variable.
If (Age < 10) {
%>
Hello Kid
<% }else if (Age between 10 - 20){
%>
Hello Dude
<% }else{
%>
Hello Folks
<% } %>
##########################################
Can someone give me some clue?
Thanks

########################################
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
make the action scope session
S
 
sandy gupta
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and yeah you should use the struts bean tag to get the property value of the bean members.
<bean:write property="age"/>
will print the age value on the page for you.
OR
You could get the form from the scope that u set it in session/request using the name attribute that u specify in the struts config and then call the getters and setters. The solution above is cleaner.
S
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not very clear about this.
<bean:write property="age" /> will output to the page. How can I assign this value in jsp scriptlet?
<% int age = <bean:write property="age"/> ; %>
Something like that?

Thanks
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic