In Displaytag if you want to use struts indexed properties and validate using DynaValidatorForm, here is the solution for this.

The below validates the user entered values in the input fields in a display:column and displays an error message and also highlights the invalid input fields when the enter value is invalid.

struts-config
<form-bean name="Form" type="org.apache.struts.validator.DynaValidatorForm" dynamic="true">
           <form-property name="hrs" type="java.util.ArrayList"/>
          ..................................
.............................................

</form-bean>


JSP:



<display:table name="sessionScope.Form.Hrs" id="rows" requestURI="PrepareAction.do" >
.................
..................
<display:column titleKey="lbl.hours">
//In the below c:set statement make sure to give the array(hrs[]) from the struts form-bean
      <c:set var="adHoursName" value="hrs[${rows_rowNum -1}].adHrs"/>

                   <c:if test="${rows.adHrs != null}">
                       <c:choose>
                           <c:when test="${rows_rowNum == 4}">
                                    <c:out value="${rows.adHrs}"/>
                           </c:when>
                           <c:otherwise>
<html:text name="Form" property='<%= pageContext.getAttribute("adHoursName").toString() %>' errorStyleClass="errormsg"/>
                           </c:otherwise>
                       </c:choose>
                   </c:if>
               </display:column>

</display:table>

validator.xml:
Take a look at http://www.niallp.pwp.blueyonder.co.uk/strutsvalidatorextends.html

   <formset>
       <form name="Form" >
           <field property="hrs" depends="extends">
               <var>
                   <var-name>extends</var-name>
                   <var-value>adhours</var-value>
               </var>
           </field>
       </form>
       <form name="adhours">
           <field property="adHrs" depends="integer,validwhen">
               <msg name="integer" key="lbl.notvalidnumber"/>
               <msg name="validwhen" key="lbl.notvalidnumber"/>
               <var>
                   <var-name>test</var-name>
                   <var-value>(*this* >= 0)</var-value>
               </var>
           </field>
       </form>
   </formset>

jsp: show errors: I am showing only one message using below. can show all error messages too.
<logic:messagesPresent>
<fmt:message var="errorMsg" key="lbl.entervalidnumber" bundle="${appbundle}"/>
     <span class="errors"><c:out value="${errorMsg}"/></span>
</logic:messagesPresent>


Thanks to all who helped me on working on this. Hope this saves time for other users who would like to do similar stuff.


From: "Rick Herrick" <[EMAIL PROTECTED]>
Reply-To: displaytag-user@lists.sourceforge.net
To: displaytag-user@lists.sourceforge.net
Subject: Re: [displaytag-user] Design question
Date: Thu, 6 Jul 2006 08:06:18 -0700 (PDT)

fea jabi wrote:
> This might not be exactly displaytag question. But hoping to get help.
>
> have a display tag table
>
> in one of the columns have <html:text>. not all rows have the <html:text>
> in
> this column.(<html:text>  struts tag)
>
> need to validate the user entered values in the <html:text> using
> validator.xml (of Struts).
>
> Created an object.java file which holds the row data of the table.
> Created
> a list of these row objects.
>
> Not sure how to proceed now. should I put the List as a property in the
> form-bean?? if I did so how will the user edited <html:text> updated to
> the
> list so that I can do validations?

This is one of the more difficult things to do without resorting to either
really butt-ugly solutions (e.g. naming form vars things like "textnn"
where nn is a number representing the list index of the object and having
to do string parsing of the var names and mapping of the params, etc.) or
somewhat difficult config and deployment schemes.

What I'd recommend is looking at the BeanUtils package.  Off the top of my
head, I can't remember exactly how the var naming works, but you end up
with something like this:

<input type="text" name="myText[nn]">

Again, in this case, nn is the index of the object in the list (it can
also be a key to a map), but BeanUtils handles translating this into the
appropriate object and property.  Or maybe something like this:

<input type="text" name="myList[nn].myTextProperty">

Where the myList[nn] translates to the correct object in the list and the
indicated property on that object gets set to the value.

Also, note that while I'm just using a straight <input> tag, this works
just as well for the Struts <html:text> tag.

Sorry I can't give you more explicit info on how to set this up, as it's
been quite a while since I've done it (I've been doing .Net development
for the past few months :^P).  And it's sort of complicated to get working
correctly, so I'd recommend setting up a real simple sandbox application
where you can get it working with a small data set.  But basically
BeanUtils gives you the ability to handle beans, maps, lists, etc. with
the familiar dot notation you use with ELs, displaytag, etc., such as
bean.listProperty[index].mapProperty[key].property.

--
Rick Herrick
[EMAIL PROTECTED]

I haven't got time for inner peace.

"No reasonable definition of reality could be expected to permit
this."--Albert Einstein, Boris Podolsky and Nathan Rosen in 1935


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to