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)}">
  <p>The 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="calcAvailable"><jsp: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)}">
  <p>The answer is .... ${actionBean.result}</p>
</c:when>
<c:when test="${calcAvailable}">
  <p>Sorry, 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() {
>         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">
>
>        <h3><fmt: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:inline"><stripes:text
> name="numberOne"/></div>
>                        </div>
>                        <div>
>                            <div style="width:150px;"><stripes:label
> for="numberTwo"/></div>
>                            <div style="display:inline"><stripes:text
> name="numberTwo"/></div>
>                        </div>
>                    </td>
>                    <td valign="bottom">
>                        <div>
>                            <stripes:submit name="addition"/>
>                            <stripes:submit name="subtraction"/>
>                            <stripes:submit name="multiplication"/>
>                            <stripes:submit name="division"/>
>                        <div>
>                    </td>
>                </tr>
>            </table>
>
>        </stripes:form>
>
>        <br/>
>
>        <hr size="1" noshade color="#000" align="left"><br/>
>        <c:if test="${!empty actionBean.result}">
>            Result: ${actionBean.result}<br/>
>        </c:if>
>        <c:if test="${!empty sessionScope.user.userName}">
>            Logged in as: ${sessionScope.user.firstName}
> ${sessionScope.user.lastName} (${sessionScope.user.userName})<br/>
>        </c:if>
>
>    </stripes:layout-component>
>
> </stripes:layout-render>
> #########################
>
>
>
>


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

Reply via email to