You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ch...@kattare.com on 2005/07/09 13:27:42 UTC

two struts:logic and dynabeans questions



Hi,
I’m sorry if these questions are a bit newbie.  But then 
I am a newbie and
I’m getting a bit desperate since I need to get a demo up and working
this weekend and am, frankly, entirely stuck.

The bit of the project I’m currently working on dynamically builds a
multi-page form based on fields in a database.

We’re using Struts and Dynabeans to pass data from DB to the view tier.

I’m then iterating around the main form Dynabean result set and need to
do a large number of comparisons to values in other Dynabeans or values
in session scope etc.

So my first question is how can I check the value in a Dynabean against
a value in session scope?
Say for example I have the active session ID in a session scoped
variable called sectID and a bean containing the rows from the main query:

property="dynaProperties"/>
                            <logic:iterate id="row" name="rowSet"
property="rows" > 

Then:
                              <logic:equal name="row" property="sect_id"
value="<% request.getAttribute("sectID") %>">

(which doesn’t work, of course). I wondered about using jstl to do this
and thereby avoiud the scriptlet but it was beyond me how I could get it
to work with the Dynabean.

In a similar way I need to go a comparison from one Dynabeaan field to
another.

Say
<bean:define id="cols" name="pickList" property="dynaProperties"/>
                            <logic:iterate id="row" name="rowSet"
property="rows" >

<logic:iterate id="items" name="pickList" property="rows" > 
                                              <logic:equal name="items"
property="quest_id" value=<bean:write name="rows" 	property="quest_id" />>


Thanks in advance,

Charles








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


Re: two struts:logic and dynabeans questions

Posted by ch...@kattare.com.
Wendy,

Thanks so much for your response.  Sorry I have replied until now – 
I’ve had my head down trying to get the coding done.  I used the

<c:set var="jstlName">
    <bean:write name="myDynaBean" property="name" />
 </c:set>
 <c:out value="${jstlName}">

trick for the demo version.  I will revisit this this week with a view 
to hopefully using the DynaActionForms technique.

I’m using tomcat 5 by the way.

Charles
	






Quoting Wendy Smoak <ja...@wendysmoak.com>:

> From: <ch...@kattare.com>
> 
> > We're using Struts and Dynabeans to pass data from DB to the view
> tier.
> 
> What Servlet container and version are you using?  (The real question
> is,
> what version of the Servlet specification does it support?)  It's
> becoming
> more and more important to state that up front... I don't want to
> give the 
> usual
>  "use JSTL 1.0 and Struts-EL" speech, only to find out that you're
> on
> Tomcat 5.
> 
> > So my first question is how can I check the value in a Dynabean
> against
> > a value in session scope?
> > Say for example I have the active session ID in a session scoped
> > variable called sectID and a bean containing the rows from the main
> query:
> >
> >   <logic:equal name="row" property="sect_id"
> >             value="<% request.getAttribute("sectID") %>">
> >
> > (which doesn't work, of course).
> 
> Well... actually it _would_ if you'd make that:
>    <logic:equal name="myBean" property="name"
>              value="<%= request.getAttribute("someName") %>">
> (Note the <%= instead of <% in 'value'. )
> 
> > I wondered about using jstl to do this
> > and thereby avoiud the scriptlet but it was beyond me how I could
> get it
> > to work with the Dynabean.
> 
> I don't think JSTL 1.0 and DynaBean will work together:
>   
> http://www.mail-archive.com/commons-
user@jakarta.apache.org/msg00864.html
> That's an old message, but I did a quick test with Tomcat
> 4.1/BeanUtils 1.6
> and was not able to access a LazyDynaBean property with JSTL.  So I
> think it
> still holds for that combination.
> 
> Take a look at the Struts DynaActionForm classes and see what they
> did to
> fix the problem... there is a 'getMap()' method, so you can get to
> the
> properties with JSTL:
>      <c:out value="${myForm.map.propName}"/>
> or  <c:out value="${myForm.map['propName']}"/>
> 
> The Struts tags _do_ recognize DynaBeans,
>     <bean:write name="myDynaBean" property="name" />
> but then you're back to needing an expression in the <logic:equal>
> 'value'
> attribute.
> 
> This is ugly, but it works:
> <c:set var="jstlName">
>    <bean:write name="myDynaBean" property="name" />
> </c:set>
> <c:out value="${jstlName}">
> 
> I've never needed to do this, so there may be another combination of
> things
> that will get you what you need.
> 
> As for comparing objects, <logic:equal> turns into:
>    <c:if test="${someObj.prop eq someRequestAttr}"> ... </c:if>
> 
> -- 
> Wendy Smoak
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


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


Re: Calling validator rule direct from code

Posted by ch...@kattare.com.
Thanks for this.  I think I’m going to have to go a bit outside of 
standard Struts functionality to do what I need to do but the validator 
is part of commons now of course so I can make code level calls that 
way.



Quoting Martin Gainty <mg...@hotmail.com>:

> Good Morning Charles
> >From what I can gather there are 4 scenarios to instantiate a form
> and 
> handle validation
> http://mail-archives.apache.org/mod_mbox/struts-user/200407.mbox/%
3ccd0k69$78m$1@sea.gmane.org%3e
> 
> If you decide to use option D) DynaValidatorForm then
> Take a look at Rick Reumann's site for example of usage
> http://www.reumann.net/struts/lesson3/step4.do
> HTH,
> Martin-
> 
> ----- Original Message ----- 
> From: <ch...@kattare.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Monday, July 18, 2005 7:11 AM
> Subject: Calling validator rule direct from code
> 
> 
> > Hi,
> >
> > Using Tomcat 5,   I have an application which builds a multipage
> web
> > form based on data from a database and user input.  I'd like to be
> able
> > to use the validtator to it but can't determine the required
> fields
> > until run time.  I was wondering how I could use the pre-build
> > validator rules in this situation.  It is possible to explicitly
> call a
> > validator rule directly from a servlet.    For example suppose I
> wanted
> > to call the date validation rule passing it a string containing a
> date
> > field and a datePattern of mm/dd/yyyy.  Can this be done?  If so
> does
> > anyone have an example?  Or is there another way of solving this?
> >
> >
> > Thanks,
> >
> > Charles
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


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


Re: Calling validator rule direct from code

Posted by Martin Gainty <mg...@hotmail.com>.
Good Morning Charles
>From what I can gather there are 4 scenarios to instantiate a form and 
handle validation
http://mail-archives.apache.org/mod_mbox/struts-user/200407.mbox/%3ccd0k69$78m$1@sea.gmane.org%3e

If you decide to use option D) DynaValidatorForm then
Take a look at Rick Reumann's site for example of usage
http://www.reumann.net/struts/lesson3/step4.do
HTH,
Martin-

----- Original Message ----- 
From: <ch...@kattare.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Monday, July 18, 2005 7:11 AM
Subject: Calling validator rule direct from code


> Hi,
>
> Using Tomcat 5,   I have an application which builds a multipage web
> form based on data from a database and user input.  I'd like to be able
> to use the validtator to it but can't determine the required fields
> until run time.  I was wondering how I could use the pre-build
> validator rules in this situation.  It is possible to explicitly call a
> validator rule directly from a servlet.    For example suppose I wanted
> to call the date validation rule passing it a string containing a date
> field and a datePattern of mm/dd/yyyy.  Can this be done?  If so does
> anyone have an example?  Or is there another way of solving this?
>
>
> Thanks,
>
> Charles
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 

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


Calling validator rule direct from code

Posted by ch...@kattare.com.
Hi,

Using Tomcat 5,   I have an application which builds a multipage web 
form based on data from a database and user input.  I’d like to be able 
to use the validtator to it but can’t determine the required fields 
until run time.  I was wondering how I could use the pre-build 
validator rules in this situation.  It is possible to explicitly call a 
validator rule directly from a servlet.    For example suppose I wanted 
to call the date validation rule passing it a string containing a date 
field and a datePattern of mm/dd/yyyy.  Can this be done?  If so does 
anyone have an example?  Or is there another way of solving this?


Thanks,

Charles


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


Re: two struts:logic and dynabeans questions

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: <ch...@kattare.com>

> We're using Struts and Dynabeans to pass data from DB to the view tier.

What Servlet container and version are you using?  (The real question is,
what version of the Servlet specification does it support?)  It's becoming
more and more important to state that up front... I don't want to give the 
usual
 "use JSTL 1.0 and Struts-EL" speech, only to find out that you're on
Tomcat 5.

> So my first question is how can I check the value in a Dynabean against
> a value in session scope?
> Say for example I have the active session ID in a session scoped
> variable called sectID and a bean containing the rows from the main query:
>
>   <logic:equal name="row" property="sect_id"
>             value="<% request.getAttribute("sectID") %>">
>
> (which doesn't work, of course).

Well... actually it _would_ if you'd make that:
   <logic:equal name="myBean" property="name"
             value="<%= request.getAttribute("someName") %>">
(Note the <%= instead of <% in 'value'. )

> I wondered about using jstl to do this
> and thereby avoiud the scriptlet but it was beyond me how I could get it
> to work with the Dynabean.

I don't think JSTL 1.0 and DynaBean will work together:
   http://www.mail-archive.com/commons-user@jakarta.apache.org/msg00864.html
That's an old message, but I did a quick test with Tomcat 4.1/BeanUtils 1.6
and was not able to access a LazyDynaBean property with JSTL.  So I think it
still holds for that combination.

Take a look at the Struts DynaActionForm classes and see what they did to
fix the problem... there is a 'getMap()' method, so you can get to the
properties with JSTL:
     <c:out value="${myForm.map.propName}"/>
or  <c:out value="${myForm.map['propName']}"/>

The Struts tags _do_ recognize DynaBeans,
    <bean:write name="myDynaBean" property="name" />
but then you're back to needing an expression in the <logic:equal> 'value'
attribute.

This is ugly, but it works:
<c:set var="jstlName">
   <bean:write name="myDynaBean" property="name" />
</c:set>
<c:out value="${jstlName}">

I've never needed to do this, so there may be another combination of things
that will get you what you need.

As for comparing objects, <logic:equal> turns into:
   <c:if test="${someObj.prop eq someRequestAttr}"> ... </c:if>

-- 
Wendy Smoak



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