[jboss-user] [JBoss Seam] - Re: Parameters not sent when using s:selectItems
marius.oancea
do-not-reply at jboss.com
Sun Nov 18 07:56:50 EST 2007
simple code not working (the List is not set on submit):
|
|
| import java.util.ArrayList;
| import java.util.List;
|
| import org.jboss.seam.annotations.Name;
|
| @Name("testAction")
| public class TestAction {
| public List<Element> multiSelect;
|
| public List<Element> getMultiSelect() {
| return multiSelect;
| }
|
| public void setMultiSelect(List<Element> multiSelect) {
| this.multiSelect = multiSelect;
| }
|
| static public List<Element> allElements = new ArrayList<Element>();
| static {
| allElements.add(new Element(1, "One"));
| allElements.add(new Element(2, "Two"));
| allElements.add(new Element(3, "Three"));
| }
| public List<Element> getAllElements() {
| return allElements;
| }
|
| public void setAllElements(List<Element> allElements) {
| TestAction.allElements = allElements;
| }
|
|
| }
|
|
|
| import java.io.Serializable;
| import java.util.List;
|
| import javax.faces.component.UIComponent;
| import javax.faces.context.FacesContext;
| import javax.faces.convert.Converter;
| import javax.persistence.EntityManager;
|
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Transactional;
|
|
| @Name("elementConvertor")
| @org.jboss.seam.annotations.faces.Converter(forClass=Element.class)
| public class ElementConvertor implements Converter, Serializable{
|
| @In
| private EntityManager entityManager;
|
| @Transactional
| public Object getAsObject(FacesContext context, UIComponent component, String value)
| {
| if (value != null)
| {
| try
| {
| Integer id = Integer.parseInt(value);
| if (id != null)
| {
| List<Element> allElements = TestAction.allElements;
| for (int i = 0; i < allElements.size(); i++) {
| if (allElements.get(i).getId().equals(id)) return allElements.get(i);
| }
| }
| }
| catch (NumberFormatException e) {
| }
| }
| return null;
| }
|
| public String getAsString(FacesContext context, UIComponent component, Object value)
| {
| if (value instanceof Element)
| {
| Element c = (Element) value;
| return "" + c.getId();
| }
| else
| {
| return null;
| }
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
| import java.util.ArrayList;
| import java.util.List;
|
| import org.jboss.seam.annotations.Name;
|
| @Name("testAction")
| public class TestAction {
| public List<Element> multiSelect;
|
| public List<Element> getMultiSelect() {
| return multiSelect;
| }
|
| public void setMultiSelect(List<Element> multiSelect) {
| this.multiSelect = multiSelect;
| }
|
| static public List<Element> allElements = new ArrayList<Element>();
| static {
| allElements.add(new Element(1, "One"));
| allElements.add(new Element(2, "Two"));
| allElements.add(new Element(3, "Three"));
| }
| public List<Element> getAllElements() {
| return allElements;
| }
|
| public void setAllElements(List<Element> allElements) {
| TestAction.allElements = allElements;
| }
|
|
| }
|
|
|
| === xList.page.xml====
| <?xml version="1.0" encoding="UTF-8"?>
| <page xmlns="http://jboss.com/products/seam/pages"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
|
| <param name="multiSelect" value="#{testAction.multiSelect}"/>
| </page>
|
|
|
| ===xList.xhtml=====
| <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:rich="http://richfaces.org/rich"
| template="layout/template.xhtml">
|
| <ui:define name="body">
|
| <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
|
| <h:form id="mySearch" styleClass="edit" >
|
| <rich:simpleTogglePanel label="Test submit multiple selection" switchType="ajax">
|
| <s:decorate template="layout/display.xhtml">
| <ui:define name="label">Please select some objects</ui:define>
| <h:selectManyListbox id="multiSelect" value="#{testAction.multiSelect}" >
| <s:selectItems value="#{testAction.allElements}"
| var="element"
| label="#{element.name}"/>
| </h:selectManyListbox>
|
| </s:decorate>
|
|
|
|
| </rich:simpleTogglePanel>
|
| <div class="actionButtons">
| <h:commandButton id="search" value="Search" action="/test/test.xhtml" />
| </div>
|
| </h:form>
|
| #{testAction.multiSelect}
|
|
| </ui:define>
|
| </ui:composition>
|
|
testAction.setMultiSelect() is never called.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4105846#4105846
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4105846
More information about the jboss-user
mailing list