Hi per and Michael, I had to end the logic tag to make theese sort of things work: <xsp:page> <page> <xsp:logic> if (!request.isUserInRole("root")) { </xsp:logic> <!-- Note this -->
<xsp:attribute name="security-error">Not authorized</xsp:attribute> <xsp:logic> } </xsp:logic> </page> </xsp:page> As I figured it´s like <% in asp. You´re in different "modes" when in logic element and outside. Attached is a real-life example (with for loops, not if statements, but the behaviour is probably the same) that is used from a flowscript to generate a "datePicker" calendar. Regards, Per-Olof Noren < >> >> <page> >> <xsp:logic> >> if (!request.isUserInRole("root")) >> { >> <xsp:attribute name="security-error">Not authorized</xsp:attribute> >> } >> else >> { >> <xsp:content> >> >> <!-- Build the page if authorized --> >> <content /> >> >> </xsp:content> >> } >> </xsp:logic> >> </page> >> >> </xsp:page> Per Kreipke wrote: > Michael, > > Thanks for the tip. However, your tip makes the problem even more > interesting. > > When the 'if' statement is true, the <xsp:attribute> does appear on the > toplevel element and the XML is valid (no more array bounds exception). > > But when the 'if' statement is false, the <page> element isn't the top most, > it's emitted after the <content> element. E.g. <page> is a sibling of the > <content> element and the XML has _two_ top level elements, also invalid. > > Per > > >>-----Original Message----- >>From: Enke, Michael [mailto:[EMAIL PROTECTED]] >>Sent: Tuesday, September 10, 2002 2:58 AM >>To: [EMAIL PROTECTED] >>Subject: Re: XSP bug: can get generate() to skip elements using java >>'if's >> >> >>Per Kreipke wrote: >> >>>The following XSP snippet will cause an >> >>ArrayIndexOutOfBoundsException in >> >>>Cocoon 2.0.3 because the start of the outer element is never >> >>emitted to the >> >>>SAX stream. >>> >>>XSP Snippet: >> >> >>I would always write it as: >> >> <xsp:page ....> >> >> <page> >> <xsp:logic> >> if (!request.isUserInRole("root")) >> { >> <xsp:attribute name="security-error">Not authorized</xsp:attribute> >> } >> else >> { >> <xsp:content> >> >> <!-- Build the page if authorized --> >> <content /> >> >> </xsp:content> >> } >> </xsp:logic> >> </page> >> >> </xsp:page> >> >>note: </xsp:logic> replaced by <xsp:content> >>and <xsp:logic> replaced by </xsp:content> >> >>Michael >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, email: [EMAIL PROTECTED] >> >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED]
<?xml version="1.0" encoding="ISO-8859-1"?> <xsp:page xmlns:dw="http://curalia.se/DW/1.0" xmlns:request="http://apache.org/xsp/request/2.0" xmlns:session="http://apache.org/xsp/session/2.0" xmlns:xscript="http://apache.org/xsp/xscript/1.0" xmlns:xsp="http://apache.org/xsp" language="java" create-session="yes" xmlns:jpath="http://apache.org/xsp/jpath/1.0"> <xsp:structure> <xsp:include>java.text.DateFormat</xsp:include> <xsp:include>java.text.ParseException</xsp:include> <xsp:include>java.text.SimpleDateFormat</xsp:include> <xsp:include>java.util.Calendar</xsp:include> <xsp:include>java.util.Date</xsp:include> <xsp:include>java.util.GregorianCalendar</xsp:include> <xsp:include>java.util.Locale</xsp:include> </xsp:structure> <dw:page> <dw:row> <dw:col> <dw:frame width="220"> <dw:continuation><jpath:continuation/></dw:continuation> <dw:caption>Välj datum</dw:caption> <dw:row> <dw:col> <dw:calendar> <xsp:logic> Date highlightDate = new Date(); CompiledExpression highlight = jxpathContext.compile("highlight"); Object value = highlight.getValue(jxpathContext); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { highlightDate = format.parse((String) value); } catch (Exception e) { System.out.println("Exception during parse"); e.printStackTrace(); highlightDate = new Date(); } Calendar calendar = new GregorianCalendar(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setMinimalDaysInFirstWeek(1); calendar.setTime(highlightDate); calendar.add(Calendar.MONTH, -1); Date prev = calendar.getTime(); calendar.setTime(highlightDate); calendar.add(Calendar.MONTH, 1); Date next = calendar.getTime(); calendar.setTime(highlightDate); </xsp:logic> <xsp:element name="month" prefix="dw" uri="http://curalia.se/DW/1.0"> <xsp:attribute name="name"><xsp:expr>new SimpleDateFormat("MMMMMMMMMMMM").format(highlightDate)</xsp:expr></xsp:attribute> <xsp:attribute name="year"><xsp:expr>calendar.get(Calendar.YEAR)</xsp:expr></xsp:attribute> <xsp:attribute name="prev"><xsp:expr>format.format(prev)</xsp:expr></xsp:attribute> <xsp:attribute name="next"><xsp:expr>format.format(next)</xsp:expr></xsp:attribute> <xsp:logic> calendar.setTime(highlightDate); Date theDate = null; int weeks = calendar.getActualMaximum(Calendar.WEEK_OF_MONTH); for (int week = 1; week <= weeks; week++) { calendar.setTime(highlightDate); calendar.set(Calendar.WEEK_OF_MONTH, week); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); </xsp:logic> <xsp:element name="week" prefix="dw" uri="http://curalia.se/DW/1.0"> <xsp:attribute name="nr"><xsp:expr>calendar.get(Calendar.WEEK_OF_YEAR)</xsp:expr></xsp:attribute> <xsp:logic> for (int j = 1; j <= 7; j++) { theDate = calendar.getTime(); String a = format.format(theDate); String b = format.format(highlightDate); </xsp:logic> <xsp:element name="day" prefix="dw" uri="http://curalia.se/DW/1.0"> <xsp:attribute name="date"><xsp:expr>format.format(theDate)</xsp:expr></xsp:attribute> <xsp:attribute name="nr"><xsp:expr>calendar.get(Calendar.DAY_OF_MONTH)</xsp:expr></xsp:attribute> <xsp:attribute name="highlight"><xsp:expr>a.equalsIgnoreCase(b)</xsp:expr></xsp:attribute> </xsp:element> <xsp:logic> calendar.add(Calendar.DAY_OF_WEEK, 1); } </xsp:logic> </xsp:element> <xsp:logic>}</xsp:logic> </xsp:element> </dw:calendar> </dw:col> </dw:row> </dw:frame> </dw:col> </dw:row> </dw:page> </xsp:page>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]