You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Hunt <te...@yahoo.com> on 2001/02/02 20:46:10 UTC

define tag

Hi
If we use struts-bean:define tag and if the variable
is not found, does it raise exception. If yes how can
I catch it and handle it.
Normally if A is in Sesion scope and a property B
then we would do 
<bean:define id="m" name="A" scope="session"
type="typeA" />
<bean:define id="B" name="m" scope="page" type="typeB"
/>

Now if for some reason we cant find A in the session
or say A is null, we cant put a series of if
conditions in the jsp. How are we supposed to handle
such scenarios
Thanks
Hunt

__________________________________________________
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Re: define tag

Posted by Ted Husted <ne...@husted.com>.
OK, lame-brain is back again. Here's the example I was looking for. 

--

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<HTML>
<logic:present name="guava"><bean:define id="cool"
name="guava"/></logic:present>
<BODY>
<P>
<logic:present name="cool"><bean:write name="cool"
property="name"/></logic:present>
<logic:notPresent name="cool">Ooops</logic:notPresent>
</P>
</BODY>
</HTML>

--

Also note that logic:present / notPresent can be told which scope to
check, if that's important.

*********** REPLY SEPARATOR  ***********

On 2/2/2001 at 11:46 AM John Hunt wrote:

Hi
If we use struts-bean:define tag and if the variable
is not found, does it raise exception. If yes how can
I catch it and handle it.
Normally if A is in Sesion scope and a property B
then we would do 
<bean:define id="m" name="A" scope="session"
type="typeA" />
<bean:define id="B" name="m" scope="page" type="typeB"
/>

Now if for some reason we cant find A in the session
or say A is null, we cant put a series of if
conditions in the jsp. How are we supposed to handle
such scenarios
Thanks
Hunt


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/



Re: define tag

Posted by Ted Husted <ne...@husted.com>.
Ignore my previously example. It's totally wrong. 

I usually handle such matters defensively, by using logic:notPresent to
test for what I will need, and then forward-off to where I need to go
to get them (usually the action for the page). 

Can't seem to come up with a quick standalone example of this using
define bean though. But that's the general approach.

Long day. 

-T.



-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/



Re: define tag

Posted by Ted Husted <ne...@husted.com>.
Here's a sample JSP that may help answer your questions. 

<HTML>
<bean:define id="cool" name="guava"/>
<BODY>
<P><logic:notExist name="cool">Ooops ... </logic:notExist></P>
<P><bean:write name="cool" property="name"></P>
</BODY>
</HTML>

You''ll find that the bean tags, like HTML, are very forgiving.

One nice thing about working with JSP is that it very easy to try
things like this, to see how things work.

*********** REPLY SEPARATOR  ***********

On 2/2/2001 at 11:46 AM John Hunt wrote:

Hi
If we use struts-bean:define tag and if the variable
is not found, does it raise exception. If yes how can
I catch it and handle it.
Normally if A is in Sesion scope and a property B
then we would do 
<bean:define id="m" name="A" scope="session"
type="typeA" />
<bean:define id="B" name="m" scope="page" type="typeB"
/>

Now if for some reason we cant find A in the session
or say A is null, we cant put a series of if
conditions in the jsp. How are we supposed to handle
such scenarios
Thanks
Hunt

__________________________________________________
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/