dev@jsftemplating.java.net

Re: JSFTemplating: if command event

From: Anissa Lam <Anissa.Lam_at_Sun.COM>
Date: Mon, 04 Dec 2006 12:41:53 -0800

Senthil Chidambaram wrote:
> Can we have
> if(check for something) call a handler in command event. What I'm
> trying to ask is, can we have if statement in command event.
>
> thx
> Senthil
Is this what you are looking for ? We have lots of code that depends on
the if() handler. I have also attached the email that Ken sent out when
he put this support in.
The code below is in appserv/callflowDetail.jsf

           <sun:button id="closeButton" immediate="#{true}" text="$resource{i18n.button.Close}" >
                    <!command
                        if ($pageSession{isWebService}=#{true}) {
                            redirect(page="../webService/webServiceMessages.jsf?instance=#{instanceName}&webServiceKey=$pageSession{wsKeyEncoded}");
                        }
                        if(!$session{supportCluster}){
                            redirect(page="../appServer/callFlowConfig.jsf?instanceName=#{instanceName}");
                        }
                        if($session{supportCluster}){
                            redirect(page="../standalone/eeCallFlowConfig.jsf?instanceName=#{instanceName}");
                        }
                    />
                </sun:button>


attached mail follows:



User: kenpaulsen
Date: 2006/10/17 17:47:23

Modified:
   jsftemplating/src/java/com/sun/jsftemplating/layout/template/TemplateReader.java
   jsftemplating/src/java/com/sun/jsftemplating/handlers/UtilHandlers.java

Log:
 * Added the ability to omit the quotes around an "if" handler condition.
 
   In other words, you may do:
 
   if (#{foo} | #{bar}) {
       myHandler1(...);
       myHandler2(...);
   }
 
 Please let me know if you experience any problems with this, I believe it
 is feature complete. I don't know of any outstanding bugs.

File Changes:

Directory: /jsftemplating/src/java/com/sun/jsftemplating/layout/template/
=========================================================================

File [changed]: TemplateReader.java
Url: https://jsftemplating.dev.java.net/source/browse/jsftemplating/src/java/com/sun/jsftemplating/layout/template/TemplateReader.java?r1=1.21&r2=1.22
Delta lines: +19 -3
--------------------
--- TemplateReader.java 18 Oct 2006 00:04:58 -0000 1.21
+++ TemplateReader.java 18 Oct 2006 00:47:21 -0000 1.22
@@ -866,9 +866,21 @@
                     + "' was missing the '(' character!");
             }
 
- // Read NVP(s)...
+ // Move to the first char inside the parenthesis
             parser.skipCommentsAndWhiteSpace(parser.SIMPLE_WHITE_SPACE);
             ch = parser.nextChar();
+
+ // Allow if() handlers to be more flexible...
+ if (handlerId.equals(IF_HANDLER)
+ && (ch != '\'') && (ch != '"') && (ch != 'c')) {
+ // We have an if() w/o a condition="" && w/o quotes...
+ // Take the entire value inside the ()'s to be the expression
+ parser.unread(ch);
+ handler.setCondition(parser.readUntil(')', false).trim());
+ ch = ')';
+ }
+
+ // Read NVP(s)...
             while ((ch != -1) && (ch != ')')) {
                 // Read NVP
                 parser.unread(ch);
@@ -876,7 +888,7 @@
                     nvp = parser.getNVP(defVal);
                 } catch (SyntaxException ex) {
                     throw new SyntaxException("Unable to process handler '"
- + def.getId() + "'!", ex);
+ + handlerId + "'!", ex);
                 }
                 parser.skipCommentsAndWhiteSpace(
                     parser.SIMPLE_WHITE_SPACE + ",;");
@@ -893,7 +905,8 @@
                     // First check for special input value (condition)
                     String name = nvp.getName();
                     if (name.equals(CONDITION_ATTRIBUTE)
- && (inputs.get(CONDITION_ATTRIBUTE) == null)) {
+ && ((inputs.get(CONDITION_ATTRIBUTE) == null)
+ || (handlerId.equals(IF_HANDLER)))) {
                         // We have a Handler condition, set it
                         handler.setCondition(nvp.getValue().toString());
                     } else {
@@ -1082,8 +1095,11 @@
     public static final String CONDITION_ATTRIBUTE =
         "condition";
 
+ public static final String IF_HANDLER = "if";
+
     public static final char LEFT_CURLY = '{';
     public static final char RIGHT_CURLY = '}';
+
 
     public static final ProcessingContext LAYOUT_DEFINITION_CONTEXT =
         new LayoutDefinitionContext();

Directory: /jsftemplating/src/java/com/sun/jsftemplating/handlers/
==================================================================

File [changed]: UtilHandlers.java
Url: https://jsftemplating.dev.java.net/source/browse/jsftemplating/src/java/com/sun/jsftemplating/handlers/UtilHandlers.java?r1=1.12&r2=1.13
Delta lines: +1 -1
-------------------
--- UtilHandlers.java 18 Oct 2006 00:21:01 -0000 1.12
+++ UtilHandlers.java 18 Oct 2006 00:47:21 -0000 1.13
@@ -61,7 +61,7 @@
     }
 
     @Handler(id="if",
- input={_at_HandlerInput(name="condition", type=String.class, required=true)})
+ input={_at_HandlerInput(name="condition", type=String.class)})
     public static void ifHandler(HandlerContext context) {
         // Do nothing, the purpose of this handler is to provide condition
         // support which is handled by the parser / runtime.




---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe_at_jsftemplating.dev.java.net
For additional commands, e-mail: cvs-help_at_jsftemplating.dev.java.net