Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do preload all the data in Struts

 
Chua Keng Guan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chua Keng Guan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic