>
> > The "struts-logic" library includes quite a few
> > variations of an "if" tag that
> > can perform different sorts of conditional checks
> > for you.  At the moment,
> > however, there is nothing that provides the "else"
> > or "elseif" construct.  This
> > is mostly because I've yet to see a syntax for this
> > that is:
> > * consistent with the XML syntax required by JSP
> > custom tags
> > * easily understood by page authors
> > * not butt-ugly to look at or to type
> >
> > I'm open to suggestions for a solution to these
> > issues.
> >
> > > Mike Campbell        email: [EMAIL PROTECTED]
> >
> > Craig

I'm not too familiar with custom tag writing, so I don't know how
technically feasible this is, but... how about a "cond" tag (similar to
lisp's cond), whose body can contain multiple "test" tags.  The first
test which evaluates to true is allowed to render its body, and then
further processing is inhibited.  This would have the effect of "if,
else if, else if ...".

<logic:cond>
  <logic:equal name="name" property="property" value="A">The value is
A</logic:equal>
  <logic:equal name="name" property="property" value="B">The value is
B</logic:equal>
  <logic:equal name="name" property="property" value="C">The value is
C</logic:equal>
  <logic:true>An unexpected value?</logic:true>
</logic:cond>

... which should be equivalent to ...

if (name.getProperty().equals("A")) {
  out.write("The value is A");
}
else if (name.getProperty().equals("B")) {
  out.write("The value is B");
}
else if (name.getProperty().equals("C")) {
  out.write("The value is C");
}
else if (true) {
  out.write("An unexpected value?");
}


Jim N.

Reply via email to