Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there a possible way to use index properties on this situation

 
xin xin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have been thinking of this for weeks, but still don't know if the index properties will help or not.

Here are my application requirements, and any suggestions are needed, thanks.

This project needs to display a lot of data on a jsp page, the row number is fixed what I mean fixed is it depends on the data in database so I won't be able to hardcode them. But the columns are dynamic, user could add as many columns as they want.

For example here is the structure of 5 rows by 2 columns:

client: [text input ] | [text input ]
matter: [text input ] | [text input ]
name: [text input ] | [text input ]
address: [text input ] | [text input ]
e-mail: [text input ] | [text input ]

Does anyone know how to do this using Struts, 'cause I really don't know if the ActionForm will do the job here, since how to define the fields getter or setter methods in ActionForm?

Thanks a lot!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a hard time understanding what you want to do here. Please help me get a better idea of how the page is supposed to look as the user adds more data.

Will it look like this?

client: [text input ] | [text input ]
matter: [text input ] | [text input ]
name: [text input ] | [text input ]
address: [text input ] | [text input ]
e-mail: [text input ] | [text input ]

client: [text input ] | [text input ]
matter: [text input ] | [text input ]
name: [text input ] | [text input ]
address: [text input ] | [text input ]
e-mail: [text input ] | [text input ]

client: [text input ] | [text input ]
matter: [text input ] | [text input ]
name: [text input ] | [text input ]
address: [text input ] | [text input ]
e-mail: [text input ] | [text input ]


or like this?

client: [text input ] | [text input ] [text input ] | [text input ]
matter: [text input ] | [text input ][text input ] | [text input ]
name: [text input ] | [text input ][text input ] | [text input ]
address: [text input ] | [text input ][text input ] | [text input ]
e-mail: [text input ] | [text input ]
[text input ] | [text input ]
 
xin xin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill Higginson,

Thanks for reply, it will look like the second option, user is able to add a column each time, for example, here is the 5 row by 2 column:

client: [input text][input text]
metter: [input text][input text]
name: [input text][input text]
address: [input text][input text]
e-mail: [input text][input text]

If the user add one column, it will be:

client: [input text][input text][input text]
metter: [input text][input text][input text]
name: [input text][input text][input text]
address: [input text][input text][input text]
e-mail: [input text][input text][input text]

I know this is kind of abnormal, each row has the same kind of data.

Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, indexed properties will work well in this situation. There are many ways to do this, but here's one suggestion:

Create a javaBean called Case or something like that which has properties for all the fields you listed (client, matter, etc.). In your ActionForm, create a collection of these beans called cases.

Then in your jsp, use indexed properties along with logic:iterate to produce the output. Something like this:
<tr>
<td>client:</td>
<logic:iterate id="case" name="myForm" property="cases" indexId="i">
<td><html:text property='<%="cases["+i+"].client" %>' /></td>
</logic:iterate>
</tr>
<tr>
<td>matter:</td>
<logic:iterate id="case2" name="myForm" property="cases" indexId="i2">
<td><html:text property='<%="cases["+i2+"].matter" %>' /></td>
</logic:iterate>
</tr>

repeat this process for name, address, and email.
 
xin xin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much,

I will try it this way to see if I can get it working, because I won't be able to know the properties until I query the database, so how am I able to set up all the set and get properties. Maybe I can use a list, not sure.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't know the properties in advance, use one of the implementations of the java.util.Map interface (Hashmap, Treemap,etc.). You can then get the labels from the keySet() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic