aspose file tools*
The moose likes Struts and the fly likes Struts Indexed Properties (again) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Indexed Properties (again)" Watch "Struts Indexed Properties (again)" New topic
Author

Struts Indexed Properties (again)

A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Firstly sorry that I am plaguing this forum with more questions about this. For some reason I just can't follow this concept/get it to work.
I am trying to use
http://wiki.apache.org/struts/StrutsCatalogLazyList

And so far I had:

And as such have :
In the ProdSelectionFrom:


In the JSP:


And can't even get this to display properly.
I am getting the error message:

No getter method for property: "skills" of bean: "ProdSelectionForm"
javax.servlet.ServletException: javax.servlet.jsp.JspException: No getter method for property: "skills" of bean: "ProdSelectionForm"

Can someone point out the obvious flaws that I must be missing.

thanks in advance for your time.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Overloaded methods in an ActionForm are not supported by some versions of Struts. I'd recommend that you name your indexed getter and setter "getSkill" and "setSkill" and keep the name of the non-indexed getter "getSkills".

Then change your JSP code to:



Merrill
Consultant, Sima Solutions
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
When going on this I have each product being put retrieved from get/setSkill, and I want to pull out some of the attributes of a product, such as price, description and numProducts. From what I have read the 2 manners in which to do this are either
using dot notation such as Product.getPrice and the other option was to use the nested attribute.
Is that correct ?
And is there one that is preferred over the other ? Personally I am leaning to the nested simply for cleaner code, but would like the opinion of some more experienced people.
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
I ended up changing the display so that it does the following:


<logic:notEmpty name="ProdSelectionForm" property="results" scope="request">
<logic:iterate name="ProdSelectionForm" property="results" id="ResultsPage">
<tr>
<td><html:text name="ResultsPage" property="description" indexed="true"/>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>

And this works fine. I am still running into the same problem however. I can't get anything back when I submit the form. I am going to try changing this to a session scope as you suggested in the past and see if I can make some progress. If there are thoughts/suggestions as to why this is occuring I would be more than happy to hear them.

thanks again in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I personally don't like the nested tags. To me it makes more sense to use the regular tags and the dot notation. That way you know where each property is coming from and don't have to look through the levels of nesting in order to find it.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Unless you have a getResultsPage method in your Action form, the above code isn't going to work. The "id" attribute of the logic:iterate tag must match the name of the indexed getter.
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
I have a getResultsPage method, and also tried to change it to session. It sort of works. Now at least when I submit the page it comes back with values. The main problem being that they are the ones that I started with (meaning that the editing is not sticking.)
I think that this is a bit confusing though so I am planning on changing it to results and result for my id - sound reasonable ?
[ November 21, 2006: Message edited by: A knibbs ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
from http://struts.apache.org/1.x/struts-taglib/indexedprops.html

In Group 1 (which includes html:text), all of these tags will generate an HTML "name" attribute of "name[nn].property".

This means that your jsp code will result in your page submitting a value to ResultsPage[x].description. This is where Merrill's suggestion fits in. The id attribute of your iterate tag must match the name of your indexed get method. If you have a method "getSkill(int index)" you need to use an id attribute of "skill". This will result in a name value of "skill[x].skillId", which in turn get translated into form.getSkill(x).setSkillId(value);

I also just posted a working indexed properties example that might help.
http://www.coderanch.com/t/55172/Struts/Indexed-Properties-Example

- Brent
[ November 21, 2006: Message edited by: Brent Sterling ]
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Thank you so much for posting a working example. I am going to be pouring over it for the next little while, and hopefully this will clarify everything for me.

You and merrill helped me understand how to iterate over the values without the working example. As of right now my problem is that when I submit my form there is nothing there when I go to pull it out. Going to have a look at your sample and see where my flaw is.

The first thoughts are this :
1) I had no idea that I had to put indexed in the action.
2) I was trying to use the same action for both submitting as well as
prepopulating, maybe that is the cause of my latest problem.
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Thank you so much for posting a working example. I am going to be pouring over it for the next little while, and hopefully this will clarify everything for me.

You and merrill helped me understand how to iterate over the values without the working example. As of right now my problem is that when I submit my form there is nothing there when I go to pull it out. Going to have a look at your sample and see where my flaw is.

The first thoughts are this :
1) I had no idea that I had to put indexed in the action.
2) I was trying to use the same action for both submitting as well as
prepopulating, maybe that is the cause of my latest problem.
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Question time.
I am certain that this is going to sound incredibly stupid, but what does the following line do :
<html:hidden name="orderItem" property="productId" indexed="true" />

Your example works perfectly with the line in, but without it it does not work. This may very well be the key thing that I have been missing causing me all my grief and pain.

I am also assuming that using indexed properties with a checkbox will be similar except that you will need to use the reset to set them back to their default. Again please correct me if my understanding is incorrect.


Thanks so much for all the help you have provided to this point.
[ November 22, 2006: Message edited by: A knibbs ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I added some info to the other post:

About the hidden indexed field for productId...In my example I am using request scope. Each "item" has three properties: productId, productName and quantity. The only one that is editable on web page is quantity. With just the indexed text field on the form, the only data that gets submitted back is the quantity. The result is that that code would have a Collection of OrderItem objects with just the quantity property filled. With the hidden tag for the productId attribute, the productId property will also be populated so I know which "line item" to tie the quantity value to.

Is that the "key thing" you have been missing? I am not sure. There is no real magic going on. I could very well have added productId to the page as an editable field using an html:text tag and it would have worked just the same (as long as the use did not edit the value in the productId text box).

- Brent
 
wood burning stoves
 
subject: Struts Indexed Properties (again)