• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic Table

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using plain html and struts.

In my application i need to display a row of data and need to display a link/button to create another row. How to do this kind of layout using struts. Please help me...

Thanks
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use dhtml to append another line on a new layer; the complexity is in managing all that (submit all layers) and there may be browser incompatibilties.

your best bet is to have another button/image (say 'add item') that submits the form each time to your action. assuming that you are using indexed properties to handle your items data, the action would add 1 additional empty item to the array of item objects and forward to the same display page. this guarantees that the data is retained each time a new line is added and the approach is 'fully struts'. the downside is that you're going back to the action each time.
 
Srilakshmi Vara
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alan,

I tried by writing a action which increments a counter.
I am using the counter in my jsp to repeat the rows. But i can see the variable incremented in action class but the variable is not getting changed in the jsp.

Can you explain me why this kind of problem occurs.. i have different states of Actionforms with jsps. I am confused how the struts maintains the ActionForm with the JSP are mapped through the config file.


I am posting my code will you have a look at it please.......

Incrementer Action:

public class Incrementer extends Action{
public Incrementer() { }

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest req,HttpServletResponse res)
throws Exception {
TransForm trans = (TransForm)form;
int countVS = trans.getAddVitalSign();
countVS = countVS+1;
if(countVS != 0) trans.setAddVitalSign(countVS);
return mapping.findForward("success");
}
}


jsp tag is <html:text name="transForm" property="addVitalSign"/>

Entrees in the config are

<form-bean name="transForm" type="org.fdny.cts.actionforms.TransForm"/>
<action path="/AddRow"
type="Incrementer"
name="transForm"
scope="request" validate="false">
<forward name="success" path="/DisplayTrans.do" />
</action>
<action path="/DisplayTrans"
type="DisplayTrans"
name="transForm"
scope="request" validate="false">
<forward name="success" path="/jsp/TRANS.jsp" />
</action>
 
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
because the number of items is dynamic, you must use struts indexed properties to maintain your form and track the changes. if you haven't done indexed properties before, you'll need to take some time to learn on your own following examples.

here are 2 resources on indexed properties.
http://struts.apache.org/faqs/indexedprops.html
http://www.developer.com/java/ejb/article.php/2233591
 
Srilakshmi Vara
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alan,

I tried using indexed properties. But i am getting null pointer exception..
I donno where its going wrong.
I have a jsp in which i need to display set of rows dynamically, at the end i have a hyperlink adding for row, if its clicked

i am calling Incrementer action but it is raising me a null pointer exception. I am wondering how will be the state of my action form when it goes and comes back from the action.


My incrementer action is

public class Incrementer extends Action{
public Incrementer() { }

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest req,HttpServletResponse res)
throws Exception {
TransForm trans = (TransForm)form;
VitalSignLine[] vsLines = trans.getVSLines();
if(vsLines != null){
VitalSignLine[] newvsLines = new VitalSignLine[vsLines.length+1];
for(int i=0;i<vsLines.length;i++)
newvsLines[i]=vsLines[i];
newvsLines[newvsLines.length-1]=new VitalSignLine();
trans.setVSLines(newvsLines);
}
return mapping.findForward("success");
}
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic