how to put a value to a field "selectonmenu"

UI Components for JSF
Post Reply
caioatiladf
Posts: 39
Joined: 21 Jun 2011, 18:41

20 Jul 2011, 20:33

Good afternoon.

I have an application that shows only a xhtml "datatable" containing all records of a particular product.
When the user clicks an image, it is redirected to the registration application. Bean in this product I can put values ??in all other fields but can not put into the field "selectonmenu."
Can anyone help me? how to load the value for this field?

the xhtml:

Code: Select all

...
<table cellspacing="5px">
							<tr>
								<td><h:outputText value="Código" /></td>
								<td><p:inputText disabled="true"  title="Código da Nuance" size="20" value="#{controleNuance.nuaCodigoAux}" style="background: #EBF9FE;" /></td>


								<td><h:outputText value="Produto *" /></td>
								<td><p:selectOneMenu effect="drop" style="width:210px"
									value="#{controleNuance.codProduto}" required="true"
									requiredMessage="É necessário escolher a qual produto esta Nuance é pertencente!">
									<f:selectItem itemLabel="Selecione um Produto" itemValue="" />
									<f:selectItems value="#{controleProduto.lista}" var="prod"
										itemLabel="#{prod.proNome}" itemValue="#{prod.proCodigo}" />
								</p:selectOneMenu></td>

							</tr>
...





my bean:

Code: Select all



imports...

@ManagedBean
@RequestScoped
public class ControleNuance {
	Nuance Nuance = new Nuance();	
	public List<Nuance> lista = new ArrayList<Nuance>();
	RepositorioJPA<Nuance> jpa = new RepositorioJPA<Nuance>();
	ControleProduto controleProduto = new ControleProduto();
	List<Produto> listaProduto = new ArrayList<Produto>();
	
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Date date = new Date();
	
	
	private String undMedida;
	UnidadeMedida unidadeMedida = new UnidadeMedida();
		
	private String codProduto;
	Produto produto = new Produto();
	
	private String nuaCodigoAux;
	private boolean insert = true;
	private boolean edit = false;
		



	public String redirecionaEdicao(){	
		insert = false;
		edit = true;		
		
		//<--------------------------------------------------here i try to put the value ------------------------------------------->
		produto = new Produto();
		produto = jpa.selecionaUnidadeMedidaPorCodigo(Nuance.getProCodigo().getProCodigo());		
		//produto.setProCodigo(Nuance.getProCodigo().getProCodigo());		
		Nuance.setProCodigo(produto);

		//<--------------------------------------------------if I assign value to any other field to succeed------------------------>
		Nuance.setNuaPeso(12332.43);


		
		return "Create";
	}
	
	public String redirecionaListar(){
		return "List";
	}
	
	public List<Nuance> listaNuances(){
		List<Nuance> lista = jpa.selecionarTodosComOrdenacao("Nuance","nua_nome","asc");		

		listaProduto = controleProduto.getLista();

		return lista;
	}
	
	public List<Nuance> getLista() {		
		lista = listaNuances();
			
		return lista;
	}

	
	public Nuance getNuance() {
		return Nuance;
	}

	public void setNuance(Nuance Nuance) {
		this.Nuance = Nuance;
	}

	public String getNuaCodigoAux() {
		if(Nuance.getNuaCodigo() != null){
			nuaCodigoAux = Nuance.getNuaCodigo()+"";
		}else{
			nuaCodigoAux = "";
		}
		return nuaCodigoAux;		
	}

	public void setNuaCodigoAux(String nuaCodigoAux) {
		this.nuaCodigoAux = nuaCodigoAux;
	}

	public boolean isInsert() {
		return insert;
	}

	public void setInsert(boolean insert) {
		this.insert = insert;
	}

	public boolean isEdit() {
		return edit;
	}

	public void setEdit(boolean edit) {
		this.edit = edit;
	}

public UnidadeMedida getUnidadeMedida() {
		return unidadeMedida;
	}

	public void setUnidadeMedida(UnidadeMedida unidadeMedida) {
		this.unidadeMedida = unidadeMedida;
	}
	
	
	public String getUndMedida() {
		return undMedida;
	}

	public void setUndMedida(String undMedida) {
		this.undMedida = undMedida;
	}
	
	
	
	public Produto getProduto() {
		return produto;
	}

	public void setProduto(Produto produto) {
		this.produto = produto;
	}
	
	
	public String getCodProduto() {
		return codProduto;
	}

	public void setCodProduto(String codProduto) {
		this.codProduto = codProduto;
	}
	
	
}


Can anyone help me? I can only assign values ??to other fields and not for fields of type selectonmenu.

caioatiladf
Posts: 39
Joined: 21 Jun 2011, 18:41

25 Jul 2011, 18:29

...

User avatar
leventgny
Posts: 238
Joined: 24 May 2011, 16:49
Contact:

26 Jul 2011, 09:22

Hi,

In my trials, it seems p:selectOneMenu loads my list.
Or please clarify your problem if i missed any points.
Of course with your PrimeFaces version.
PrimeFaces Team Member

caioatiladf
Posts: 39
Joined: 21 Jun 2011, 18:41

26 Jul 2011, 14:08

Hello

The list is loaded with all values. What is not loaded is the following:

suppose I have chosen a particular value from the list and save. Once again I go on record that he had chosen that value and this value would have selected wines. you understand? The problem is not the list to come with values. That she always has. The problem is to make the list come with a certain amount already marked as default.

As an example I quote the following occasion: A person has a number of civil status. (single, married, divorced ...) Let's say I chose married to this person's marital status. Now whenever I enter the person would like this form was already filled by default in my MARRIED "dropbox." Got it?
Use primefaces 3.0 M2.

caioatiladf
Posts: 39
Joined: 21 Jun 2011, 18:41

28 Jul 2011, 14:06

Anyone know?


smallya
Posts: 264
Joined: 19 Mar 2010, 19:22
Contact:

28 Jul 2011, 23:01

I was having the same problem and then due to shortage of time I chose a workaround - using selectOneListBox instead.

<h:selectOneListbox id="language" value="#{currentUser.language.languageCode}" size="1">
<f:selectItems value="#{staticCacheManager.languageList}"/>
</h:selectOneListbox>
Netbeans 7.2| GlassFish 3.2 | PostgreSQL 9.1| MongoDB | Primefaces 3.4.2
_______________________________________________________________
Subraya Mallya
http://tinyhabit.com |http://twitter.com/tinyhabit

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 56 guests