dev@jsftemplating.java.net

Re: JSFTemplating: RE: Example for reading handlers...

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Wed, 18 Apr 2007 08:32:37 -0700

Do you want to do more in the case of an exception in your catch block?
Other than that, it looks good to me!

Thanks!

Ken

Jason Lee wrote:
> How does this look?
>
> } else if ("ui:event".equals(nodeName)) {
> // per Ken, we need to append "/>" to allow the handler
> parser code
> // to end correctly
> String body = node.getNodeValue() +"/>";
> String eventName =
> ((Node)node.getAttributes().getNamedItem("type")).getNodeValue();
> InputStream is = new ByteArrayInputStream(body.getBytes());
> EventParserCommand command = new EventParserCommand();
> try {
> TemplateParser parser = new TemplateParser(is);
> parser.open(); // Needed to initialize things.
> // Setup the reader...
> TemplateReader reader = new TemplateReader("foo",
> parser); // TODO: get a real ID
> reader.pushTag("event"); // The tag will be popped at
> the end
> // Read the handlers...
> command.process(new BaseProcessingContext(),
> new ProcessingContextEnvironment(reader,
> parent, true), eventName);
> // Clean up
> parser.close();
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> } finally {
> if (is != null) {
> try {
> is.close();
> } catch (Exception e) {
> // ignore
> }
> }
> }
> }
>
> -----
> Jason Lee, SCJP
> Senior Software Engineer
> http://www.iec-okc.com
>
>
>
>> -----Original Message-----
>> From: Ken.Paulsen_at_Sun.COM [mailto:Ken.Paulsen_at_Sun.COM]
>> Sent: Tuesday, April 17, 2007 6:54 PM
>> To: Jason Lee; jsftemplating
>> Subject: Example for reading handlers...
>>
>>
>> Per our IRC discussion, we'll provide the following format
>> for the Faclets syntax for handlers:
>>
>> <ui:event type="[eventType]">
>> handler1(input1="value" input2='value', output1=>$attribute{foo});
>> handler2(...);
>> if (#{something}) {
>> handler3(...);
>> }
>> </ui:event>
>>
>>
>> If you have 2nd thoughts other ideas let me know. We can
>> refine the body content above if you have ideas (like qoob's
>> ideas re: I/O params, etc.).
>>
>> Your Faclets XML parser will need to handle the XML part and
>> pass in the body content to the EventParserCommand. I wrote
>> a test case showing how this is done. Look at:
>>
>>
>> /test/java/com/sun/jsftemplating/layout/template/EventParserCo
>> mmandTest.java
>>
>> You may cache a reference to the EventParserCommand class
>> (perhaps it should have been a singleton?). The "elt" in the
>> test class is the LayoutComponent that contains the
>> <ui:event> tag. You will need to call
>> parser.open() and reader.pushTag("event"). You will also
>> need to append "/>" to the end of your handlers (body
>> content) in order to allow the code to correctly stop when it
>> is supposed to.
>>
>> After you do that, handlers should be 100% functional for the
>> Facelets syntax! Let me know if you have questions or problems.
>>
>> Thanks!
>>
>> Ken
>>
>>