开发者

Why are these Seam field values not binding?

I am building a a simple research routine whith 2 date fields a selectOneMenu and a button:

<h:form id="pesquisaAbastecimentoForm">
<table>
    <tr>
        <td>
            <s:decorate id="dataInicialField" template="../layout/edit.xhtml">
                <ui:define name="label" id="labelDataInicial">Data Inicial</ui:define>
                <rich:calendar id="dataInicial" value="#{abastecimentoAction.dataInicialPesquisa}"
                    datePattern="dd/MM/yyyy HH:mm" />
            </s:decorate>
            <s:decorate id="dataFinalField" template="../layout/edit.xhtml">
                <ui:define name="label" id="labalDataFinal">Data Final</ui:define>
                <rich:calendar id="dataFinal" value="#{abastecimentoAction.dataFinalPesquisa}"
                    datePattern="dd/MM/yyyy HH:mm" />
            </s:decorate>                           
        </td>
        <td>
            <s:decorate id="carroField" template="../layout/edit.xhtml">
                <ui:define name="label">Carro</ui:define>
                <h:selectOneMenu value="#{abastecimentoAction.idCarroPesquisa}" required="false">
                    <s:selectItems var="carro" value="#{carroList.resultList}" label="#{carro.nome}" itemValue="#{carro.id}" />
                </h:selectOneMenu>
            </s:decorate>
            <s:div styleClass="actionButtons">
                <s:button action="#{abastecimentoAction.pesquisaAbasatecimentos}" id="pesquisaAbastecimentos" value="Pesquisar Abastecimento">
                </s:button>
            </s:div>
        </td>
    </tr>
</table>
</h:form>

And I have a seam component which should get the values and get the method pesquisaAbastecimentos executed.

@Name("abastecimentoAction")
@Scope(ScopeType.CONVERSATION)
public class AbastecimentoAction implements Serializable {

    private static final long serialVersionUID = -2008939547568730028L;

    @Logger
    Log log;

    @In
    EntityManager entityManager;

    @In
    User user;

    //variáveis para pesquisa do abastecimento
    private Date dataInicialPesquisa;
    private Date dataFinalPesquisa;
    private int idCarroPesquisa;

    @DataModel
    List<AbastecimentoMensal> listaAbastecimentoMensal;

    @SuppressWarnings("unchecked")
    @Create
    public void pesquisaAbasatecimentos() { ... }

public Date getDataInicialPesquisa() {
        return dataInicialPesquisa;
    }

    public void setDataInicialPesquisa(Date dataInicialPesquisa) {
        this.dataInicialPesquisa = dataInicialPesquisa;
    }

    public Date getDataFinalPesquisa() {
        return dataFinalPesquisa;
    }

    public void setDataFinalPesquisa(Date dataFinalPesquisa) {
        this.dataFinalPesquisa = dataFinalPesquisa;
    }

    public int getIdCarroPesquisa() {
        return idCarroPesquisa;
    }

    public void setIdCarroPesquisa(int idCarroPesquisa) {
        this.idCarroPesquisa = idCarroPesquisa;
    }

The method is correctly executed but the values for the fields are never populated. As I am relatively new to seam I could not find out why these fields are not being correc开发者_如何学Ctly filled by seam framework. The values are actually null and 0 when the button is pressed and the method gets called. Any clues?

tx in advance. []s


Change

<s:button action="#{abastecimentoAction.pesquisaAbasatecimentos}" id="pesquisaAbastecimentos" value="Pesquisar Abastecimento">
            </s:button>

to

  <h:commandButton action="#{abastecimentoAction.pesquisaAbasatecimentos}" id="pesquisaAbastecimentos" value="Pesquisar Abastecimento">
            </h:commandButton>

The reason its not working is because <s:button> performs a HTTP GET, and does not POST your form.

You should also change int to Integer if it doesn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜