Struts Logic:equal problem compairing bean values

I have two seperate beans available to a .jsp. I am trying to set the "selected" value of a Select option tag to "true" if the value of bean 1 equals the value of bean 2.

Code as below:

<logic:present name="SActionForm" scope="request">

<bean:define id="SActionForm" name="SActionForm" scope="request"/>

</logic:present>

...

...

...

<select name="category" id="category">

<logic:iterate id="category" name="categoryList" type="uk.co.test.scr.bom.Category" scope="session">

<option value='<bean:write name="category" property="category_id"/>'><logic:equal name='category' property='category_id' value='<bean:write name="SActionForm" property="category"/>'> selected='true'</logic:equal>>

<jsp:getProperty name="category" property="category_description"/>

</option>

</logic:iterate>

</select>

-

I've checked the values match by printing out the bean values during each iteration, therfore I think it a problem specific to the logic:equal statement:

<logic:equal name='category' property='category_id' value='<bean:write name="SActionForm" property="category"/>'> selected='true'</logic:equal>

Anyone any ideas?

Thanks in advance

[1378 byte] By [StrutFoola] at [2007-10-2 9:46:39]
# 1
Haii bosssAre u getting any exception? if so just paste the stackt trace...And are u sure that 'category' is a bean ? where is it present? form or any scope?regardsShanu
mshanua at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

No exceptions, category is a bean in present in session scope.

Bit strange:

<logic:equal name='category' property='category_id' value='<bean:write name="SActionForm" property="category"/>'>

selected="true"

</logic:equal>

doesn't work, yet the following does...

<logic:equal name='category' property='category_id' value='<%=SActionForm.getCategory()%>'>

selected="true"

</logic:equal>

any ideas why? does bean:write get property values in a different manner?

Thanks

StrutFoola at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Haii

<logic:equal name='category' property='category_id' value='<bean:write name="SActionForm" property="category"/>'>

selected="true"

</logic:equal>

This will not work..cuz bean:write will write into your page..precisely..whatever u write in bean:write will come under out.println() function...

i think u got me,,,,

regards

Shanu

mshanua at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
i think we are not supposed to write a struts tag inside a struts tag. Just check it.Regards,Sra1
sra1a at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Yeah exactly..........................................
mshanua at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
So if we can't nest struts tags in this manner, what is the best way of compairing properties of two seperate beans?
StrutFoola at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

"Compares the variable specified by one of the selector attributes against the specified constant value." THis is the description of logic:equal given by struts people iteself..so they are expecting only constants to be compared with not dynamic.

if u want dynamic values to compare with the that u have written is the only way.........

regards

shanu

mshanua at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Thanks Shanu,

The problem with the way I have written it is that the getter method of said property is non-static, where from a .jsp we would be trying to reference the getter method from a static context. Causing a compilation problem.

Any way around this? other than changing the bean property to a static type?

StrutFoola at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
Ignore that last stament it wa the way I had referenced the bean in the jsp.Thanks all for your help.
StrutFoola at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

compairing bean values with that manner is not correct .

you can try this:

<bean:define id="targetvalue">

<bean:write name="name" property="property">

</bean:define>

<logic:equal name="sourcename" value="<%=targetvalue%>">

....

</logic:equal>

WillZhanga at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

That dint work for me... but i found another way; i.e., using EL.. check the code below...

<bean:define id="targetvalue" name="name" property="property"/>

<logic:equal name="sourcename" value="${targetvalue}">

....

</logic:equal>

A * R

Rajesh_Menona at 2007-7-16 23:52:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

This will solve your issue my friend

<bean:define id="targetvalue" name="name" property="property"/>

<logic:equal name="sourcename" value="${targetvalue}">

....

</logic:equal>

A * R

Rajesh_Menona at 2007-7-16 23:52:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
That works for me. But I had to put the type tag too. Something like this :<bean:define id="filialAtual" name="filial" property="fabEmp" type="java.lang.String" />After this, I could compare the values just fine.Great Post, folks!
eduardoCarneiroa at 2007-7-16 23:52:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...