views:

1148

answers:

5

Why doesn't the code below work? The idea is that the page checks to see if the dropdown variable has changes since you last refreshed the page.

 <logic:equal name="Result" value = "-1">
   <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate"
         type="java.lang.String" toScope = "session" />
 </logic:equal> 


 <logic:equal name="Result" value = "-1">
   <bean:define id="DropDownValue" name="smlMoverDetailForm" property="moverChangeType" 
type="java.lang.String" toScope = "session" />              
</logic:equal>

<-- when you fisrt access this page from the above are run -->

 <bean:define id="NewDropDownValue" name="smlMoverDetailForm"
  property="moverChangeType" type="java.lang.String" toScope = "sess

<-- this happens everytime the page is refreshed-->

   <logic:equal name= DropDownValue   value = NewDropDownValue>
    <bean:define id="JOININGDATE" name="smlMoverDetailForm"
  property="empFDJoiningDate" type="java.lang.String" toScope = "session" />
   </logic:equal> 

    <logic:notEqual name="DropDownValue"   value = "NewDropDownValue">
    <bean:define id="DropDownValue" name="smlMoverDetailForm" 
    property="moverChangeType" type="java.lang.String" toScope = "session"
     />              
    </logic:notEqual>
A: 
<logic:equal name= DropDownValue   value = NewDropDownValue>

I'm not sure if this is your problem (describe how it doesn't work please), but the above is not valid xml: it needs quotes around the attribute values.

Sietse
thats about right , what should i be usinf?
I've tried adding the quotes back in but it still doesn't work. i get a jsp conpile error :moverDetailC.jsp(192,39) equal symbol expected' line 192 is <logic:equal name= "DropDownValue" value = "NewDropDownValue">any helod is much appreciated
A: 

The problem is as your describe i can't get the logic tags to evaluate the values held in the defined beans.

+1  A: 

You have realized, that your bean:define - at least in your question stated here - is flawed?

toScope="sess

is most likely not what you want - it doesn't even terminate the tag. But this may be formatting in StackOverflow... Also, the missing quotes have been mentioned in other answers.

The error may be the use of the value property: According to http://struts.apache.org/1.2.x/userGuide/struts-logic.html#equal value is The constant value to which the variable, specified by other attribute(s) of this tag, will be compared.

Thus, given that you've defined a bean named NewDropDownValue you might want to evaluate

<logic:equal name="DropDownValue" value="<%=NewDropDownValue/>">

Edit: Additionally I can't remember what happens when you only conditionally define a bean - your bean is defined inside a logic:equal block that might or might not be evaluated. It might be legal and have defined results, I just can't remember...

Olaf
A: 

Actually, I don't really get what you want, but here's some pseudocode (removing those dangerous pointy brackets) of your code in the question

if result == -1
   define JOININGDATE
end
if result == -1
   define DropDownValue
end

This might be an error (you might want to check once for 'equals' and once for 'does not equal') or be written shorter and more clear

if result == -1
   define JOININGDATE
   define DropDownValue
end
// otherwise don't define both values

Your question might get better answers (or be answered by you yourself) if you placed some output inside of those logic tags and post both the output and a bit more of the context (e.g. actual parameter values -- what is 'Result'). But then - you've posted from an unregistered account and have not been seen for some time...

Olaf
A: 

Try this:

<logic:equal name="Result" value = "-1">
   <bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate"
         type="java.lang.String" toScope = "session" />
 </logic:equal> 


<logic:equal name="Result" value = "-1">
   <bean:define id="DropDownValue" name="smlMoverDetailForm" property="moverChangeType" 
        type="java.lang.String" toScope = "session" />              
</logic:equal>

<!-- when you fisrt access this page from the above are run -->

<bean:define id="NewDropDownValue" name="smlMoverDetailForm"
    property="moverChangeType" type="java.lang.String" toScope = "session"/>

<!-- this happens everytime the page is refreshed-->

<logic:equal name="DropDownValue" value="<%=request.getSession().getAttribute("NewDropDownValue").toString()%>">
    <bean:define id="JOININGDATE" name="smlMoverDetailForm"
        property="empFDJoiningDate" type="java.lang.String" toScope ="session" />
</logic:equal>

<logic:notEqual name="DropDownValue" value="NewDropDownValue">
    <bean:define id="DropDownValue" name="smlMoverDetailForm" 
        property="moverChangeType" type="java.lang.String" toScope = "session"/>              
</logic:notEqual>

Errors corrected:

  • Comments were not well formed
  • Third was not correctly ended
  • Change the way to get NewDropDownValue

I think those changements will make it runs correctly.

Fred