• 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

populating jsp page dynamically using form beans

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everybody,
I've a general search page where user can input different search criteria.
(for ex. search on name, employee no., location, position etc.)
Its not mandatory to put values in all the input field so some input field may be empty too.(like user may search on name and location only). Now when the user hits the search button; I've to display the search criteria entered by user along with the search results.(say user entered Marie in name and texas in location).
In the result jsp my SearchFormBean(bean used on the search page) will be populated with the name and location.
Now my problem lies in displaying only those values which are present in the bean(name and location). Is there any elegant way to check all the properties of FormBean but displaying only those which are present (or not null).

Thanks in anticipating.
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use logic:notEmpty (struts logic tag lib) or c:if (JSTL) to check empty. uh...on second thought, if the value is empty, it won't show up so what's the point of checking?
 
Rohit Men
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
Actually along with the values I want to populate the labels. Like if the user entered Name as marie and Location as texas; so on the result page I want to display only name and location as:-
Name marie
Location texas
I dont want to diplay other labes for which the user didnt entered any values. (like position, employee no. etc.)
If possible can you explain the answer with the help of code as how to access each attribute of Form bean to check ?
Thanks
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i see the reason. use JSTL and access the form-bean based on the scope in which it was stored. ex:

substitue sessionScope for requestScope if the form-bean is in session. substitue the 'FormBeanName' with whatever your action's form-bean name is.

i can't quite remember, but i believe that the requestScope and sessionScope may not be necessary since JSTL will search through all the scopes automatically.
 
Rohit Men
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alan.

I'll use the following code give by you.

I've 2 more things to incorporate with this.
1)There may be 50(or more) input fields. So I think it'll not be a good idea to use something like FormBeanName.name, FormBeanName.Address, FormBeanName.location in <c:if.... for 50 times. If I can use something generic for my form-bean attributes (name, address,location etc.) that will be great.
(like If I can iterate over the attributes of the form-bean).
2)I'm getting the label for the particular attribute from messageresources.properties file. In the current case where we're testing for each attribute of the form-bean, i can get it using <bean:message key="search.name"/> and similarly for other attributes. But If we're using something dynamic like <c:if test="${requestScope.FormBeanName.$attribute. In that scenario how will I use that generic attribute as a key in <bean:message/>.

Hope I made my problems clear. Thanks a lot for helping me out on this.
 
Rohit Men
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alan,
I found something in this regard.

I think I can use something like:-

will this work?. I'll try it tomorrow morning.
If this works then how to get the <bean:message based on beanAttributes.key?

For my code, if the key is name, address or location the coresponding entry in messageresources.properties file is :-

search.name=Name
search.address=Address
search.location=Location

Thanks.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can also use <logic:iterate> to iterate through the list of values
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
 
Hemamalini Varadachari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I thk we can go for a logic resent tag
<logic resent name="RRSSearchRecord" property="typeOfDate">
<span class="Criteria_Lbl"><bean:message key="Record.TypeofDate" />:</span>
ass="Criteria_Vl"><bean:write name="RRSSearchRecord" property="toDate" /></SPAN>
</logic resent>

We have done this way and it worked fine!!! but we need to do have a logic resent for each for form elements.. :-)

Thanks
Hema
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic