File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes populating jsp page dynamically using form beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "populating jsp page dynamically using form beans" Watch "populating jsp page dynamically using form beans" New topic
Author

populating jsp page dynamically using form beans

Rohit Men
Greenhorn

Joined: Aug 30, 2005
Posts: 9
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.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
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?


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Rohit Men
Greenhorn

Joined: Aug 30, 2005
Posts: 9
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

Joined: Apr 14, 2005
Posts: 354
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

Joined: Aug 30, 2005
Posts: 9
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

Joined: Aug 30, 2005
Posts: 9
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.
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
you can also use <logic:iterate> to iterate through the list of values
Hemamalini Varadachari
Greenhorn

Joined: Sep 30, 2005
Posts: 3
Hi,


Thanks & Regards<br />Hema
Hemamalini Varadachari
Greenhorn

Joined: Sep 30, 2005
Posts: 3
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: populating jsp page dynamically using form beans