aspose file tools*
The moose likes Struts and the fly likes How do preload all the data in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How do preload all the data in Struts" Watch "How do preload all the data in Struts" New topic
Author

How do preload all the data in Struts

Chua Keng Guan
Greenhorn

Joined: Oct 11, 2006
Posts: 10
can anyone pls help me to find how to preload all data for database then display... It is ugent for me... PLS
[ October 11, 2006: Message edited by: Chua Keng Guan ]
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi Keng,
I think that you want to load data from database and display it. I had done in the following fashion.
After a user logs in and is directed to another page(that would show the data from the database) an intermiedate action class is called. This class loads all info from the DB and then displays the relavant page.
Here is a part of the struts-config.xml that would give you an idea.

<action path="/actions/login/userLoggedIn"
type="com.abc.xyz.common.InitCreateAction"
name="initcreateForm" scope="session">
<forward name="admin" path="/actions/showSearchPage.do" />
<forward name="user" path="/actions/showSearchPage.do" />
</action>

<action path="/actions/showSearchPage"
type="com.abc.xyz.search.actions.InitSearchAction"
scope="session" validate="true" input="/forms/login/login.jsp">
</action>

Hope it helps.

Regards,
Roshani


Regards,<br />Roshani
Chua Keng Guan
Greenhorn

Joined: Oct 11, 2006
Posts: 10
Thank.... i will try it because i new in struts not sure about it.... got any simple way or can explain the code... thank you very much
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi Keng,

Let me try to be a little elaborate.

login.jsp- You log in and you should be directed to the display.jsp if the login is correct. It is plain jsp.
display.jsp- Requires to prepopulate the drop down box(combo) from the DB.
DisplayForm.java - Action Form of display.jsp.
DisplayAction.java -Action Class of display.jsp
InitCreateForm.java- In between Form class that would do the pre-population.
InitCreateAction.java- In between action class that would forward to the dispaly.jsp page.

-----------------
display.jsp

<tr>
<td class="tablecolumndark">LOCATION:</td>
<html:select property="userLocation">
<html ptionsCollection name="cat" property="locations"/>
</html:select>
</tr>

-----------------------------
DisplayForm.java

Will have getXXX() and setXXX().
-------------------------------

InitCreateForm.java

public class InitCreateForm extends ValidatorForm
{
private Vector locations =new Vector();

public void setLocations( Vector locations)
{
this.locations=locations;
}

public Vector getLocations()
{
return locations;
}
}
-------------------------------
InitCreateAction.java

public final class InitCreateAction extends Action
{

public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception
{

InitCreateForm initcreateForm = (InitCreateForm)form;
HttpSession session = request.getSession();

try
{
//getLocation() method retrives the values from the DB.
Vector location=getLocation();
initcreateForm.setLocations(location);

}catch(Exception e )
{
e.printStackTrace();
}
if (some condition)
return mapping.findForward("admin");
else
return mapping.findForward("user");
}
-------------------------------
struts-config.xml

<action path="/actions/login/userLoggedIn"
type="com.abc.xyz.common.InitCreateAction"
name="initcreateForm" scope="session">
<forward name="admin" path="/actions/showSearchPage.do" />
<forward name="user" path="/actions/showSearchPage.do" />
</action>

<action path="/actions/showSearchPage"
type="com.abc.xyz.search.actions.InitSearchAction"
scope="session" validate="true" input="/forms/login/login.jsp">
</action>

-----------------------

Hope things are clearer now.
Regards,
Roshani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do preload all the data in Struts
 
Similar Threads
how to set classpath for javawebserver & weblogic
Data base connection
how to set classpath for javawebserver & weblogic
how to access remote database(data from all tables)
how can show the data in database to jtable??