Sorry,
the section
<f:converter
converterId="org.apache.myfaces.tobago.example.reference.IntegerConverter"
/>
should be included in the tc:selectOneChoice
This belongs to the faces-config.xml
<converter>
<converter-id>org.apache.myfaces.tobago.example.reference.IntegerConverter</converter-id>
<converter-class>org.apache.myfaces.tobago.example.reference.IntegerConverter</converter-class>
</converter>
But I revisit my testPage I forgot to set the valuebinding for the
property value. In my example I don't need a Converter anymore.
I would suggest you put a messages tag on your page anywhere (where it
made sense)
Just added my example code to the gendoc example webapp of tobago
https://svn.apache.org/repos/asf/myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/selectOneChoice.jsp
https://svn.apache.org/repos/asf/myfaces/tobago/trunk/tobago-tool/gendoc/src/main/java/org/apache/myfaces/tobago/example/reference/Controller.java
If you get a validation error from an other element you can surround the
tc:selecetOneChoice with a tc:form to enable partial validation for this
field.
Regards
Bernd
Clemens Sietas wrote:
Hello Bernd,
thank you for your hints. I implemented the converter class IntegerConverter
(hopefully I did choose the right Interface (javax.faces.convert.Converter)
My IDE already tells me that converter-id and converter-class are not allowed
here.
Thus the converter does not work in Tomcat.
I pasted the error output from Tomcat further down. A verbatim tag ist
suggested. However that did not help either.
You also mentioned a message tag (<tc:messages />). Can I place it anywhere in
the file?
What is wrong with my converter tag?
<tc:selectOneChoice value="#{myBean.userOption}"
valueChangeListener="#{maintenance.changeUserSelectedStatus}"
id="userGroupChoice">
<f:selectItems value="#{maintenance.userOptionItems}" id="userChoiceItems"/>
<converter>
<converter-id>com.test.converter.IntegerConverter</converter-id>
<converter-class>com.test.converter.IntegerConverter</converter-class>
</converter>
<f:facet name="change">
<tc:command />
</f:facet>
</tc:selectOneChoice>
-- the converter class:
package com.test.converter;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import javax.faces.convert.Converter;
import org.apache.log4j.Logger;
public class IntegerConverter implements Converter {
/** Log4j-Protokolierer */
private Logger log = Logger.getLogger(this.getClass().getName());
public Object getAsObject(FacesContext context, UIComponent component, String
value) throws ConverterException {
log.info("getAsObject " + value);
return new Integer(value);
}
public String getAsString(FacesContext context, UIComponent
component, Object value) throws ConverterException {
log.info("getAsString " + value);
return value.toString();
}
}
Tomcat output:
17.01.2007 08:48:06 BodyContent should be empty. Component with id _idJsp67 clas
s org.apache.myfaces.tobago.component.UIPanel content
<converter>
<converter-id>com.test.converter.IntegerConverter</converter-id>
<converter-class>com.test.converter.IntegerConverter</converter-class>
</converter>
Please use the f:verbatim tag for nested content!
Regards
Clemens
Hello Clemens,
I think you get a Validation Error : Value is not a valid option.
Can you add a message tag to your page?
Please change the type of your Constants to String or add a converter to
your selectOneChoice tag on the page
for example
<f:converter
converterId="org.apache.myfaces.tobago.example.reference.IntegerConverter"
/>
<converter>
<converter-id>org.apache.myfaces.tobago.example.reference.IntegerConverter</converter-id>
<converter-class>org.apache.myfaces.tobago.example.reference.IntegerConverter</converter-class>
</converter>
public class IntegerConverter implements Converter {
private static final Log LOG = LogFactory.getLog(OnOffConverter.class);
public Object getAsObject(FacesContext context, UIComponent
component, String value) throws ConverterException {
LOG.info("getAsObject " + value);
return new Integer(value);
}
public String getAsString(FacesContext context, UIComponent
component, Object value) throws ConverterException {
LOG.info("getAsString " + value);
return value.toString();
}
}
Regards
Bernd
Clemens Sietas wrote:
Hello,
I have read a long thread on the valueChangeListener from November 2006
in this mailing-list.
I adapted my code to the help in the tread, however, the
valueChangeListener still is not called.
I just subscribed to ask for further help. Here is my code:
<tc:loadBundle basename="overview" var="overviewBundle"/>
<layout:overview>
<jsp:body>
<f:view>
<tc:form>
<tc:panel>
...
...
<tc:panel>
<tc:selectOneChoice value="#{myBean.userOption}"
valueChangeListener="#{myBean.changeUserSelectedStatus}"
id="userChoice">
<f:selectItems value="#{myBean.userOptionItems}"
id="userChoiceItems"/>
<f:facet name="change">
<tc:command />
</f:facet>
</tc:selectOneChoice>
</tc:panel>
...
...
</tc:panel>
</tc:form>
</f:view>
</jsp:body>
</layout:overview>
----
public class ProcessChangeController {
/** Log4j-Protokolierer */
private Logger log = Logger.getLogger(this.getClass().getName());
private int userOption;
private static SelectItem[] userOptionItems = new SelectItem[]{
new SelectItem(new Integer(SEARCH_OPT_USER), "for User"),
new SelectItem(new Integer(SEARCH_OPT_ADMI), "for Admin")};
public int getUserOption() {
return userOption;
}
public void setUserOption(int userOption) {
this.userOption = userOption;
}
public void changeUserSelectedStatus(ValueChangeEvent event) {
log.info("PrChgCtrl_cls::changeUserSelectedStatus(ValueChangeEvent)
pressed");
userOption = (Integer) userOptionItems[1].getValue();
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale(Locale.US);
...
...
}
---
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>com.test.ProcessChangeController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
---
Thanks for any help
Clemens