aspose file tools*
The moose likes Struts and the fly likes bean:write name=.... before 'property=' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write name=.... before Watch "bean:write name=.... before New topic
Author

bean:write name=.... before 'property='

Fernando Alvarez Junco
Greenhorn

Joined: Aug 09, 2006
Posts: 3
Hi! I'm not sure if i can write this:

<logic:match name="columnasResultadosGrafico" property="<bean:write name='cabecera'/>" value="on">

I have read some forums that uses this in their source, but when I use it, the following exception is thrown:

No getter method for property: "<bean:write name='cabecera'/>" of bean: "columnasResultadosGrafico"

So struts is not giving the value that i'm triying to write and crashes...
Can anybody tell why this happends?
Thank you very much!
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
You are embedding tags, which will not work.

If you have a bean called 'columnasResultadosGrafico' that has a method called 'getCabecera()' that returns the string you would like to search in, and you are searching for the substring 'on', it would look like this:

I've never used the logic:match tag so I may be wrong, but I got my information from http://struts.apache.org/1.2.7/userGuide/struts-logic.html#match.
Fernando Alvarez Junco
Greenhorn

Joined: Aug 09, 2006
Posts: 3
i haven't explained very good what i'm trying to do. May be this is better

<logic:iterate name="columnNames" id="header" property="names">
<logic:match name="columnStatus" property="<bean:write name='header'/>" value="on">
<th>
<bean:write name="header"/>
</th>
</logic:match>

i'm iterating over the String[] names, and i want to know if the name returned on each iteration is set to 'on' in the bean columnStatus. In this bean is implemented a getter method for each value that returns the iteration.

Thank you very much for your answer, Dom, but that's not what i was asking... i hope this post is more descriptive.
Waiting for answers
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
I'm still confused on what you are trying to accomplish.

You have a bean columnNames that has a getNames which returns a String[].

You are iterating over that String[] (names).

I am confused on where you are trying to find the String 'on', and how it is related to the columnStatus bean.

Maybe if you post the code from your action class I can make more sense out of it.
[ August 09, 2006: Message edited by: Dom Lassy ]
Fernando Alvarez Junco
Greenhorn

Joined: Aug 09, 2006
Posts: 3
this is a 'control bean', only values 'on' or 'off' for each property.

In session this bean is called 'columnStatus'

public class BeanLogmnrContent {
private String scn;
private String timestamp;
private String threadNumber;

public String getters ...
public void setters ...
}



the string[] names, has the column names returned by the query. Column names has the same names as
properties of bean BeanLogmnrContent

public class ColumnNames {
private String [] names;

public String[] getNames() {
return names;
}

public void setNames(String[] names) {
this.nombres = names;
}

}


i want to implement a loop that read all strings stored in names[] and 'ask' to the control bean if
that column name is 'on' or 'off'.



example
supose names={scn,timestamp,threadNumber} and iterating over this array

in first iteration i want to call columnStatus.getSCN()... if 'on' then write 'scn'
second iteration call to columStatus.getTimestamp() if 'on' then write 'timestamp'
third iteration call to columStatus.getThreadNumber() if 'on' then write 'threadNumber'
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
If I understand what you're attempting, it would look something like this if you wrote it as Java:

Obviously, this won't compile.

One option would be to have columnNames.getNames() return a list of 'HeaderBeans' which would be a class that contains a header value and a display value, so your code, in Java, would look something like this:

or in Struts Tags:

[ August 09, 2006: Message edited by: Ray Stojonic ]
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
What you want to do is reflection. I don't believe you can do reflection using jstl or the struts taglib.

The way you're doing things doesn't really make sense. It seems like it might violate MVC as well, but I don't know all of the details.

Anyway, ideally, all of the information you want should be placed in a simple bean in your action class. For example, you can have a bean with a list property. That list can contain objects that contain a display value and a name - simple objects with setters and getters only, no logic. This bean should be populated in your action class and should not 'bind' to other beans or objects. It should simply be a container for everything, and all of the heavy lifting should be in your action class and populating the bean there. Then, your jsp will be a piece of cake to write and you won't worry about violating the MVC paradigm.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write name=.... before 'property='