Hi all.
Before I get into my question, I have been trying for 2 days to achieve what I want to do
and I've read almost every article I can find about the s:selectItems and
f:selectItems components that I can find. But, I can't seem to find any examples or I
am just not understanding things which is why I can't get this to work. But anyways,
this is my problem.
I have a web page that I want to use the selectOneMenu component on to select a
"Category" Object.
So I figured I could just use the following code:
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <html
xmlns="http://www.w3.org/1999/xhtml"
|
xmlns:ui="http://java.sun.com/jsf/facelets"
|
xmlns:h="http://java.sun.com/jsf/html"
|
xmlns:f="http://java.sun.com/jsf/core"
|
xmlns:rich="http://richfaces.org/rich"
|
xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
|
xmlns:s="http://jboss.com/products/seam/taglib"
|
xmlns:j4j="http://javascript4jsf.dev.java.net/"
| xmlns:gekko="http://gekkoTagLibs.com">
|
| <head></head>
| <body>
| <h:form id="searchCriteria" >
| <rich:panel>
| <f:facet name="header">
| <h:outputText value="Factor for Category/Subcategory Enquiry
(TLONL999)"></h:outputText>
| </f:facet>
|
| <rich:panel>
| <h:messages globalOnly="true"/>
| </rich:panel>
|
| <h:panelGrid columns="3">
| <h:outputText value="Category:"
styleClass="inputLabel"></h:outputText>
| <h:selectOneMenu id="categoryFilter"
value="#{catSubcatEnquiryActionBean.categoryCode}" >
| <s:selectItems value="#{categories}" var="category"
noSelectionLabel=""
| label="#{category.name}"/>
| <f:attribute name="className" value="CategoryCode"/>
| </h:selectOneMenu>
| <h:message for="categoryFilter"></h:message>
| <h:outputText value="Subcategory:"
styleClass="inputLabel"></h:outputText>
| <h:selectOneListbox id="subcategoryFilter">
| </h:selectOneListbox>
| <h:message for="subcategoryFilter"></h:message>
| <h:outputText value="Date:"
styleClass="inputLabel"></h:outputText>
| <rich:calendar id="calendarFilter"
| showInput="true"
| enableManualInput="true"
| datePattern="#{catSubcatEnquiryActionBean.dateFormat}"
| currentDate="#{catSubcatEnquiryActionBean.currentDate}"
| value="#{catSubcatEnquiryActionBean.dateFilter}"
| converter="gekkoDateConverter"
| >
| </rich:calendar>
| <h:message id="calendarErrors"
for="calendarFilter"></h:message>
| </h:panelGrid>
|
| </rich:panel>
|
| <h:commandButton id="formSubmit" type="submit"
value="Search" action="#{catSubcatEnquiryActionBean.doSearch}">
| <gekko:defaultAction/>
| </h:commandButton>
|
| </h:form>
|
| </body>
| </html>
|
the CatSubcatEnquiryActionBean is as follows:
| package gekko.web.actionbean.enquiryservices;
|
| import gekko.domain.reference.ltl.CategoryCode;
| import gekko.services.query.Query;
| import gekko.services.query.QueryService;
| import gekko.services.reference.DateService;
| import gekko.util.FormatUtils;
| import gekko.util.StringUtils;
|
| import java.util.Date;
| import java.util.List;
|
| import javax.faces.application.FacesMessage;
| import javax.faces.context.FacesContext;
| import javax.faces.validator.ValidatorException;
|
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Factory;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.datamodel.DataModel;
| import org.jboss.seam.annotations.datamodel.DataModelSelection;
| import org.jboss.seam.faces.FacesMessages;
|
| @Name("catSubcatEnquiryActionBean")
| @Scope(ScopeType.SESSION)
| public class CatSubcatEnquiryActionBean {
|
| @In("#{dateServiceImpl}")
| private DateService dateSvc; //NOPMD
|
| @In("#{queryServiceImpl}")
| private QueryService querySvc;
|
| @In
| FacesMessages facesMessages;
|
| private Date dateFilter;
| private String subcategory;
|
| @DataModel("categories")
| private List<CategoryCode> categoryList; //NOPMD
|
| @DataModelSelection("categories")
| private CategoryCode categoryCode;
|
| @Factory(value="categories")
| public void getCategories() {
| Query<CategoryCode> qCat = querySvc.createQuery(CategoryCode.class);
| qCat.equalsConstraint("deleted", false);
| categoryList = querySvc.list(qCat);
| }
|
| public Date getDateFilter() {
| return dateFilter;
| }
|
| public void setDateFilter(Date dateFilter) {
| this.dateFilter = dateFilter;
| }
|
| public Date getCurrentDate() {
| return dateSvc.getCurrentDate();
| }
|
| public String getDateFormat() {
| return FormatUtils.SHORT_DATE_FORMAT;
| }
|
| public String getSubcategory() {
| return subcategory;
| }
|
| public void setSubcategory(String subcategory) {
| this.subcategory = subcategory;
| }
|
| public List<CategoryCode> getCategoryList() {
| return categoryList;
| }
|
| public void setCategoryList(List<CategoryCode> categoryList) {
| this.categoryList = categoryList;
| }
|
| public CategoryCode getCategoryCode() {
| return categoryCode;
| }
|
| public void setCategoryCode(CategoryCode categoryCode) {
| this.categoryCode = categoryCode;
| }
|
| public String doSearch() throws ValidatorException {
|
| if (StringUtils.isBlank(this.subcategory) &&
| StringUtils.isBlank(FormatUtils.formatDate(this.dateFilter,
FormatUtils.SHORT_DATE_FORMAT, ""))) {
|
| FacesMessage message = new FacesMessage();
| message.setDetail("At least one of Category or Date must be filled in to
performa a search.");
| message.setSummary("No search criteria given");
| message.setSeverity(FacesMessage.SEVERITY_ERROR);
|
| FacesContext.getCurrentInstance().addMessage(null, message);
|
| }
|
| return "";
| }
|
| }
|
However, when I use this. I get the following message when I select a Category and submit
the form.
| /web/enquiryServices/categorySubcategory/catSubcategoryEnquiry.xhtml @26,95
value="#{catSubcatEnquiryActionBean.categoryCode}":
java.lang.IllegalArgumentException: argument type mismatch
|
I've attempted to use the <s:convertEntity/> but this gives me a No Transaction
error and would not work anyway because the CatSubcatEnquiryActionBean is not an Entity.
I can't make the Category.java a Seam bean due to the way our system architect wants
to seperate the persistence from Seam. They only want Seam for its JSF integration.
Just in case this is needed to solve my problem here is my faces-config.xml
| <?xml version="1.0" encoding="UTF-8"?>
| <faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
|
| <!--<component>-->
| <!--<component-type>gekko.web.defaultAction</component-type>-->
| <!--<component-class>-->
| <!--gekko.web.components.UIDefaultAction-->
| <!--</component-class>-->
| <!--</component>-->
|
| <!-- Facelets support -->
| <application>
| <variable-resolver>
| org.springframework.web.jsf.DelegatingVariableResolver
| </variable-resolver>
| <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
| <message-bundle>messages</message-bundle>
| </application>
|
| <converter>
| <converter-id>gekkoDateConverter</converter-id>
| <converter-class>
| gekko.web.converter.DateConverter
| </converter-class>
| </converter>
|
| <converter>
| <converter-id>gekkoGenericObjectConverter</converter-id>
| <converter-class>
| gekko.web.converter.GenericObjectConverter
| </converter-class>
| </converter>
|
| </faces-config>
|
and my components.xml
| <?xml version="1.0" encoding="UTF-8"?>
| <components
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns="http://jboss.com/products/seam/components"
|
xmlns:core="http://jboss.com/products/seam/core"
|
xmlns:bpm="http://jboss.com/products/seam/bpm"
|
xmlns:security="http://jboss.com/products/seam/security"
|
xmlns:framework="http://jboss.com/products/seam/framework"
|
xmlns:transaction="http://jboss.com/products/seam/transaction"
|
xmlns:spring="http://jboss.com/products/seam/spring"
| xsi:schemaLocation=
| "http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-2.0.xsd
|
http://jboss.com/products/seam/core
http://jboss.com/products/seam/core-2.0.xsd
|
http://jboss.com/products/seam/bpm
http://jboss.com/products/seam/bpm-2.0.xsd
|
http://jboss.com/products/seam/persistence
http://jboss.com/products/seam/transaction-2.0.xsd
|
http://jboss.com/products/seam/security
http://jboss.com/products/seam/security-2.0.xsd
|
http://jboss.com/products/seam/framework
http://jboss.com/products/seam/framework-2.0.xsd
|
http://jboss.com/products/seam/spring
http://jboss.com/products/seam/spring-2.0.xsd">
|
|
| <core:init transaction-management-enabled="false">
| </core:init>
| <transaction:no-transaction/>
|
| </components>
|
I guess I just want to know. How do I select an item in my selectOneMenu and update my
CatSubCatEnquiryActionBean?
I thought this would be easy, but I'm really struggeling to find a way to do this.
Do I need to write my own converter? And if so, how do I find out which selectItem was the
selected one?
I hope someone can make sense of what I'm trying to do cause I'm a tad confused at
the moment.
Thanks
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4098611#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...