You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rob Decker <ro...@objectsource.org> on 2005/04/22 21:55:45 UTC

Re: selectOneMenu issue

I was just saying there is someone out there who would think how lucky I was that my 
action was called at all.

Try setting columns="2" on the panelGrid.

--
Rob

@objectsource.org


---------- Original Message -----------
From: Whitney Hunter <wh...@hunterfam.com>
To: MyFaces Discussion <my...@incubator.apache.org>
Sent: Fri, 22 Apr 2005 12:29:33 -0700
Subject: selectOneMenu issue

> Hi all,
> 
> I am having a difficult time getting <h:selectOneMneu> to workwith a 
> converter. I have a very simple jsp that presents a menu and hasa submit 
> button. The problem is that the submit() method on controllerclass is never 
> called when the selectOneMenu control is on the page. IfI remove this control 
> it works. I am getting the same behavior withmyfaces and the reference 
> implementation so I expect that I am missingsomething. Can anyone point me in 
> the right direction?
> 
> Thanks a lot,
> Whitney
> 
> Here is my jsp code:
> 
>  <f:view>
> <h:form>
> <h:panelGrid columns="1">
> <h:selectOneMenu value="#{controller.modelObject}"
> converter="converter">
> <f:selectItemsvalue="#{controller.modelObjectSelectItems}" />
> </h:selectOneMenu>
> <h:commandButton value="submit"
> actionListener="#{controller.submit}" />
> </h:panelGrid>
> </h:form>
> </f:view>
> 
> RIController.java
> 
>  private static List modelObjects = new ArrayList();
> 
> private RIModelObject modelObject;
> 
> static {
> modelObjects.add(new RIModelObject("one"));
> modelObjects.add(new RIModelObject("two"));
> modelObjects.add(new RIModelObject("three"));
> }
> 
> public void submit(ActionEvent event) {
> System.out.println("Object: " + modelObject.getValue());
> }
> 
> public List getModelObjectSelectItems() {
> List selectItems = new ArrayList();
> 
> Iterator iter = modelObjects.iterator();
> while (iter.hasNext()) {
> RIModelObject modelObject = (RIModelObject) iter.next();
> selectItems
> .add(new SelectItem(modelObject,modelObject.getValue()));
> }
> 
> return selectItems;
> }
> 
> public RIModelObject getModelObject() {
> return modelObject;
> }
> 
> public void setModelObject(RIModelObject modelObject) {
> this.modelObject = modelObject;
> }
> 
> RIConverter.java
> 
>  public Object getAsObject(FacesContext context, UIComponentcomponent,
> String value) throws ConverterException {
> if (value == null) {
> return null;
> }
> 
> return new RIModelObject(value);
> }
> 
> public String getAsString(FacesContext context, UIComponentcomponent,
> Object value) throws ConverterException {
> if (value == null) {
> return null;
> }
> 
> if (value instanceof RIModelObject) {
> return ((RIModelObject) value).getValue();
> } else {
> throw new ConverterException("Incorrect type");
> }
> }
> 
> RIModelObject.java
> 
>  private String value;
> 
> public RIModelObject(String value) {
> this.value = value;
> }
> 
> public String getValue() {
> return value;
> }
> 
> public void setValue(String value) {
> this.value = value;
> }
------- End of Original Message -------


Re[2]: selectOneMenu issue

Posted by Paul Gonchar <pg...@nighterra.com>.
Nope, there is no any default validators. You may check it out by
calling getValidators method on the component instance. The only
instance I've seen was my own validator that does nothing.
I had the same problem before with selectOne component. And it was
very hard to find the reason :-(
 The problem is that JSF wants to make sure that selected items (beans
actually) are members of collection returned by f:selectItems tag. I'm
not sure if this is really necessary but anyways, after conversion of
the bean value JSF will call equals on every element of the collection
and the converted value. Usually, converter returns a new object so
default implementation of equals method will always return false. JSF
supposes that the converted bean is not a member of the list and
displays that "Value is not valid" message. The simplest way to fix
this is to override equals method of bean class, which is used in listbox.

I've got selectOne working fine but I still can't get selectMany working
with converter :(( I posted a message here but no one seems to know
the answer. And I couldn't find any examples of this thing working.
Has any one ever seen selectMany component working with converter on
Sun's or Apache's implementation of JSF?

Paul.



RD> I don't know of the top of my head what the default is for validation. There seems to 
RD> be some default validator that doesn't like your object though.

RD> --
RD> Rob

RD> @objectsource.org


RD> ---------- Original Message -----------
RD> From: Whitney Hunter <wh...@hunterfam.com>
RD> To: MyFaces Discussion <us...@myfaces.apache.org>
RD> Sent: Fri, 22 Apr 2005 13:26:06 -0700
RD> Subject: Re: selectOneMenu issue

>> That was a good idea. I get this error: Validation Error: Value isnot valid. 
>> But it is not clear to me why I am getting this.
>> 
>> Rob Decker wrote:Maybe you're getting a conversion error. Put a <h:messages> 
>> in the page to see if you get an error.
>> 
>> --
>> Rob
>> 
>> @objectsource.org
>> 
>> ---------- Original Message -----------
>> From: Whitney Hunter <wh...@hunterfam.com>
>> To: MyFaces Discussion <us...@myfaces.apache.org>
>> Sent: Fri, 22 Apr 2005 12:59:22 -0700
>> Subject: Re: selectOneMenu issue
>> 
>> That has no effect other than placing the button next to the menuinstead of 
>> below it. The actionListener is still not called.
>> 
>> Rob Decker wrote:I was just saying there is someone out there who would think 
>> how lucky I was that my action was called at all.
>> 
>> Try setting columns="2" on the panelGrid.
>> 
>> --
>> Rob
>> 
>> @objectsource.org
>> 
>> ---------- Original Message -----------
>> From: Whitney Hunter <wh...@hunterfam.com>
>> To: MyFaces Discussion <my...@incubator.apache.org>
>> Sent: Fri, 22 Apr 2005 12:29:33 -0700
>> Subject: selectOneMenu issue
>> 
>> Hi all,
>> 
>> I am having a difficult time getting <h:selectOneMneu> to workwith a 
>> converter. I have a very simple jsp that presents a menu and hasa submit 
>> button. The problem is that the submit() method on controllerclass is never 
>> called when the selectOneMenu control is on the page. IfI remove this control 
>> it works. I am getting the same behavior withmyfaces and the reference 
>> implementation so I expect that I am missingsomething. Can anyone point me in 
>> the right direction?
>> 
>> Thanks a lot,
>> Whitney
>> 
>> Here is my jsp code:
>> 
>> <f:view>
>> <h:form>
>> <h:panelGrid columns="1">
>> <h:selectOneMenu value="#{controller.modelObject}"
>> converter="converter">
>> <f:selectItemsvalue="#{controller.modelObjectSelectItems}" />
>> </h:selectOneMenu>
>> <h:commandButton value="submit"
>> actionListener="#{controller.submit}" />
>> </h:panelGrid>
>> </h:form>
>> </f:view>
>> 
>> RIController.java
>> 
>> private static List modelObjects = new ArrayList();
>> 
>> private RIModelObject modelObject;
>> 
>> static {
>> modelObjects.add(new RIModelObject("one"));
>> modelObjects.add(new RIModelObject("two"));
>> modelObjects.add(new RIModelObject("three"));
>> }
>> 
>> public void submit(ActionEvent event) {
>> System.out.println("Object: " + modelObject.getValue());
>> }
>> 
>> public List getModelObjectSelectItems() {
>> List selectItems = new ArrayList();
>> 
>> Iterator iter = modelObjects.iterator();
>> while (iter.hasNext()) {
>> RIModelObject modelObject = (RIModelObject) iter.next();
>> selectItems
>> .add(new SelectItem(modelObject,modelObject.getValue()));
>> }
>> 
>> return selectItems;
>> }
>> 
>> public RIModelObject getModelObject() {
>> return modelObject;
>> }
>> 
>> public void setModelObject(RIModelObject modelObject) {
>> this.modelObject = modelObject;
>> }
>> 
>> RIConverter.java
>> 
>> public Object getAsObject(FacesContext context, UIComponentcomponent,
>> String value) throws ConverterException {
>> if (value == null) {
>> return null;
>> }
>> 
>> return new RIModelObject(value);
>> }
>> 
>> public String getAsString(FacesContext context, UIComponentcomponent,
>> Object value) throws ConverterException {
>> if (value == null) {
>> return null;
>> }
>> 
>> if (value instanceof RIModelObject) {
>> return ((RIModelObject) value).getValue();
>> } else {
>> throw new ConverterException("Incorrect type");
>> }
>> }
>> 
>> RIModelObject.java
>> 
>> private String value;
>> 
>> public RIModelObject(String value) {
>> this.value = value;
>> }
>> 
>> public String getValue() {
>> return value;
>> }
>> 
>> public void setValue(String value) {
>> this.value = value;
>> }
>> ------- End of Original Message -------
>> ------- End of Original Message -------
RD> ------- End of Original Message -------


Re: selectOneMenu issue

Posted by Rob Decker <ro...@objectsource.org>.
I don't know of the top of my head what the default is for validation. There seems to 
be some default validator that doesn't like your object though.

--
Rob

@objectsource.org


---------- Original Message -----------
From: Whitney Hunter <wh...@hunterfam.com>
To: MyFaces Discussion <us...@myfaces.apache.org>
Sent: Fri, 22 Apr 2005 13:26:06 -0700
Subject: Re: selectOneMenu issue

> That was a good idea. I get this error: Validation Error: Value isnot valid. 
> But it is not clear to me why I am getting this.
> 
> Rob Decker wrote:Maybe you're getting a conversion error. Put a <h:messages> 
> in the page to see if you get an error.
> 
> --
> Rob
> 
> @objectsource.org
> 
> ---------- Original Message -----------
> From: Whitney Hunter <wh...@hunterfam.com>
> To: MyFaces Discussion <us...@myfaces.apache.org>
> Sent: Fri, 22 Apr 2005 12:59:22 -0700
> Subject: Re: selectOneMenu issue
> 
> That has no effect other than placing the button next to the menuinstead of 
> below it. The actionListener is still not called.
> 
> Rob Decker wrote:I was just saying there is someone out there who would think 
> how lucky I was that my action was called at all.
> 
> Try setting columns="2" on the panelGrid.
> 
> --
> Rob
> 
> @objectsource.org
> 
> ---------- Original Message -----------
> From: Whitney Hunter <wh...@hunterfam.com>
> To: MyFaces Discussion <my...@incubator.apache.org>
> Sent: Fri, 22 Apr 2005 12:29:33 -0700
> Subject: selectOneMenu issue
> 
> Hi all,
> 
> I am having a difficult time getting <h:selectOneMneu> to workwith a 
> converter. I have a very simple jsp that presents a menu and hasa submit 
> button. The problem is that the submit() method on controllerclass is never 
> called when the selectOneMenu control is on the page. IfI remove this control 
> it works. I am getting the same behavior withmyfaces and the reference 
> implementation so I expect that I am missingsomething. Can anyone point me in 
> the right direction?
> 
> Thanks a lot,
> Whitney
> 
> Here is my jsp code:
> 
> <f:view>
> <h:form>
> <h:panelGrid columns="1">
> <h:selectOneMenu value="#{controller.modelObject}"
> converter="converter">
> <f:selectItemsvalue="#{controller.modelObjectSelectItems}" />
> </h:selectOneMenu>
> <h:commandButton value="submit"
> actionListener="#{controller.submit}" />
> </h:panelGrid>
> </h:form>
> </f:view>
> 
> RIController.java
> 
> private static List modelObjects = new ArrayList();
> 
> private RIModelObject modelObject;
> 
> static {
> modelObjects.add(new RIModelObject("one"));
> modelObjects.add(new RIModelObject("two"));
> modelObjects.add(new RIModelObject("three"));
> }
> 
> public void submit(ActionEvent event) {
> System.out.println("Object: " + modelObject.getValue());
> }
> 
> public List getModelObjectSelectItems() {
> List selectItems = new ArrayList();
> 
> Iterator iter = modelObjects.iterator();
> while (iter.hasNext()) {
> RIModelObject modelObject = (RIModelObject) iter.next();
> selectItems
> .add(new SelectItem(modelObject,modelObject.getValue()));
> }
> 
> return selectItems;
> }
> 
> public RIModelObject getModelObject() {
> return modelObject;
> }
> 
> public void setModelObject(RIModelObject modelObject) {
> this.modelObject = modelObject;
> }
> 
> RIConverter.java
> 
> public Object getAsObject(FacesContext context, UIComponentcomponent,
> String value) throws ConverterException {
> if (value == null) {
> return null;
> }
> 
> return new RIModelObject(value);
> }
> 
> public String getAsString(FacesContext context, UIComponentcomponent,
> Object value) throws ConverterException {
> if (value == null) {
> return null;
> }
> 
> if (value instanceof RIModelObject) {
> return ((RIModelObject) value).getValue();
> } else {
> throw new ConverterException("Incorrect type");
> }
> }
> 
> RIModelObject.java
> 
> private String value;
> 
> public RIModelObject(String value) {
> this.value = value;
> }
> 
> public String getValue() {
> return value;
> }
> 
> public void setValue(String value) {
> this.value = value;
> }
> ------- End of Original Message -------
> ------- End of Original Message -------
------- End of Original Message -------


Re: selectOneMenu issue

Posted by Rob Decker <ro...@objectsource.org>.
Maybe you're getting a conversion error. Put a <h:messages> in the page to see if you 
get an error.

--
Rob

@objectsource.org


---------- Original Message -----------
From: Whitney Hunter <wh...@hunterfam.com>
To: MyFaces Discussion <us...@myfaces.apache.org>
Sent: Fri, 22 Apr 2005 12:59:22 -0700
Subject: Re: selectOneMenu issue

> That has no effect other than placing the button next to the menuinstead of 
> below it. The actionListener is still not called.
> 
> Rob Decker wrote:I was just saying there is someone out there who would think 
> how lucky I was that my action was called at all.
> 
> Try setting columns="2" on the panelGrid.
> 
> --
> Rob
> 
> @objectsource.org
> 
> ---------- Original Message -----------
> From: Whitney Hunter <wh...@hunterfam.com>
> To: MyFaces Discussion <my...@incubator.apache.org>
> Sent: Fri, 22 Apr 2005 12:29:33 -0700
> Subject: selectOneMenu issue
> 
> Hi all,
> 
> I am having a difficult time getting <h:selectOneMneu> to workwith a 
> converter. I have a very simple jsp that presents a menu and hasa submit 
> button. The problem is that the submit() method on controllerclass is never 
> called when the selectOneMenu control is on the page. IfI remove this control 
> it works. I am getting the same behavior withmyfaces and the reference 
> implementation so I expect that I am missingsomething. Can anyone point me in 
> the right direction?
> 
> Thanks a lot,
> Whitney
> 
> Here is my jsp code:
> 
> <f:view>
> <h:form>
> <h:panelGrid columns="1">
> <h:selectOneMenu value="#{controller.modelObject}"
> converter="converter">
> <f:selectItemsvalue="#{controller.modelObjectSelectItems}" />
> </h:selectOneMenu>
> <h:commandButton value="submit"
> actionListener="#{controller.submit}" />
> </h:panelGrid>
> </h:form>
> </f:view>
> 
> RIController.java
> 
> private static List modelObjects = new ArrayList();
> 
> private RIModelObject modelObject;
> 
> static {
> modelObjects.add(new RIModelObject("one"));
> modelObjects.add(new RIModelObject("two"));
> modelObjects.add(new RIModelObject("three"));
> }
> 
> public void submit(ActionEvent event) {
> System.out.println("Object: " + modelObject.getValue());
> }
> 
> public List getModelObjectSelectItems() {
> List selectItems = new ArrayList();
> 
> Iterator iter = modelObjects.iterator();
> while (iter.hasNext()) {
> RIModelObject modelObject = (RIModelObject) iter.next();
> selectItems
> .add(new SelectItem(modelObject,modelObject.getValue()));
> }
> 
> return selectItems;
> }
> 
> public RIModelObject getModelObject() {
> return modelObject;
> }
> 
> public void setModelObject(RIModelObject modelObject) {
> this.modelObject = modelObject;
> }
> 
> RIConverter.java
> 
> public Object getAsObject(FacesContext context, UIComponentcomponent,
> String value) throws ConverterException {
> if (value == null) {
> return null;
> }
> 
> return new RIModelObject(value);
> }
> 
> public String getAsString(FacesContext context, UIComponentcomponent,
> Object value) throws ConverterException {
> if (value == null) {
> return null;
> }
> 
> if (value instanceof RIModelObject) {
> return ((RIModelObject) value).getValue();
> } else {
> throw new ConverterException("Incorrect type");
> }
> }
> 
> RIModelObject.java
> 
> private String value;
> 
> public RIModelObject(String value) {
> this.value = value;
> }
> 
> public String getValue() {
> return value;
> }
> 
> public void setValue(String value) {
> this.value = value;
> }
> ------- End of Original Message -------
------- End of Original Message -------