aspose file tools*
The moose likes JSF and the fly likes JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF" Watch "JSF" New topic
Author

JSF

Sivarama Raju
Greenhorn

Joined: May 22, 2008
Posts: 6
Hi friends,

Can any one please guide me to create a dropdown using JSF ?

Thanks and regards,
Arun Thulaseedharan
Greenhorn

Joined: May 07, 2008
Posts: 20
i think you can make use of <h:selectOneMenu> tag available in jsf for this....

<h:selectOneMenu value="#{form.day}">
<f:selectItem itemValue="Sunday" itemLabel="Sunday"/>
<f:selectItem itemValue="Monday" itemLabel="Monday"/>
<f:selectItem itemValue="Tuesday" itemLabel="Tuesday"/>
<f:selectItem itemValue="Wednesday" itemLabel="Wednesday"/>
<f:selectItem itemValue="Thursday" itemLabel="Thursday"/>
<f:selectItem itemValue="Friday" itemLabel="Friday"/>
<f:selectItem itemValue="Saturday" itemLabel="Saturday"/>
</h:selectOneMenu>

supposing that you want the value selected to go to the backing bean this code snippet is fine i guess.. here the value goes to the backing bean "form" and updates the property "day"....n for making this drop down we can make use of either <f:selectItem> when the list in the drop down is less and <f:selectItems> when the list in the drop down is more and you need to populate that from a backing bean......hope this answer your question...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16140
    
  21

You can also provide the selectItems as a list from a backing bean.

Note: please try to be more specific with your topic titles - it attracts people who are better able to help you when they know what the subject of the question will be without having to open up the message.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sivarama Raju
Greenhorn

Joined: May 22, 2008
Posts: 6
Hi Arun,

Thanks a lot for you reply friend. I will try using <h:selectOneMenu>.
I will inform you about my progress. Thanks a lot.

Thanks and regards,
siva
Sivarama Raju
Greenhorn

Joined: May 22, 2008
Posts: 6
Hey, thanks Tim.
Sivarama Raju
Greenhorn

Joined: May 22, 2008
Posts: 6
hi Arun,

I tried a lot with the Dropdown, but couldn't give action to the submit button, for the items in dropdown. This is my code:

JSF:
<h:selectOneMenu value="#{CalcBean.selectValue}">
<f:selectItem itemLabel="Add" itemValue="SubmitAdd" />
<f:selectItem itemLabel="Multiply"itemValue="SubmitMultiply" />
<f:selectItem itemLabel="Subtract" itemValue="SubmitDivide" />
<f:selectItem itemLabel="Divide" itemValue="SubmitDivide"/>
</h:selectOneMenu>

<h:commandButton action="#{CalcBean.selectChoice}" "Submit"></h:commandButton>

Backing bean:

public String selectChoice() {
String returnVal = "";
if (selectValue == "SubmitAdd") {
returnVal = add();
} else if (selectValue == "SubmitMultiply") {
returnVal = multiply();
} else if (selectValue == "SubmitSutract") {
returnVal = subtract();
} else if (selectValue == "SubmitDivide") {
returnVal = divide();
}
return returnVal;
}


public String getSelectChoice() {
return selectChoice;
}

public void setSelectValue(String aSelectValue) {
this.selectValue = aSelectValue;
}

public String getSelectValue() {
return selectValue;
}


Hey i am new yaar, might have dont some silly mistakes.

Thanks and regards,
siva
[ May 22, 2008: Message edited by: Sivarama Raju ]
Arun Thulaseedharan
Greenhorn

Joined: May 07, 2008
Posts: 20
this is my first page....
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<f:view>

<head>
<title><hutputText value="ProjectTrack" /></title>
</head>
<body>
<h:form>
<h:selectOneMenu value="#{calcBean.selectValue}">
<f:selectItem itemLabel="Add" itemValue="SubmitAdd" />
<f:selectItem itemLabel="Multiply" itemValue="SubmitMultiply" />
<f:selectItem itemLabel="Subtract" itemValue="SubmitSubtract" />
<f:selectItem itemLabel="Divide" itemValue="SubmitDivide" />
</h:selectOneMenu>

<h:commandButton value="Submit" type="submit" action="#{calcBean.selectChoice}" />
</h:form>
</body>
</f:view>
</html>

i think you dint put the tags inside a h:form...i guess only then you will be able to include that command button.....
Sivarama Raju
Greenhorn

Joined: May 22, 2008
Posts: 6
<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" version="2.0">

<ui:composition>
<h:form id="CalcForm">
<h:panelGrid columns="3">
<hutputLabel value="First Number" for="firstNumber" />
<h:inputText id="firstNumber" value="#{CalcBean.firstNumber}"
required="true" />
<h:message for="firstNumber" />

<hutputLabel value="Second Number" for="secondNumber" />
<h:inputText id="secondNumber" value="#{CalcBean.secondNumber}"
required="true" />
<h:message for="secondNumber" />
</h:panelGrid>
<h:panelGroup>

<h:selectOneMenu value="#{CalcBean.selectChoice}">

<f:selectItem itemLabel="Add" itemValue="SubmitAdd" />
<f:selectItem itemLabel="Multiply" itemValue="SubmitMultiply" />
<f:selectItem itemLabel="Subtract" itemValue="SubmitDivide" />
<f:selectItem itemLabel="Divide" itemValue="SubmitDivide"/>

</h:selectOneMenu>

<h:commandButton action="#{CalcBean.selectValue}" value="Submit"></h:commandButton>


</h:panelGroup>
</h:form>
</ui:composition>
</jsp:root>

Hi Arun
this is my dropdown.jspx page
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16140
    
  21

NOTE

Sivarama has reposted the question in this thread: http://www.coderanch.com/t/214027/JSF/java/Dropdown-created-has-list-items

It can be confusing when the same question is being answered by in different threads by people who don't know what other people are saying, so we ask that anyone wishing to say anything further on the topic respond on the new thread listed above.

Paul, could you close this thread, please? Sivarama's just taking my advice to use a more specific topic name, but since the topic was already started, we've ended up with this unfortunate situation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF