aspose file tools*
The moose likes Struts and the fly likes bean:write property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write property" Watch "bean:write property" New topic
Author

bean:write property

Rafa Barcel� Bauz�
Greenhorn

Joined: Aug 09, 2006
Posts: 22
Hello.

I'm working in an application based on Struts 1.1 framework, and i'm getting an error when using bean:write tag on a getter method of a model bean who operates over a map like this.

public class MyModelClass extends Serializable {
...
...
private Map data;
...
...
public String getData() {
return data.get(DefaultValue);
}
public String getData(String s) {
return data.get(s)
}
...
...
}

after this, in the Action layer i do this

public class MyAction extends Action {
...
MyModelClass myModelClass = .....
request.setAttribute("mymodelclass", myModelClass)
...
}
then in the jsp file i try this and doesn't work...

bean:write name="mymodelclass" property="data(en)"

Someone know's how to instantiate the getData(String s) in a correct way???

Thanks!!!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The syntax of your bean:write tag is correct, but you must create a mapped getter in your model class to go along with it. For more information on mapped properties, see the heading Mapped Properties in this link.


Merrill
Consultant, Sima Solutions
Rafa Barcel� Bauz�
Greenhorn

Joined: Aug 09, 2006
Posts: 22
Well, but supose that my Map data, contains a simply bean like this.

public class SimpleBean implements Serializable {
private String name;
private String address;

public String getName() { return name }
public void setName(String name) { this.name = name }
}

now "MyModelClass" should look like this...

public class MyModelClass extends Serializable {
...
...
private Map data;
...
...
public SimpleBean getData() {
return (SimpleBean) data.get(DefaultValue);
}

public SimpleBean getData(String s) {
return (SimpleBean) data.get(s)
}
...
...
}

so my bean write tag should look like this

<bean:write name="mymodelclass" property="data(en).name" />

but it doesn't works!!!

any explanation on what i'm wrong???

Thanks!!
Rafa Barcel� Bauz�
Greenhorn

Joined: Aug 09, 2006
Posts: 22
It's possible that i should need to incorporte in my /lib the commons-beanUtils.jar for a bean:write with a Map???

if I need this jar, which version is better for my struts 1.1 version??
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Yes, you definitely do need commons-beanutils.jar in your WEB-INF/lib folder. The version you want is the one that comes with the Struts 1.1 download.

Another thing you might try is naming your mapped method something other than getData (getMappedData for exampe). In version 1.1 I seem to recall there being problems with overloaded methods in ActionForm beans.

The example you've written should work as long as you have the correct libraries. Just to prove it, below is a brief example that I tested and verified that it works. I tested this with Struts 1.3.8, but it should still work in Struts 1.1.

The Model class:

The Action Class:

The JSP:

The result I get is:
The value is: value
[ September 12, 2007: Message edited by: Merrill Higginson ]
Rafa Barcel� Bauz�
Greenhorn

Joined: Aug 09, 2006
Posts: 22
Thanks!!! the problem seems that in Struts 1.1 there's a problem when I overload a getter method. I have updated de beanutils jar and changed method signature and now works fine!!! .

But....., now I have another problem. How can I invocate the getter method with the struts locate language as a parameter...???

I like something like this:

<bean:write name="myModelClass" property="data(lang).value" scope="request" />

where lang is the locale.getLanguage()

I tried this:
<% String lang = ((Locale) session.getAttribute("org.apache.struts.action.LOCALE")).getLanguage(); %>

<bean:write name="myModelClass" property="data(<%=lang%> .value" scope="request" />

but the answer is:

Null property value for 'data(<%=lang%> ''


any help??

Thanks!!!
techy babu
Greenhorn

Joined: Dec 10, 2008
Posts: 1
Hey Did you fix this issue with the locale?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write property