Combo product and play value in inputText

Asked

Viewed 43 times

1

I am developing a DOCUMENT registration with parameters such as Material, Name and other data. And how it will work, before performing a normal PRODUCT registration with parameters of Material and Name and on the registration screen of DOCUMENT I want to open a combo like this code "Material" and choosing it, will be automatically played the name in the inputText NAME field.

I created the combo and I can select.

How to perform this function, something from JSF, Javascript? They told me about valueChanceListener, but tmb do not know how it would be?

Canvas: inserir a descrição da imagem aqui

::PRODUCT ENTITY

@Audited
@Entity
@Table(name = "produto")
public class Produto implements Serializable{

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "material", unique = true, length = 5, nullable = false)
private int material;

@IdentificaCampoPesquisa(descricaoCampo = "Nome", campoConsulta = "nome",      principal = 1)
@Column(name = "nome", nullable = false, length = 50)
private String nome;

::DOCUMENT ENTITY

@Audited
@Entity
@Table(name = "documento")
public class Documento implements Serializable{

private static final long serialVersionUID = 1L;

@IdentificaCampoPesquisa(descricaoCampo = "Código", campoConsulta = "id")
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "material", length = 5, nullable = false)
private int material;

@IdentificaCampoPesquisa(descricaoCampo = "Nome", campoConsulta = "nome",      principal = 1)
@Column(name = "nome", nullable = false, length = 50)
private String nome;

::SCREEN AND SELECTONEMENU

<h:panelGrid id="gridDocCabecalho" columns="14">

<p:outputLabel for="material" value="Material " />
<p:selectOneMenu id="material" filter="true"
    value="#{documentoBeanView.objetoSelecionado.material}"
    converter="omnifaces.SelectItemsConverter" required="true"
    requiredMessage="Faltou selecionar o campo obrigatório 'Material'!!">

    <f:selectItem noSelectionOption="true"  itemLabel="Selecione material" />

    <f:selectItems value="#{produtoBeanView.produtos}" var="cursor"
    itemLabel="#{cursor.material}" itemValue="#{cursor.material}" 
    actionListener="documentoBeanView.teste()"/>
</p:selectOneMenu>

<p:outputLabel for="nome" value="Nome " />
<p:inputText id="nome" value="Nome " />

::Entity Produtobeanview

@Controller
@Scope(value="session")
@ManagedBean(name="produtoBeanView")
public class ProdutoBeanView extends BeanManagerViewAbstract {

private static final long serialVersionUID = 1L;

private String url = "/cadastro/cad_produto.jsf?faces-redirect=true";
private String urlFind = "/cadastro/busca/find_produto.jsf?faces-redirect=true";

private Produto objetoSelecionado =  new Produto();

private List<Produto> produtos = new ArrayList<Produto>();

@Autowired
private ProdutoController produtoController;

public List<SelectItem> getProduto() throws Exception{      
return produtoController.getListProdutoController();
}
  • The code returned in the browser, HTML.

  • I saw you edited the question. So it would be $(document).on("change", "#material", function(){ $("#nome").val($(":selected", this).text()); });

  • If you want to send the value, would be: $(document).on("change", "#material", function(){ $("#nome").val($(this).val()); });

  • Then I don’t know how to say why I don’t know about jsf. D But on ordinary pages this should work.

  • @Rafaelblum, front is not my forte...

No answers

Browser other questions tagged

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