Re: Expression Language in JSP and JasperException

2007-02-21 Thread Piotr Kiraga

Hi David,


Ok  forgive me now, but this is getting confusing.  Where does
result come into this picture?  Were you expecting actionBean to be an
instance of a different class?  You aren't offering a lot to go on here.


Sorry for mixup. I've just thought that it is just about some option
in Tomcat configuration or something, and I haven't knew it. Like I
see... It may be not. :(

Here goes more background.

login.jsp (handled by LoginActionBean class) redirects after
submission login form to calculator.jsp. After submition form from
calculator.jsp  (what is handled by CalculatorActionBean class) it
returns to calculator.jsp and shows the result of mathematical
equation. Sources of calculator.jsp and it's class are placed below.

Problem shows when I'm submiting from LoginActionVean to
calculator.jsp. Like I wrote before, LoginActionBean doesn't have
result field because it doesn't need it. But JSP (in this case used by
two classes) expects result in:
46:c:if test=${!empty actionBean.result}
47:Result: ${actionBean.result}br/
line.

Here actionBean could be an instance of different class.

Sorry for so much source in thread, here it goes:




#
package com.some.packages.action;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontValidate;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.LocalizableError;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidationErrors;
import net.sourceforge.stripes.validation.ValidationMethod;

/**
* A very simple calculator action.
* @author Tim Fennell
*/

public class CalculatorActionBean implements ActionBean {

private ActionBeanContext context;
private String forwardSuccess = /calculator.jsp;
private String forwardFail = /index.jsp;

private Double result;
@Validate(required=true, mask=^\\d*$) private double numberOne;
@Validate(required=true, mask=^\\d*$) private double numberTwo;

public CalculatorActionBean() {
}

/* execution */

/*
 * Handler method.
 * Handles addition functionality of web application form.
 */
@DefaultHandler
@DontValidate
public Resolution init() {
return new ForwardResolution(forwardSuccess);
}

/*
 * Handler method.
 * Handles addition functionality of web application form.
 */
public Resolution addition() {
result = getNumberOne() + getNumberTwo();
return new ForwardResolution(forwardSuccess);
}

/* getters and setters */

public ActionBeanContext getContext() {
return context;
}

public void setContext(ActionBeanContext context) {
this.context = context;
}

public double getNumberOne() {
return numberOne;
}

public void setNumberOne(double numberOne) {
this.numberOne = numberOne;
}

public double getNumberTwo() {
return numberTwo;
}

public void setNumberTwo(double numberTwo) {
this.numberTwo = numberTwo;
}

public Double getResult() {
return result;
}

public void setResult(Double result) {
this.result = result;
}

}
#




#
%@ page contentType=text/html;charset=UTF-8 language=java %
%@ taglib prefix=stripes uri=http://stripes.sourceforge.net/stripes.tld%
%@ taglib prefix=display uri=http://displaytag.sf.net%
%@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core; %
%@ taglib prefix=fmt uri=http://java.sun.com/jsp/jstl/fmt; %
fmt:setBundle basename=StripesResources/

stripes:layout-render name=/pages/layout/default.jsp

   stripes:layout-component name=contents

   h3fmt:message key=title / - fmt:message
key=title.calculator//h3

   stripes:errors /

   stripes:form action=/Calculator.action focus=

   table
   tr
   td
   div
   div style=width:150px;stripes:label
for=numberOne//div
   div style=display:inlinestripes:text
name=numberOne//div
   /div
   div
   div style=width:150px;stripes:label
for=numberTwo//div
   div style=display:inlinestripes:text
name=numberTwo//div
   /div
   /td
   td valign=bottom
   div
   

Re: Expression Language in JSP and JasperException

2007-02-21 Thread David Smith
Ok.  I'm not overly familiar with Stripes, so you'll have to bear with
me a little.  I can think of a few ways to handle this.

First, look at what makes a request from calculator.jsp unique.  You
could use the referrer header, the value of a submit button, or the
presence of the equation request parameter.  Below is an example using
the submit button:

c:if test=${(param.submitBtn == 'Calculate') and (actionBean.result !=
null)}
  pThe answer is ${actionBean.result}/p
/c:if

A better solution would be to name the actionBean that's a result of
CalculatorActionBean something more descript than just 'actionBean' like
'calcBean'.  The main advantage here is it's simple and you could use
your original expression language test -- just change the name of the
object being tested:

c:if test=${calcBean.result != null}
  ... display the result
/c:if

A more complicated solution if you can't change the name of 'actionBean'
might be to test the type of actionBean like...

c:set var=calcAvailablejsp:expression
  (request.getAttribute(actionBean) != null) 
(request.getAttribute(actionBean) instanceOf
com.some.packages.action.CalculatorActionBean )/jsp:expression/c:set
c:choose
c:when test=${calcAvailable and (actionBean.result != null)}
  pThe answer is  ${actionBean.result}/p
/c:when
c:when test=${calcAvailable}
  pSorry, I couldn't understand your equation.  Please rephrase it.../p
/c:when
c:otherwise
  !-- Just logged in.  Display the form. --
/c:otherwise
/c:choose

The essential point of this is testing for a property to be null is not
the same as testing for it's presence.  You'll have to know if it has a
property before you can test the property for null.

--David

Piotr Kiraga wrote:

 Hi David,

 Ok  forgive me now, but this is getting confusing.  Where does
 result come into this picture?  Were you expecting actionBean to be an
 instance of a different class?  You aren't offering a lot to go on here.


 Sorry for mixup. I've just thought that it is just about some option
 in Tomcat configuration or something, and I haven't knew it. Like I
 see... It may be not. :(

 Here goes more background.

 login.jsp (handled by LoginActionBean class) redirects after
 submission login form to calculator.jsp. After submition form from
 calculator.jsp  (what is handled by CalculatorActionBean class) it
 returns to calculator.jsp and shows the result of mathematical
 equation. Sources of calculator.jsp and it's class are placed below.

 Problem shows when I'm submiting from LoginActionVean to
 calculator.jsp. Like I wrote before, LoginActionBean doesn't have
 result field because it doesn't need it. But JSP (in this case used by
 two classes) expects result in:
 46:c:if test=${!empty actionBean.result}
 47:Result: ${actionBean.result}br/
 line.

 Here actionBean could be an instance of different class.

 Sorry for so much source in thread, here it goes:




 #
 package com.some.packages.action;

 import net.sourceforge.stripes.action.ActionBean;
 import net.sourceforge.stripes.action.ActionBeanContext;
 import net.sourceforge.stripes.action.DefaultHandler;
 import net.sourceforge.stripes.action.DontValidate;
 import net.sourceforge.stripes.action.ForwardResolution;
 import net.sourceforge.stripes.action.Resolution;
 import net.sourceforge.stripes.validation.LocalizableError;
 import net.sourceforge.stripes.validation.Validate;
 import net.sourceforge.stripes.validation.ValidationErrors;
 import net.sourceforge.stripes.validation.ValidationMethod;

 /**
 * A very simple calculator action.
 * @author Tim Fennell
 */

 public class CalculatorActionBean implements ActionBean {

 private ActionBeanContext context;
 private String forwardSuccess = /calculator.jsp;
 private String forwardFail = /index.jsp;
 
 private Double result;
 @Validate(required=true, mask=^\\d*$) private double numberOne;
 @Validate(required=true, mask=^\\d*$) private double numberTwo;

 public CalculatorActionBean() {
 }
 
 /* execution */
 
 /*
  * Handler method.
  * Handles addition functionality of web application form.
  */
 @DefaultHandler
 @DontValidate
 public Resolution init() {
 return new ForwardResolution(forwardSuccess);
 }

 /*
  * Handler method.
  * Handles addition functionality of web application form.
  */
 public Resolution addition() {
 result = getNumberOne() + getNumberTwo();
 return new ForwardResolution(forwardSuccess);
 }

 /* getters and setters */
 
 public ActionBeanContext getContext() {
 return context;
 }

 public void setContext(ActionBeanContext context) {
 this.context = context;
 }

 public double getNumberOne() {
 return numberOne;
 }

 public void setNumberOne(double numberOne) {
 this.numberOne = numberOne;
 }

 public double getNumberTwo() {
 

Expression Language in JSP and JasperException

2007-02-20 Thread Piotr Kiraga

Hi,

When I'm using in JSP:
  c:if test=${actionBean.result != null}.../c:if
Tomcat (5.5.17) throws exception (javax.servlet.ServletException:
Unable to find a value for result in object of class
com.some.packages.action.LoginActionBean using operator .).

I've heard that it can be configured in Tomcat, so he could pass
through it without an exception. Is it true? If so, how to do that?


Regards,

--
Piotr Kiraga

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expression Language in JSP and JasperException

2007-02-20 Thread David Smith
Does com.some.packages.action.LoginActionBean have a public method
getResult()?  The test below effectively translates to:

if (actionBean.getResult() != null) {
   //  some stuff to do 
}

--David

Piotr Kiraga wrote:

 Hi,

 When I'm using in JSP:
   c:if test=${actionBean.result != null}.../c:if
 Tomcat (5.5.17) throws exception (javax.servlet.ServletException:
 Unable to find a value for result in object of class
 com.some.packages.action.LoginActionBean using operator .).

 I've heard that it can be configured in Tomcat, so he could pass
 through it without an exception. Is it true? If so, how to do that?


 Regards,



-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expression Language in JSP and JasperException

2007-02-20 Thread Piotr Kiraga

Does com.some.packages.action.LoginActionBean have a public method
getResult()?  The test below effectively translates to:

if (actionBean.getResult() != null) {
   //  some stuff to do 
}


The problem is that there could be a class that has no property with
name result. In another case there could be another class (bean) that
has such property (than of course it works fine, but at first case
Tomcat throws exception).

--
Piotr Kiraga

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expression Language in JSP and JasperException

2007-02-20 Thread David Smith

Piotr Kiraga wrote:

Does com.some.packages.action.LoginActionBean have a public method
getResult()?  The test below effectively translates to:

if (actionBean.getResult() != null) {
   //  some stuff to do 
}


The problem is that there could be a class that has no property with
name result. In another case there could be another class (bean) that
has such property (than of course it works fine, but at first case
Tomcat throws exception).

Maybe but let's keep debugging simple.  The expression language is 
expecting a class conforming to the JavaBeans standard.  What does the 
class com.some.packages.action.LoginActionBean look like?


--David

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expression Language in JSP and JasperException

2007-02-20 Thread Piotr Kiraga

 The problem is that there could be a class that has no property with
 name result. In another case there could be another class (bean) that
 has such property (than of course it works fine, but at first case
 Tomcat throws exception).

Maybe but let's keep debugging simple.  The expression language is
expecting a class conforming to the JavaBeans standard.  What does the
class com.some.packages.action.LoginActionBean look like?


Here is LoginActionBean class code (like I sad before, there is no
result field, so getter and seter either):


package com.some.packages.action;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontValidate;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.LocalizableError;
import net.sourceforge.stripes.validation.Validate;

import com.some.packages.util.Global;
import com.some.packages.util.SessionManager;
import com.some.packages.vo.UserVO;

/**
* @author Piotr Kiraga
* @since 2007-02-15 12:13:06
*/
public class LoginActionBean implements ActionBean {

private ActionBeanContext context;
private String forwardSuccess = /calculator.jsp;
private String forwardFail = /index.jsp;

@Validate(required=true, mask=^.{4,8}$) private String userName;
@Validate(required=true, mask=^.{1,8}$) private String password;

/* execute 
*/

/*
 * Handler method.
 * Handles default action.
 */
@DefaultHandler
@DontValidate
public Resolution init() {
return new ForwardResolution(forwardFail);
}

/*
 * Handler method.
 * Handles login action.
 */
public Resolution login() {
if ( SessionManager.authorize(getContext(), getUserName(), 
getPassword()) ) {
return new ForwardResolution(forwardSuccess);
}
else {

this.getContext().getValidationErrors().addGlobalError(new
LocalizableError(login.error.invalidUserOrPass, userName));
return init();
}
}

/* validation 
**/

/* getters and setters
*/

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public ActionBeanContext getContext() {
return context;
}

public void setContext(ActionBeanContext context) {
this.context = context;
}

}



Regards,

--
Piotr Kiraga

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expression Language in JSP and JasperException

2007-02-20 Thread David Smith
Ok  forgive me now, but this is getting confusing.  Where does 
result come into this picture?  Were you expecting actionBean to be an 
instance of a different class?  You aren't offering a lot to go on here.



--David

Piotr Kiraga wrote:

 The problem is that there could be a class that has no property with
 name result. In another case there could be another class (bean) that
 has such property (than of course it works fine, but at first case
 Tomcat throws exception).

Maybe but let's keep debugging simple.  The expression language is
expecting a class conforming to the JavaBeans standard.  What does the
class com.some.packages.action.LoginActionBean look like?


Here is LoginActionBean class code (like I sad before, there is no
result field, so getter and seter either):


package com.some.packages.action;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontValidate;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.LocalizableError;
import net.sourceforge.stripes.validation.Validate;

import com.some.packages.util.Global;
import com.some.packages.util.SessionManager;
import com.some.packages.vo.UserVO;

/**
* @author Piotr Kiraga
* @since 2007-02-15 12:13:06
*/
public class LoginActionBean implements ActionBean {

private ActionBeanContext context;
private String forwardSuccess = /calculator.jsp;
private String forwardFail = /index.jsp;

@Validate(required=true, mask=^.{4,8}$) private String userName;

@Validate(required=true, mask=^.{1,8}$) private String password;

/* execute 
*/ 


/*

 * Handler method.
 * Handles default action.
 */
@DefaultHandler
@DontValidate
public Resolution init() {
return new ForwardResolution(forwardFail);
}

/*

 * Handler method.
 * Handles login action.
 */
public Resolution login() {
if ( SessionManager.authorize(getContext(), getUserName(), 
getPassword()) ) {

return new ForwardResolution(forwardSuccess);
}
else {
this.getContext().getValidationErrors().addGlobalError(new
LocalizableError(login.error.invalidUserOrPass, userName));
return init();
}
}

/* validation 
**/

/* getters and setters

*/

public String getPassword() {

return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public ActionBeanContext getContext() {
return context;
}

public void setContext(ActionBeanContext context) {
this.context = context;
}

}



Regards,




--
David Smith
Network Operations Supervisor
Department of Entomology
Cornell University
2132 Comstock Hall
Ithaca, NY 14853
Phone: (607) 255-9571
Fax: (607) 255-0940


-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expression Language in JSP and JasperException

2007-02-20 Thread Eric Haszlakiewicz
On Tue, Feb 20, 2007 at 03:23:32PM -0500, David Smith wrote:
 Ok  forgive me now, but this is getting confusing.  Where does 
 result come into this picture?  Were you expecting actionBean to be an 
 instance of a different class?  You aren't offering a lot to go on here.

That's what it sounds like to me:

 Piotr Kiraga wrote:
  The problem is that there could be a class that has no property with
  name result. In another case there could be another class (bean) that
  has such property (than of course it works fine, but at first case
  Tomcat throws exception).

I actually have some jsp code that does stuff like this, but in my case
there is a type property that each object has.  I check that and do
the appropriate thing.
If you want to hard code a class name in your jsp page, you can just use
${foo.class.name} to figure out what type of object you have.

Or, if you want to get really crazy you could loop over ${foo.class.methods}
checking if there's a method named getResult.

But, you'd probably be better off figuring out way to ensure the objects
you're working with have a result property.

eric

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]