2

People, I am with the following problem:

I have an object A that has a list of objects B.

But the number of objects in the list B is fixed (equal to 12, is an object with the month of the year and a value)

public class A{
    private Map<Integer, B> itens;         

    //gets e sets
}

public class B{
    private BigDecimal valor;
    private Date mes;  

    //gets e sets
}

I have the following question:

How can I be able to access this attribute value using JSF?

I've tried the following ways:

<h:outputLabel value="#{msg['label.mes.janeiro']}:" />
<h:inputText id="janeiro" styleClass="input-large money"
    value="#{levantamentoBean.itemCrud.itens[0].valor}">
</h:inputText>

and

 <h:outputLabel value="#{msg['label.mes.janeiro']}:" />
 <h:inputText id="janeiro" styleClass="input-large money"
        value="#{levantamentoBean.itemCrud.itens[0].valor}">
        <f:convertNumber pattern="#,##0.00" minFractionDigits="2" />
 </h:inputText>

When I receive the object in my Bean, it does not come with the updated value, that I entered in the input. Someone can tell me if this is possible?

  • I think with the BigDecimal auto-conversion will be the problem. I am to lazzy to test it. Try to set a different type for test proposes –  Oct 24 '13 at 18:33
  • 2
    Why would you use a `List` instead of a `Map`? With a Map you can index by the name of the month. – Jorge Campos Oct 24 '13 at 18:36
  • Your code is not very clear but it seems like you are returning a class A value, is that necesary? Why don't you return the element instead (class B)? – danRod Oct 24 '13 at 20:36
  • Like @danRod said, your question is unclear. Are you interested only in item 0 of the list? At any rate, [you should move that logic in `getValorPorMes`](http://stackoverflow.com/q/15568838/1530938) into a `@PostConstruct` method. There are valid reasons why both of the options you've tried are not going to work – kolossus Oct 25 '13 at 07:16
  • @PauloDiogo hehe, told you :) –  Oct 25 '13 at 11:16
  • @PauloDiogo as matheszabi stated the problem with the bigDecimal, it could be the lack of a proper converter, dig around the internet, you will find some interesting things. – Jorge Campos Oct 25 '13 at 11:31

2 Answers2

1
<h:inputText id="janeiro" styleClass="input-large money" 
        value="#{levantamentoBean.itemCrud.itens[0].valor}">
    <f:converter converterId="javax.faces.BigDecimal"/>
</h:inputText>

If you need the pattern conversion see https://community.jboss.org/message/483357#483357

ChristophT
  • 510
  • 5
  • 10
  • man, if I don't update the fields when I submit the form, in a second time the previous value is saved, like: the first value was 1, I changed the value to 1000, the value saved was 1, in a second moment I don't update the fields, the value comes 1000, if I changed the value for 2000, the value saved was 1000. –  Oct 25 '13 at 11:48
  • Please show us more details of your code. The classes `A` and `B` are a bit too unspecific. ;-) Also please post the relevant parts of the facelet, i.e. the form and its active elements. – ChristophT Oct 25 '13 at 12:21
  • @matheszabi, @Jorge Campos, @danRod, @ChristophT ,peopple i solved the problem with ``execute="@all"`` in my ```` =D thx for your support! –  Oct 25 '13 at 12:24
1

My problem was solved with this:

<h:commandLink value="Save" actionListener="#{myBean.saveItem}">                                
    <f:ajax onevent="handleOutcome" execute="@all" 
             render=":formulario:table values descriptionNeed" />
</h:commandLink>

I put execute="@all" in the <h:commandLink>, that sent All component identifiers to the server.

References:

http://docs.oracle.com/javaee/6/tutorial/doc/gkabr.html

What is <f:ajax execute="@all"> really supposed to do? It POSTs only the enclosing form

https://community.jboss.org/message/563111

http://www.mkyong.com/jsf2/jsf-2-0-ajax-hello-world-example/

That is it!

Community
  • 1
  • 1