File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Tag displaying Objects nestled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Tag displaying Objects nestled" Watch "Tag displaying Objects nestled" New topic
Author

Tag displaying Objects nestled

biraji gafiff
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Hi everyone,
I have a object that have others object like objA has objB that has objC an go on. I�ve tried to use html tag but it didn�t work. Let�s suppose i want the id of objD, so i did . How could i do that?

Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The code you've shown us could work provided your ActoinForm is structured and populated properly. Please tell us what "didn't work" means. What error messages did you get? What happened that you didn't expect to happen? Is there a getter and setter for objA on your ActionForm? Is there a getter and setter for objB in objA, etc?

If your Action form is in request scope, you will need to do a little more work with your ActionForm to give it "lazy initialization" behavior. This link provides more details on how to do that.
[ September 06, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
biraji gafiff
Greenhorn

Joined: Jul 11, 2005
Posts: 27
The error is:

But it works if i change to:

I have gets and sets for all and my objA is in the session.

Sorry my english.
Thanks.
[ September 08, 2006: Message edited by: bir gt ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
objA is in the session


hmmm...the way that the html tags work is that if you do not give a name attribute, it defaults to the form of the enclosing html:form tag. Maybe you need to change your tag to use:

name="objA" property=" objB.objC.objD.id"

- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The <html:text> tag operates on the ActionForm bean. That means that any nested objects must be accessible through the ActionForm. Whether ObjA is in the session or not is completely irrelevant. So, in order for this tag to work:

Your ActionForm bean must have a getObjA() method, OjbA must have a getObjB() method, etc.
biraji gafiff
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Hello,
I�m sorry, by objA i mean my ActionForm. That ActionForm has gets and sets for objB, that has gets and sets for objC etc. I just don�t undestand why if i put <html:text property="objB.id"> works and <html:text property="objB.objC.objD.id"> don�t.

Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
What I'm telling you is that the reason this isn't working for you must be that your beans are not coded properly. Struts does allow for nested properties, and you can go as many levels deep as you want. I'd check each of your getter methods on your objects to see if there is a misspelling somewhere. I'd also check to see that ObjA really does contain a non-null reference to ObjB, and that ObjB contains a reference to ObjC, etc.

I frequently use nested properties going three or four levels deep, so I know this works.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

"bir gt",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Case is important to. I am not sure if you are posting dummy names or not, but make sure that MyForm.getObjB().getObjC().getObjD().getId() is valid.

- Brent
[ September 13, 2006: Message edited by: Brent Sterling ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tag displaying Objects nestled