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 how to create common successful page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to create common successful page" Watch "how to create common successful page" New topic
Author

how to create common successful page

cb poo
Ranch Hand

Joined: Oct 02, 2002
Posts: 67
I would like to have one successful.jsp that can call by more that one action. This successful.jsp will show different bean for different actions.

For example of userAction, successful.jsp should show
--------
The record successfully save:-
user = myUserName
password = myUserPassword
--------

For example of AccountAction, successful.jsp should show
--------
The record successfully save:-
account id = 001
account name = myAccount
account type = saving
--------

Guys, any idea how to archieve this using struts? I don't want to create each different success.jsp for different action.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Just create a global forward named success that points to the success.jsp. Any action can forward to a global forward.


Merrill
Consultant, Sima Solutions
cb poo
Ranch Hand

Joined: Oct 02, 2002
Posts: 67
No. I talking about how to create the content of the success.jsp, where it can be shareable across all my action. And the jsp should display bean that successfully save into database for every individual action.
In this case, how do I code the jsp page. I will never know the bean name to display in jsp?
Eugene Lucash
Ranch Hand

Joined: Feb 19, 2005
Posts: 77
It's possible.
first create global forward.
and then in your jsp use some reflection, java.beans.*;
For example Introspector tool (class) to get all of Bean's properties
take a look at api documentation

import java.beans.*;
import java.lang.reflect.*;

Object bean = .....

BeanInfo i = Introspector.getBeanInfo(bean.getClass());
PropertyDescriptor[] p = i.getPropertyDescriptors();
for (PropertyDescriptor prop : p) {
Class clazz = prop.getPropertyType();
String name = prop.getName();
Method m = prop.getReadMethod();
Object value = m.invoke(bean,null);
//do something for each property
//now you have prop's name, type and value, all you need
}

if you can use DynaActionForms it is even simplier

DynaActionForm form = (DynaActionForm )f;
DynaClass dc = form.getDynaClass();
DynaProperty dn[] = dc.getDynaProperties();

for (DynaProperty d : dn){
String propertyName = d.getName();
Class clz = d.getType();
Object value = form.get(propertyName);
// do somethig for each property
}
[ February 23, 2005: Message edited by: Eugene Lucash ]
cb poo
Ranch Hand

Joined: Oct 02, 2002
Posts: 67
The solution above need to have scriplet in my jsp, right? Is there any others way to archive that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create common successful page