Add Class Size to Product

Asked

Viewed 55 times

1

I need to do something that when you register a product, make a pizza equal in size and each size in price.

So I created a size class.

public class Tamanho implements Serializable {
@Id
@GeneratedValue
private Long idTamanho;
private String tamanho;
private Double valorTamanho;
private Long produto;

and made her call within my Product class

@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) 
private List<Tamanho> tamanhos;

Now hit the question as q I will add on the registration screen so when the person click on add a size the system generate a field for the user to enter a new size and so record.

Currently I’m doing so:

<div class="modal" id="modal">                        
                <div class="modal-content" style="color: #000; input{background-color: yellow};">
                    <div class="row">
                        <div class="col s12">
                            <h3>Cadastro de Produtos</h3>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <p:inputText type="hidden" hidden="hidden" id="id" value="#{produtoBean.prod.idProduto}"/>                                   
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <mp:input id="nome" label="Nome" value="#{produtoBean.prod.nomeProduto}"/>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <mp:input id="desc"
                                          label="Descrição" value="#{produtoBean.prod.descricaoProduto}"/>
                            </div>
                        </div>                           
                        <div class="row">
                            <div class="input-field col s12">                                       
                                <mp:input id="valor" type="number" label="Valor" value="#{produtoBean.prod.valorProduto}">
                                    <f:convertNumber pattern="#,##0.00"></f:convertNumber> 
                                </mp:input>
                            </div>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <p>Categoria</p>
                                <h:panelGroup layout="block" styleClass="selection">
                                    <h:selectOneRadio layout="pageDirection" id="categoria" converter="categoriaConverter" label="Categoria" value="#{produtoBean.prod.categoriaProduto}">
                                        <f:selectItems 
                                            value="#{loginBean.pessoaAtual.categorias}"
                                            var="categoria" itemValue="#{categoria}"
                                            itemLabel="#{categoria.tituloCategoria}"/>
                                    </h:selectOneRadio>
                                </h:panelGroup>
                            </div>
                        </div>  
                        <div class="row">
                            <div class="input-field col s12">
                                <p>Ingredientes</p>
                                <h:panelGroup layout="block" styleClass="selection">
                                    <h:selectManyCheckbox 
                                        id="ingrediente"                                                           
                                        converter="ingredienteConverter"  
                                        label="Ingrediente"   
                                        layout="pageDirection"                                           
                                        value="#{produtoBean.prod.ingredientesProduto}">

                                        <f:selectItems 
                                            value="#{ingredienteBean.listarIngrediente()}"
                                            var="ingrediente" itemValue="#{ingrediente}"
                                            itemLabel="#{ingrediente.nomeIngrediente}"/>

                                    </h:selectManyCheckbox>
                                </h:panelGroup>
                            </div>
                        </div> 

                        <div class="row">
                            <div class="input-field col s12">
                                <p>Foto</p>
                                <div class="col s12 l6 m6">
                                    <mp:input hidden="hidden" type="hidden" id="imagemProduto" value="#{produtoBean.prod.imagemProduto}"></mp:input>
                                    <p:fileUpload id="upload" update="imagem, imagemProduto" label="Selecionar..." skinSimple="true" mode="advanced"
                                                  fileUploadListener="#{produtoBean.upload}" auto="true"></p:fileUpload>                                                     
                                </div>
                                <div class="col s12 l6 m6">
                                    <mp:image id="imagem" circle="true" width="150" height="150" value="../imagens/#{produtoBean.prod.imagemProduto}" />
                                </div>
                            </div>
                        </div> 
                        <div class="row" style="text-align: center;">
                            <div class="input-field col s12">                                        
                                <mp:button update=":form1:listaProduto" value="Salvar" action="#{produtoBean.salvar}"></mp:button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
  • See if it helps you: http://answall.com/questions/27982/fields-dynamicos-com-jsf-e-ajax-n%C3%A3o-rendering-mascara

  • worked out. thanks

  • If it worked put the answer and mark it as correct, this way you will help others with the same doubt

1 answer

0


I created a table:

<div class="input-field col s12">                                         
                                <p:dataTable id="listaTamanhos" emptyMessage="" value="#{tamanhoBean.listaTamanho}" var="tam">
                                        <p:column class="center-align" priority="1" headerText="Tamanho">
                                            <h:outputText value="#{tam.tamanho}"></h:outputText>
                                        </p:column>
                                        <p:column class="center-align" priority="1" headerText="Valor">
                                            <h:outputText value="#{tam.valorTamanho}">
                                                <f:convertNumber pattern="#,##0.00"></f:convertNumber> 
                                            </h:outputText>
                                        </p:column>
                                        <p:column class="center-align" priority="1" headerText="Ações">
                                            <mp:button value="Remover" update="listaTamanhos" action="#{tamanhoBean.removerTamanho(tam)}"/>
                                        </p:column>
                                    </p:dataTable>      
                                    <mp:input id="tituloTamanho" label="Tamanho" value="#{tamanhoBean.tamanho.tamanho}"/>
                                    <mp:input id="valorTamanho" type="number" label="Valor" value="#{tamanhoBean.tamanho.valorTamanho}">
                                        <f:convertNumber pattern="#,##0.00"></f:convertNumber> 
                                    </mp:input>
                                    <mp:button value="Adicionar" update="listaTamanhos, tituloTamanho, valorTamanho" action="#{tamanhoBean.adicionarTamanho()}"/>

                            </div>

In it I would add the size values, then just take the table value and set inside the product.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.