pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gk_br...@verizon.net>
Subject Re: Problems with flags
Date Wed, 22 Dec 2010 14:52:18 GMT
I don't see anything obviously lwrong. Can you step through the code (or add some debug output)
to verify that the flag-setting code is actually being called when you expect it to be?

On Dec 22, 2010, at 5:26 AM, Luiz Gustavo wrote:

> Hi Greg,
> 
> 
> These are the fragments involved:
> 
> 
> bxml
> ...
> <Form.Section>
>                         
>                             <TextInput Form.label="%lblDescricao" textSize="40" bxml:id="descricao"/>
>                             
>                             <BoxPane styles="{verticalAlignment:'center'}" Form.label="%lblValor">
>                                 <TextInput textSize="10" bxml:id="valor" />
>                                 <Checkbox buttonData="%lblConciliado" bxml:id="conciliado"
>                                     ButtonPressListener.buttonPressed="conciliadoImg.setVisible(conciliado.isSelected());"/>
>                                 <ImageView bxml:id="conciliadoImg" image="@conciliado.png"
visible="false"/>
>                             </BoxPane>
>                             
>                             <CalendarButton bxml:id="data" Form.label="%lblData"/>
>                                           
>                             <BoxPane Form.label="%lblTipo" orientation="horizontal"
styles="{padding:4}">                    
>                            
>                                 <bxml:define>
>                                     <ButtonGroup bxml:id="tipos"/>
>                                 </bxml:define>
>                                 <RadioButton bxml:id="despesaButton" buttonGroup="$tipos"
selected="true">
>                                     <content:ButtonData icon="@despesa.png" text="%lblDespesa"/>
>                                 </RadioButton>
>                                 <RadioButton bxml:id="receitaButton" buttonGroup="$tipos">
>                                     <content:ButtonData icon="@receita.png" text="%lblReceita"/>
>                                 </RadioButton>
>                                 
>                             </BoxPane>
>                             
>                             <ListButton bxml:id="categoria" Form.label="%lblCategoria"
/>
>                             
>                             <BoxPane Form.label="%lblObservacoes">
>                                 <Border styles="{color:10}">
>                                     <ScrollPane horizontalScrollBarPolicy="fill"
>                                         verticalScrollBarPolicy="fill_to_capacity"
>                                         preferredHeight="200" preferredWidth="500">
>                                         <TextArea bxml:id="observacoes"/>
>                                     </ScrollPane>
>                                 </Border>
>                             </BoxPane>
>                             
>                         </Form.Section>
> ...
> 
> 
> Binding class:
> 
> ...
>  Action.getNamedActions().put("salvarAction", new Action() {
>       @Override
>       public void perform(Component source) {
>         if (lancamento == null) {
>           salvarNovo();
>         }
>         else {
>           salvarEdicao();
>         }
>         atualizarGrid();
>       }
>     });
> 
> ...
> 
> 
> private void salvarNovo() {
> 
>     try {
>       
>       Form.Flag flagDesc = null;
>       Form.Flag flagVal = null;
>       Form.Flag flagCat = null;
>       
>       String desc = descricao.getText().trim();
>       String val = valor.getText().trim();
>       
>       if(desc == null || "".equals(desc.trim())){ 
>         flagDesc = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>       }
>       Form.setFlag(descricao, flagDesc);
>       
>       if(val == null || "".equals(val.trim())){   
>         flagVal = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>       }
>       Form.setFlag(valor, flagVal);
>       
>       if(categoria == null){      
>         flagCat = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>       }      
>       Form.setFlag(categoria, flagCat);
>       
>       if(flagDesc != null || flagVal != null || flagCat != null){
>         return;
>       }   
>       
>       lancamento = new Lancamento();
>       lancamento.setDescricao(desc);
>       lancamento.setConciliado(conciliado.isSelected());
>       lancamento.setData(data.getSelectedDate().toCalendar().getTime());
>       lancamento.setObservacao(observacoes.getText());
>       lancamento.setValor(new BigDecimal(numberFormat.parse(val)
>           .toString()));
>       lancamento.setTipoLancamento((CategoriaLancamento) categoria
>           .getSelectedItem());
> 
>       daoLancamento.cadastrar(lancamento);
>       cancelar();
>       Prompt.prompt(MessageType.INFO, resources.get("sucessoCadastro")
>           .toString(), this);
>     }
>     catch (Exception e) {
>       Prompt.prompt(MessageType.ERROR, resources.get("falhaCadastro")
>           .toString(), this);
>     }
> 
>   }
> 
>   private void salvarEdicao() {
> 
>     try {
> 
>       Form.Flag flagDesc = null;
>       Form.Flag flagVal = null;
>       Form.Flag flagCat = null;
>       
>       String desc = descricao.getText();
>       String val = valor.getText();
>       
>       if(desc == null || "".equals(desc.trim())){ 
>         flagDesc = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>       }
>       Form.setFlag(descricao, flagDesc);
>       
>       if(val == null || "".equals(val.trim())){   
>         flagVal = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>       }
>       Form.setFlag(valor, flagVal);
>       
>       if(categoria == null){      
>         flagCat = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>       }      
>       Form.setFlag(categoria, flagCat);
>       
>       if(flagDesc != null || flagVal != null || flagCat != null){
>         return;
>       }    
>       
>       lancamento.setDescricao(desc);
>       lancamento.setConciliado(conciliado.isSelected());
>       lancamento.setData(data.getSelectedDate().toCalendar().getTime());
>       lancamento.setObservacao(observacoes.getText());
>       lancamento.setValor(new BigDecimal(numberFormat.parse(val)
>           .toString()));
>       lancamento.setTipoLancamento((CategoriaLancamento) categoria
>           .getSelectedItem());
> 
>       daoLancamento.alterar(lancamento);
>       cancelar();
>       Prompt.prompt(MessageType.INFO,
>           resources.get("sucessoEdicao").toString(), this);
>     }
>     catch (Exception e) {
>       Prompt.prompt(MessageType.ERROR, resources.get("falhaEdicao").toString(),
>           this);
>     }
>   }
> 
> 
> I can't see a reason for flags no work in this scenario. I have another frame that has
just one field validated, and everything's right. Can you see something wrong?
> 
> 
> Thank's
> 
> Luiz Gustavo S. de Souza
> 
> http://luizgustavoss.wordpress.com
> http://luizgustavoss.blogspot.com
> http://twitter.com/lugustso
> 
> 
> 2010/12/22 Greg Brown <gk_brown@verizon.net>
> No, flags definitely don't appear one at a time - you should be able to flag all the
fields in your form if you want to. The message won't appear until you hover over the field,
but it should be outlined, and you should see the error icon.
> 
> There must be some other issue - not sure what it might be.
> 
> 
> On Dec 21, 2010, at 10:14 PM, Luiz Gustavo wrote:
> 
>> When the user enter some text in the field, it desapears, because flag is set to
null in the begining of the salvarEdicao method:
>> 
>> Form.Flag flagDesc = null;
>> 
>> ...
>> 
>> if(desc == null || "".equals(desc.trim())){ 
>>         flagDesc = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>> }
>> Form.setFlag(descricao, flagDesc);
>> 
>> 
>> So in the case of desc != null, I clean the flag. The problem is that the flag for
the second field (Valor) never apears. Initially i thought that flags apeared one per time
(not all at the same time), but even when the first field is ok, the flag of the second doesn't
apear.
>> 
>> Any idea?
>> 
>> 
>> 
>> 2010/12/22 Greg Brown <gk_brown@verizon.net>
>> If you want the flag to disappear when the user enters some text, you could add a
listener to the text input that clears the flag when the text changes.
>> 
>> On Dec 21, 2010, at 10:02 PM, Luiz Gustavo wrote:
>> 
>>> Hi Greg,
>>> 
>>> I'm calling salvarEdicao when the user submit de form. I whant to validate the
requeired fields befor inserting.
>>> I'll se the classes you told me, but in my scenario is there anything I can do?
>>> 
>>> 
>>> 
>>> 2010/12/22 Greg Brown <gk_brown@verizon.net>
>>> When are you calling the salvarEdicao() method? If you want to validate as the
user types, you'll need to call this method whenever the field value changes. For text, you
may want to consider using a validator for this. See the classes in org.apache.pivot.wtk.validation
and TextInput#setValidator().
>>> 
>>> 
>>> On Dec 21, 2010, at 9:37 PM, Luiz Gustavo wrote:
>>> 
>>>> Hi,
>>>> 
>>>> I'm having problems using Form.flag.
>>>> 
>>>> 
>>>> I have a method for inserting data from a form, and a validation on the begining:
>>>> 
>>>> 
>>>> private void salvarEdicao() {
>>>> 
>>>>     try {
>>>> 
>>>>      Form.Flag flagDesc = null;
>>>>       Form.Flag flagVal = null;
>>>>       Form.Flag flagCat = null;
>>>>       
>>>>       String desc = descricao.getText();
>>>>       String val = valor.getText();
>>>>       
>>>>       if(desc == null || "".equals(desc.trim())){ 
>>>>         flagDesc = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>>>>       }
>>>>       Form.setFlag(descricao, flagDesc);
>>>>       
>>>>       if(val == null || "".equals(val.trim())){   
>>>>         flagVal = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>>>>       }
>>>>       Form.setFlag(valor, flagVal);
>>>>       
>>>>       if(categoria == null){      
>>>>         flagCat = new Form.Flag(MessageType.ERROR, resources.get("campoRequerido").toString());
       
>>>>       }      
>>>>       Form.setFlag(categoria, flagCat);
>>>>       
>>>>       if(flagDesc != null || flagVal != null || flagCat != null){
>>>>         return;
>>>>       }     
>>>> 
>>>>       ...
>>>> }
>>>> 
>>>> 
>>>> When I try to submit a form with desc and val (description and value) empty,
just one flag is presented. Even when I insert data in the "Descrição" field, the flag in
the field "Descrição" continues to apear. The flag of field "Valor" doesn't apear in neigther
cases.
>>>> 
>>>> 
>>>> Any idea?
>>>> 
>>>> Cheers,
>>>> Luiz Gustavo S. de Souza
>>>> 
>>>> http://luizgustavoss.wordpress.com
>>>> http://luizgustavoss.blogspot.com
>>>> http://twitter.com/lugustso
>>>> <frame1.png><frame2.png>
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> Luiz Gustavo S. de Souza
>>> 
>>> http://luizgustavoss.wordpress.com
>>> http://luizgustavoss.blogspot.com
>>> http://twitter.com/lugustso
>> 
>> 
>> 
>> 
>> -- 
>> Luiz Gustavo S. de Souza
>> 
>> http://luizgustavoss.wordpress.com
>> http://luizgustavoss.blogspot.com
>> http://twitter.com/lugustso
> 
> 
> 
> 
> 


Mime
View raw message