struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paweł Wielgus <poulw...@gmail.com>
Subject Re: How to access enum in jsp?
Date Sun, 06 Sep 2009 16:55:11 GMT
Hi Bill,
You are comparing string with enum by == operator, so it's always false.
Also if You see this value in debug it's the effect of toString() method.
You can access enum like this com.something.ActionState@NONE
if i remebmer correctly.

Best greetings,
Paweł Wielgus.


2009/9/6 Bill Bohnenberger <bill98122@gmail.com>:
> How do I reference an enum variable in an <s:if> test attribute?
> This is the situation, and the results I get:
>
> 1) I have a enum defined as
>
>    public enum ActionState
>    {
>        NONE, INIT, LIST, ADD, EDIT, DELETE ...
>    }
>
> 2) I have a variable of this type in my action class:
>
>    ActionState state;
>
> 3) My jsp contains the following code (this is just an example):
>
>    state = <s:property value="state"/>
>    <p>
>    <s:if test="%{state == 'LIST'}">true</s:if>
>    <s:else>false</s:else>
>    </p>
>
> 4) Here are the results in the browser:
>
> Struts ValueStack Debug
>
> Value Stack Contents ObjectProperty NameProperty Value
> com.rp.db.actions.Test update Update mapInstructions  servletContext
> org.apache.catalina.core.ApplicationContextFacade@b79701 recordName
> servletResponse org.apache.catalina.connector.ResponseFacade@22e177 save
> Save locale en_US next Next state LIST cancel Cancel addContinent Add
> Continent add Add upload null actionErrors [] errors {} uploadMap Upload Map
> page 0 tableName  delete Delete command  uploadContentType null serv null
> addRegion Add Region sessinfo null uploadImage Upload Image texts null
> pageCount 0 errorMessages [] done Done edit Edit actionMessages [] pageSize
> 20 back Back httpSession
> org.apache.catalina.session.StandardSessionFacade@15d45d9 init Init
> servletRequest org.apache.struts2.dispatcher.StrutsRequestWrapper@a0a36 log
> org.apache.log4j.Logger@e2b07b uploadFileName null fieldErrors {} pageTitle
> lastState NONE confirm Confirm Delete
> com.opensymphony.xwork2.DefaultTextProvider texts null
>
> Stack Context *These items are available using the #key notation*  KeyValue
> com.opensymphony.xwork2.dispatcher.HttpServletRequest
> org.apache.struts2.dispatcher.StrutsRequestWrapper@a0a36
> com.opensymphony.xwork2.ActionContext.localeen_US
> com.opensymphony.xwork2.dispatcher.HttpServletResponse
> org.apache.catalina.connector.ResponseFacade@22e177
> com.opensymphony.xwork2.ActionContext.nameTest_init
> com.opensymphony.xwork2.ActionContext.application
> {org.apache.catalina.resources=org.apache.naming.resources.ProxyDirContext@10b23cf,
> org.apache.catalina.WELCOME_FILES=[Ljava.lang.String;@84f566,
> freemarker.Configuration=freemarker.template.Configuration@12ea1dd,
> javax.servlet.context.tempdir=F:\development\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\marmoset,
> org.apache.catalina.jsp_classpath=/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/classes/;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/commons-fileupload-1.2.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/commons-io-1.3.2.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/commons-logging-1.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/freemarker-2.3.13.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/javax.persistence_1.99.0.v200906021518.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/jenkov-butterfly-persistence-5.0.0.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/jstl-impl-1.2.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/junit-3.8.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/log4j-1.2.15.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/ognl-2.6.11.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/spring-test-2.5.6.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/standard.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/struts2-config-browser-plugin-2.1.6.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/struts2-core-2.1.6.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/tabletags-1.0.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/xwork-2.1.2.jar;/F:/development/Tomcat
> 5.5/common/classes/;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-en.jar;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-es.jar;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-fr.jar;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-ja.jar;/F:/development/Tomcat
> 5.5/common/lib/commons-el.jar;/F:/development/Tomcat
> 5.5/common/lib/jasper-compiler-jdt.jar;/F:/development/Tomcat
> 5.5/common/lib/jasper-compiler.jar;/F:/development/Tomcat
> 5.5/common/lib/jasper-runtime.jar;/F:/development/Tomcat
> 5.5/common/lib/jsp-api.jar;/F:/development/Tomcat
> 5.5/common/lib/mysql-connector-java-5.1.7-bin.jar;/F:/development/Tomcat
> 5.5/common/lib/naming-factory-dbcp.jar;/F:/development/Tomcat
> 5.5/common/lib/naming-factory.jar;/F:/development/Tomcat
> 5.5/common/lib/naming-resources.jar;/F:/development/Tomcat
> 5.5/common/lib/servlet-api.jar;/F:/development/Tomcat%205.5/bin/bootstrap.jar;/F:/development/sun/sdk/jdk/lib/tools.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/dnsns.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/localedata.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/sunjce_provider.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/sunmscapi.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/sunpkcs11.jar}
> com.opensymphony.xwork2.ActionContext.conversionErrors{}  __component_stack
> [org.apache.struts2.components.Debug@fd4662]  last.property.accessednull
> com.opensymphony.xwork2.dispatcher.ServletContext
> org.apache.catalina.core.ApplicationContextFacade@b79701
> com.opensymphony.xwork2.dispatcher.PageContext
> org.apache.jasper.runtime.PageContextImpl@6937f9
> __requestWrapper.getAttributefalse  request
> {struts.valueStack=com.opensymphony.xwork2.ognl.OgnlValueStack@cad437,
> struts.view_uri=test.jsp, struts.request_uri=/marmoset/maint/Test_init,
> struts.actionMapping=org.apache.struts2.dispatcher.mapper.ActionMapping@178c490,
> javax.servlet.forward.servlet_path=/maint/Test_init,
> javax.servlet.forward.request_uri=/marmoset/maint/Test_init,
> __cleanup_recursion_counter=1, javax.servlet.forward.context_path=/marmoset,
> .freemarker.Request=freemarker.ext.servlet.HttpRequestHashModel@14f1726,
> .freemarker.RequestParameters=freemarker.ext.servlet.HttpRequestParametersHashModel@1b0de2e
> }  last.bean.accessednull  actioncom.rp.db.actions.Test@329572  parameters{}
> __link[Ljava.lang.Object;@1c0b8a0  application
> {org.apache.catalina.resources=org.apache.naming.resources.ProxyDirContext@10b23cf,
> org.apache.catalina.WELCOME_FILES=[Ljava.lang.String;@84f566,
> freemarker.Configuration=freemarker.template.Configuration@12ea1dd,
> javax.servlet.context.tempdir=F:\development\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\marmoset,
> org.apache.catalina.jsp_classpath=/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/classes/;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/commons-fileupload-1.2.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/commons-io-1.3.2.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/commons-logging-1.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/freemarker-2.3.13.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/javax.persistence_1.99.0.v200906021518.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/jenkov-butterfly-persistence-5.0.0.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/jstl-impl-1.2.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/junit-3.8.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/log4j-1.2.15.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/ognl-2.6.11.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/spring-test-2.5.6.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/standard.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/struts2-config-browser-plugin-2.1.6.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/struts2-core-2.1.6.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/tabletags-1.0.1.jar;/F:/development/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/marmoset/WEB-INF/lib/xwork-2.1.2.jar;/F:/development/Tomcat
> 5.5/common/classes/;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-en.jar;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-es.jar;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-fr.jar;/F:/development/Tomcat
> 5.5/common/i18n/tomcat-i18n-ja.jar;/F:/development/Tomcat
> 5.5/common/lib/commons-el.jar;/F:/development/Tomcat
> 5.5/common/lib/jasper-compiler-jdt.jar;/F:/development/Tomcat
> 5.5/common/lib/jasper-compiler.jar;/F:/development/Tomcat
> 5.5/common/lib/jasper-runtime.jar;/F:/development/Tomcat
> 5.5/common/lib/jsp-api.jar;/F:/development/Tomcat
> 5.5/common/lib/mysql-connector-java-5.1.7-bin.jar;/F:/development/Tomcat
> 5.5/common/lib/naming-factory-dbcp.jar;/F:/development/Tomcat
> 5.5/common/lib/naming-factory.jar;/F:/development/Tomcat
> 5.5/common/lib/naming-resources.jar;/F:/development/Tomcat
> 5.5/common/lib/servlet-api.jar;/F:/development/Tomcat%205.5/bin/bootstrap.jar;/F:/development/sun/sdk/jdk/lib/tools.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/dnsns.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/localedata.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/sunjce_provider.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/sunmscapi.jar;/F:/development/sun/sdk/jdk/jre/lib/ext/sunpkcs11.jar}
> xwork.NullHandler.createNullObjectsfalse  current.property.pathnull  attr
> org.apache.struts2.util.AttributeMap@320399
> com.opensymphony.xwork2.ActionContext.container
> com.opensymphony.xwork2.inject.ContainerImpl@fa54fe
> com.opensymphony.xwork2.ActionContext.session{monkbiz=+a5GzlUWW6ih69v2ExOWOYoLhfM=,
> monkbizPage=0, monkbizPageCount=9}
> com.opensymphony.xwork2.ActionContext.actionInvocation
> com.opensymphony.xwork2.DefaultActionInvocation@fb6763
> com.opensymphony.xwork2.util.ValueStack.ValueStack
> com.opensymphony.xwork2.ognl.OgnlValueStack@cad437
> session{monkbiz=+a5GzlUWW6ih69v2ExOWOYoLhfM=,
> monkbizPage=0, monkbizPageCount=9}  report.conversion.errorsfalse
> xwork.MethodAccessor.denyMethodExecutionfalse  struts.actionMapping
> org.apache.struts2.dispatcher.mapper.ActionMapping@178c490
> com.opensymphony.xwork2.ActionContext.parameters{}
>   state = LIST
>
>     false
> 5)  Incidentally, test="%{state.name == 'LIST'} doesn't work either, but
> when I use <s:debug>, the value of "state" in the Value Stack is shown as
> "LIST".
>
> Thanks,
> Bill
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message