Thanks for the good explanation! Now it works. -----Ursprüngliche Nachricht----- Von: Dirk Forchel [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 11. Dezember 2008 10:49 An: user@struts.apache.org Betreff: Re: How to use s:if
First of all I recommend reading a tutorial about Struts2 and OGNL. but to answer your questions, you have to add a form property to your POJO action class (don't miss the getter and setter methods) first: public class ShowAction extends ActionSupport { public boolean all = false; public void setAll(boolean all) { this.all = all; } public boolean getAll() { return all; } when the show action is instantiated the param all=true sets your form property to the boolean true. In your JSP you can simple test with <s:if test="%{all}"> ... </s:if>, cos the attribute "test" for this tag requires a Boolean type (in other words an Boolean expression is required which is evaluated and tests for true or false). %{ } is an escape sequence for OGNL. There are tags e.g. s:property where you don't have to write this sequence for the value attribute. With # you have access to named objects in the ActionContext or to objects in different maps (parameters, request, session, application, attr). <s:set name="test" value="'Tom'"/> Hello <s:property value="#test"/>. in this example the set tag sets the value 'test' to the String 'Tom' in the ActionContext. Since we don't specify a scope, this new 'test' reference exists in the default 'action' scope. Justive wrote: > > Hi, > > I don' t know who to use the s:if tag > > I want to call a action with a parameter: > > i.e. > > http:/appsever:8080/myapp/showaction?all=true > > in my jsp I want to use the s:if to display different strings > > i.e. > > <s:if test="%{all == 'true'}" > > <tr> > <td>all is set </td> > </tr> > </s:if> > <s:else> > <tr> > <td>all is not set</td> > </tr> > </s:else> > > But how to write the test condition? > > By the way. What does the % in a condition like %{test} > And what is # in a condition like %{#test}? > > -- View this message in context: http://www.nabble.com/How-to-use-s%3Aif-tp20952072p20952430.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]