validation checkboxlist

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

validation checkboxlist

José Antonio Delgado Trujillo
I have a form with a checkboxlist linked to a bean with an array of string properties. I want the user must select at least one option.

Looking for the documentation, i think this is possible with field expression, but it requires ONGL expression.

I did it so:

FORM

<s:form action=“register”>

   <s:checkboxlist key=levels/>

</s:form>


BEAN
public class Person{

    private String[] levels;

}


XML VALIDATION
<validator>
   <field name=person.levels>
        <field-validator type=fieldexpression>
            <param name=“expression”><![CDATA[person.levels.length==0]]></param>
            <message>Selecciona al menos un curso</message>
       </field-validator>
  </field>
</validator

After that the first submit without selection i see the error field message. But if i select one options and submit i still see the error. Why??




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

Lukasz Lenart
2018-01-03 10:30 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:
>    <s:checkboxlist key=levels/>

Do you use ModelDriven? because this looks like linked directly to an action


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

José Antonio Delgado Trujillo
In the docs about model driven
https://struts.apache.org/core-developers/model-driven.html <https://struts.apache.org/core-developers/model-driven.html>

It is said that you must to implement the MovelDriven interface just the method getModel() to give an Object in which Struts populate with the parameters request and placed on the top.

i din’t understand the need of that because i can populate the object if it is a field of the Action’s class.

So what is the difference (the use of OGNL?) i can’t accede object properties?

My object person is of type Person class and it is a field of the action Register. Why can’t access to levels property of the object person by person.levels??

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

Lukasz Lenart
2018-01-04 13:24 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:
> In the docs about model driven
> https://struts.apache.org/core-developers/model-driven.html <https://struts.apache.org/core-developers/model-driven.html>
>
> It is said that you must to implement the MovelDriven interface just the method getModel() to give an Object in which Struts populate with the parameters request and placed on the top.

When using the ModelDriven interface, your top object on a stack will
be the Object, not an Action, so:
- with ModelDriven: <s:checkboxlist key=levels/> => person.levels (if
getModel() returns Person)
- without ModelDriven: <s:checkboxlist key=levels/> => levels (ia
property on an action level)

All OGNL expressions/tags are searching stack from the op to the
bottom, the top most object on the stack is always an action but
ModelDriven changes that, and a Model is the top most object on the
stack.


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

José Antonio Delgado Trujillo
OK,
Thanks for your explanation, i see clearer to use modeldriven or not.
My problem is not about the populate the options of the checkboxlist but the exception rule you must select at least one.

In the XML file i have

<field name=“personBean.levels”>
     <field-validator type=“fieldexpression>
          <param-name=“expression”>[!CDATA[#personBean.levels.length==0]]>></param>
          <message>You must select at least one option</message>
     </field-validator>
</field>


With that configuration i always obtain an error validation (showing the message in the checkboxñixt field)

In Person class
private String[] levels
private String[] levelsAvalaible={“1ESO”, “2ESO”, 3ESO”, “4ESO” }

with setters and getters


In the register-input.jsp
<form action=“register”>
   …
  <s:checkboxlist key=“personBean.levels” list=“levelsAvalaible”/>

</form>

I can see the options of the checkboxlist, but even selecting one option and submit the form i get error validation.

So i think It is a problem with the expression in the XML configuration.

 
Un saludo,
José A.

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

Lukasz Lenart
2018-01-04 18:53 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:
>           <param-name=“expression”>[!CDATA[#personBean.levels.length==0]]>></param>

"personBean.levels.isEmpty" ?

https://github.com/jkuhnert/ognl/blob/master/docs/LanguageGuide.md#pseudo-properties-for-collections

> In Person class
> private String[] levels
> private String[] levelsAvalaible={“1ESO”, “2ESO”, 3ESO”, “4ESO” }
>
> with setters and getters
>
>
> In the register-input.jsp
> <form action=“register”>
>    …
>   <s:checkboxlist key=“personBean.levels” list=“levelsAvalaible”/>

You should use "name" instead of "key"


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

José Antonio Delgado Trujillo
> “personBean.levels.isEmpty”


Yes, it’s empty an in the form the first time rendered all the options are unchecked.


>
> You should use "name" instead of "key"

Why not key? i have the correspondan property files
personBean.levels=Cursos

I also see the label Cursos and the options

The problem is about the XML validation.
<field name=“personBean.levels”>
     <field-validator type=“fieldexpression>
          <param-name=“expression”>[!CDATA[#personBean.levels.length==0]]>></param>
          <message>You must select at least one option</message>
     </field-validator>
</field>

It is always trigger

Un saludo,
José A.

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

Lukasz Lenart
2018-01-05 19:26 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:
> Why not key? i have the correspondan property files
> personBean.levels=Cursos
>
> I also see the label Cursos and the options

Ok, but please be aware that the most important thing is a "name"
attribute that must match the corresponding bean name and its
property.

>
> The problem is about the XML validation.
> <field name=“personBean.levels”>
>      <field-validator type=“fieldexpression>
>           <param-name=“expression”>[!CDATA[#personBean.levels.length==0]]>></param>
>           <message>You must select at least one option</message>
>      </field-validator>
> </field>

Here you have an example

https://github.com/apache/struts-examples/blob/master/control-tags/src/main/resources/org/apache/struts/edit/action/EditAction-validation.xml#L31


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

José Antonio Delgado Trujillo
Thanks a lot Lukasz,

I had the same like the example except the expression of the validation.
I misunderstood the param-name=“expression” - It was the expression to evaluate!!! (i was thinking about the expression to fail the validation)


>> <param-name=“expression”>[!CDATA[#personBean.levels.length==0]]>></param>

<para-name=“expression”>[!CDATA[personBean.levels.length > 0]]>></param>

Unfortunately it still doesn’t work and i don’t any idea why the form display always the error message.

Un saludo,
José A.

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

Lukasz Lenart
2018-01-08 20:04 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:
> <para-name=“expression”>[!CDATA[personBean.levels.length > 0]]>></param>
>
> Unfortunately it still doesn’t work and i don’t any idea why the form display always the error message.

Can you share rendered html? What's a name of the radio buttons?


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

Brian Holzer
In reply to this post by José Antonio Delgado Trujillo
Hey there,
   I'm not sure if this is affecting anything, but the syntax appears to be wrong for your <para-name="expression".... config.  Looking at yours below, compared to the example from the link that Lukasz provided you they are different.  I'm not sure if that was just a typo or not?

From the link:   <param name="expression"><![CDATA[personBean.carModels.length > 0]]></param>
vs
José :                 <para-name="expression">[!CDATA[personBean.levels.length > 0]]>></param>

in José's, the < and > don't match properly. There appears to be a missing < before the [!CDATA...  and an extra > after the 0]]
in José's,  <para-name=....   vs   from the link  <param name=.....

SGI (Corporate Head Office) • 2260 11th Avenue • Regina, SK • S4P0J9 • <a href="http:\\www.sgi.sk.ca">www.sgi.sk.ca • 1-844-TLK-2SGI (1-844-855-2744)

This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the named addressee, please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that using, disclosing, copying or distributing the contents of this information is strictly prohibited.

You are receiving this message because you are a customer of SGI.  If you do not wish to receive promotional messages via email, click here to unsubscribe (but you'll be missing out!)

>>> Lukasz Lenart <[hidden email]> January 9, 2018 12:16 AM >>>
2018-01-08 20:04 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:
> <para-name="expression">[!CDATA[personBean.levels.length > 0]]>></param>
>
> Unfortunately it still doesn't work and i don't any idea why the form display always the error message.

Can you share rendered html? What's a name of the radio buttons?


Regards
--
Lukasz
+ 48 606 323 122 http://www.lenart.org.pl/




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

José Antonio Delgado Trujillo
In reply to this post by Lukasz Lenart
solved!!!

It was a problem with unbalanced ]

Un saludo,
José A.

Reply | Threaded
Open this post in threaded view
|

Re: validation checkboxlist

José Antonio Delgado Trujillo
In reply to this post by Brian Holzer
Upss
unbalanced ]
the para-name was autocorrection of the email editor!!!
thanks

Un saludo,
José A.

> On 9 Jan 2018, at 14:45, Brian Holzer <[hidden email]> wrote:
>
> Hey there,
>    I'm not sure if this is affecting anything, but the syntax appears to be wrong for your <para-name="expression".... config.  Looking at yours below, compared to the example from the link that Lukasz provided you they are different.  I'm not sure if that was just a typo or not?
>
> From the link:   <param name="expression"><![CDATA[personBean.carModels.length > 0]]></param>
> vs
> José :                 <para-name="expression">[!CDATA[personBean.levels.length > 0]]>></param>
>
> in José's, the < and > don't match properly. There appears to be a missing < before the [!CDATA...  and an extra > after the 0]]
> in José's,  <para-name=....   vs   from the link  <param name=.....
>
> SGI (Corporate Head Office) • 2260 11th Avenue • Regina, SK • S4P0J9 • www.sgi.sk.ca <http://www.sgi.sk.ca/> • 1-844-TLK-2SGI (1-844-855-2744)
>
> This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the named addressee, please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that using, disclosing, copying or distributing the contents of this information is strictly prohibited.
>
> You are receiving this message because you are a customer of SGI.  If you do not wish to receive promotional messages via email, click here <https://mysgi.sgi.sk.ca/afOnlineServices/onlineservices/public/customerUnsubscribe.do> to unsubscribe (but you'll be missing out!)
>
> >>> Lukasz Lenart <[hidden email]> January 9, 2018 12:16 AM >>>
> 2018-01-08 20:04 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:
> > <para-name="expression">[!CDATA[personBean.levels.length > 0]]>></param>
> >
> > Unfortunately it still doesn't work and i don't any idea why the form display always the error message.
>
> Can you share rendered html? What's a name of the radio buttons?
>
>
> Regards
> --
> Lukasz
> + 48 606 323 122 http://www.lenart.org.pl/ <http://www.lenart.org.pl/>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]