tags:

views:

300

answers:

1

hi all,

i want to use "if condition and while loop" in struts1 framework. i have Bean class with setter() and getter() methods for fname and lname property. how to use that bean variable in jsp for checking if condition. how to check if condition..if i want to check like if(firstname==lastname){some actoin...} pls reply ASAP

A: 

To perform tests and loops you can use the Struts logic tags. What you are looking for are the <logic:equal> and <logic:iterate> tags. These work easily if you want to test or loop over properties of action form beans, thanks to their property attribute.

You could also use the <c:if> and <c:forEach> tags of JSTL for operations like these (these are generic tags that don’t depend on Struts).

dpb
is there any struts1 tag to move the execution control from one place to another with in same jsp page.for eg. i have used logic:iterate in my applicatoin to loop the table like below. <logic:iterate name=""><table><tr><th>dynamic data </th></table><table><tr><td>dynamic data</td></tr></table></logic:iterate>in the above code if i want to get out after the first table iterate done without entering 2nd table..how to do??
Manu
So that I understand, you want something similar to a break instruction inside the iterator tag? You can’t do that with Struts/JSTL tags, you can only chose to show (or not) the content of the tag based on some condition. That will be something like <logic:iterate><logic:equal property=”..” value=”..”>Table 1 here</logic:equal><logic:notEqual property=”..” value=”..”>Table 2 here</logic:notEqual></logic:iterate>. You can't create complex logic with tags. That's the whole idea with tags, to move the complex logic up in Java code. This avoids you to use messy scriptlets in your JSP files.
dpb
thank dude.. i ll up and get back to you
Manu
hi want to access from bean object in jsp page .how to get that.pls help asap.1)i have formbean class with customername,date,amount,rate etc with setter() and getter() for the field menmbers.2) i have dataaccess class where i can get data for the bean calss property from database and set data to formbean class object like loan.setCloseDt11(rs.getString("CloseDt")); loan.setAmount11(rs.getString("Amount")); loan.setRate11(rs.getString("Rate")); return loan; and returning this object.my question is how to access this object in jsp page.
Manu
hi this my code..class formbean{ string amount;String rate; public void setAmount(String amount){this.amount=amouny}; String getAmount(){return amount;}}class dao{ public Formbean fetchcust() { loan.setCloseDt11(rs.getString("CloseDt")); loan.setAmount11(rs.getString("Amount")); loan.setRate11(rs.getString("Rate")); return loan; } }
Manu
I posted an answer in your other question here: http://stackoverflow.com/questions/2264388/how-to-access-formbean-class-obj-in-jsp-page
dpb
my formbean exteds Action Form.. my dao class returns the "object" of formbean class.in that dao class i set values to the setter() method of formbean class. like loan.setAmount(rs.getString(0)); return obj; in that case how to access that object in jsp page(the accessing jsp page is "popup window" if i click the button in baseform )
Manu