[jboss-user] [JBoss Seam] - Re: Parameters not sent when using s:selectItems
marius.oancea
do-not-reply at jboss.com
Mon Nov 19 05:15:52 EST 2007
Problem is 99% solved by doing the following:
explicitelly added element convertor as Pete sugessted:
<h:selectManyListbox id="theList" value="#{testAction.multiSelect}" >
| <s:selectItems value="#{testAction.allElements}" var="element" label="#{element.name}" />
| <f:converter converterId="elementConvertor" />
| </h:selectManyListbox>
In param tag I called a convertor for the list parameter:
<?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="theList" converterId="elementListConvertor" value="#{testAction.multiSelect}" />
| </page>
The convertor is implemented as below:
| @org.jboss.seam.annotations.faces.Converter
| @Name("elementListConvertor")
| public class ElementListParameterConvertor implements Converter, Serializable {
| @In
| private EntityManager entityManager;
|
| @Transactional
| public Object getAsObject(FacesContext context, UIComponent component, String value) {
| if (value != null) {
| String[] allIds = value.split(" ");
| List<Element> theList = new ArrayList<Element>();
| for (int i = 0; i < allIds.length; i++) {
| String id = allIds;
| if (id == null || id.trim().length() == 0) continue;
| theList.add(findElement(id));
| }
| return theList;
| }
| return null;
| }
|
| private Element findElement(String id) {
| List<Element> allElements = TestAction.allElements;
| for (int i = 0; i < allElements.size(); i++) {
| if (allElements.get(i).getId().equals(new Integer(id))) return allElements.get(i);
| }
| return null;
| }
|
| public String getAsString(FacesContext context, UIComponent component, Object value) {
| if (value instanceof List) {
| List<Element> theList = (List<Element>) value;
| String s = "";
|
| for (Iterator iterator = theList.iterator(); iterator.hasNext();) {
| if (s.length() != 0) s += " ";
| Element element = (Element) iterator.next();
| s += element.id;
|
| }
| return s;
| }
| return null;
| }
|
| }
|
Having that done, all works (without need for any conversation propagation and so on).
Also if you call in the browser "localhost:8080/test/xList.seam?theList=1%202" the entries in "select" are selected as expected.
The single point that does not work is the url when you submit the page:
- point the browser to "localhost:8080/test/xList.seam?theList=1%202"
- system shows first two entries in list selected (AS EXPECTED)
- select the third entry and press submit
- system update the browser location to "localhost:8080/test/xList.seam" (WRONG, the correct is localhost:8080/test/xList.seam?theList=1%202%203)
For input Fields and selectOne, the system behaves as expected - parameter is automatically added to the URL. The problem is specific to selectManyListbox component.
Additionally, if you have a :
<s:link view="/xList.xhtml"
| value="Test List"
| propagation="none"/>
the select multi parameter is not automatically added (while an input filed and selectOne is).
Thanx again to Pete Muir for give me the valuable hints.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4105957#4105957
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4105957
More information about the jboss-user
mailing list