user330606
user330606

Reputation:

Update a object in a list

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?

Upvotes: 2

Views: 1137

Answers (2)

user330606
user330606

Reputation:

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!

Upvotes: 1

ChristophT
ChristophT

Reputation: 510

<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

Upvotes: 1

Related Questions