How can I return default value of h:selectonemenu after click button submit in jsf -



How can I return default value of h:selectonemenu after click button submit in jsf -

i want homecoming null value of f:selectitem after submitted data

<h:selectonemenu id="tourcategory" value="#{placebean.tourcateid}" immediate="true" required="true" requiredmessage="tour category required"> <f:selectitem itemvalue="${null}" itemlabel="select..."></f:selectitem> <f:selectitems value="#{placebean.listtourcategory()}" var="tourcategory" itemlabel="#{tourcategory.name}" itemvalue="#{tourcategory.tourcateid}"> </f:selectitems> </h:selectonemenu>

you can accomplish clear value of tourcateid

this illustration nowadays how set default value h:selectonemenu

xhtml

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>setting default selectonemenu</title> </h:head> <h:body> <h:form> <h:selectonemenu id="coffeeselected" value="#{coffeebean.favcoffee3}"> <f:selectitem itemvalue="${null}" itemlabel="select..."> </f:selectitem> <f:selectitems value="#{coffeebean.favcoffee3value}" var="c" itemlabel="#{c.coffeelabel}" itemvalue="#{c.coffeevalue}" /> </h:selectonemenu> <h:commandbutton value="submit" actionlistener="#{coffeebean.clear}"> <f:ajax execute="@form" render="coffeeselected" /> </h:commandbutton> </h:form> </h:body> </html>

managedbean

package com.wittakarn.view; import java.io.serializable; import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped; import javax.faces.event.actionevent; @managedbean(name = "coffeebean") @sessionscoped public class coffeebean implements serializable { public string favcoffee3; public coffee[] coffee3list; public string getfavcoffee3() { homecoming favcoffee3; } public void setfavcoffee3(string favcoffee3) { this.favcoffee3 = favcoffee3; } public coffee[] getfavcoffee3value() { coffee3list = new coffee[3]; coffee3list[0] = new coffee("coffee3 - cream latte", "cream latte"); coffee3list[1] = new coffee("coffee3 - extreme mocha", "extreme mocha"); coffee3list[2] = new coffee("coffee3 - buena vista", "buena vista"); homecoming coffee3list; } public void clear(actionevent event){ system.out.println("favcoffee3:" + favcoffee3); favcoffee3 = null; } }

domain

public class coffee { public string coffeelabel; public string coffeevalue; public coffee(string coffeelabel, string coffeevalue) { this.coffeelabel = coffeelabel; this.coffeevalue = coffeevalue; } public string getcoffeelabel() { homecoming coffeelabel; } public string getcoffeevalue() { homecoming coffeevalue; } }

jsf

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -