File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes selectManyCheckbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "selectManyCheckbox" Watch "selectManyCheckbox" New topic
Author

selectManyCheckbox

Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Hi,

I have 3 tabbed panes.

In the 3rd tab pane I need to create dynamic selectManyCheckbox with input text in a button click. I couldn't work it out. What I am trying to get it is, when I click the 'Add' button it shoul show one check box with an input text box.

Here, when I click Add button not only it doesn't show anything but also the control goes to the first tab .

Here is my code :





bean:



I am not sure about rendering components.

Appreciate any thoughts.

Thanks,
Joe.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Basically it looks like as follows:

JSF

MyBean
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Thanks for the reply.

I have tried that. But checkbox is still not coming .Eventhough one text box is coming once i press Add button, second time it fails showing the error 'duplicate component id'. Do I need to add UISelectItem for checkbox and text box ? How can I do that ? Please can you give me some more clear view ?

Thanks,
Joe.
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Originally posted by Bauke Scholtz:
Basically it looks like as follows:

JSF

MyBean


Can you please give me more clear view ? I got one input text but not any checkboxes . If I press the command button 2 times, it gives 'duplicate id' error. Could any one please help me .

Thanks,
Joe.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Originally posted by Joe Jose:

Can you please give me more clear view ? I got one input text but not any checkboxes .
You have to add selectitems to the checkbox, otherwise it will be empty indeed.
If I press the command button 2 times, it gives 'duplicate id' error.
Or you're doing something wrong (first try not to set the ID, JSF will do it all for you), or you need a JSF version upgrade.
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Thankyou very much for the reply Bauke.

As you said, I cancelled setting id and now tried to set selectItem value to check box. Please have a look into my code :



Please can you spot where I am going wrong ?

Thanks,
Joe.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I was thinking about it .. You better can use DTO's to hold data in it for UIInput components.

JSF

MyBeanMyBean should be session scoped to keep the new added items in the session. If you really want to use the request scope, then use Map FacesContext.getCurrentInstance().getExternalContext().getSessionMap() instead to store and retrieve the List items.
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Thank you very much for the reply.Thank you for your time for think about it.

I wll try it. In between I was trying another method without using checkbox. I was enering stings seperated by coma and adding it to a selectmanylistbox. But the list box behaves strangely. When I select an item from the list box and press the button, it gives exception'NoSuchElementException'. I am not sure where am going wrong. I fed up with JSF.

Here is my code :

jsp:


mybean:



If I don't select an item from the list, the remove button works fine and it removes all items !

Please let me know your thoughts on it.

Thanks,
Joe.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Please make you familair with Collections ..

I tried to understand your code and I guess this is what you want.

JSFMyBean
[ October 11, 2006: Message edited by: Bauke Scholtz ]
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Thanks Bauke. Very thoughtful of you for finding time to spare for me.

I tried your seconf solution. But didn't work out. I don't understand why it fails when select an item from the selectManyListbox ? !

It gives an exception :

java.util.NoSuchElementException
at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:96)
at javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:122)
at javax.faces.component.UISelectMany.matchValue(UISelectMany.java:401)
at javax.faces.component.UISelectMany.validateValue(UISelectMany.java:370)
at javax.faces.component.UIInput.validate(UIInput.java:634)
at javax.faces.component.UIInput.executeValidate(UIInput.java:838)
at javax.faces.component.UIInput.processValidators(UIInput.java:412)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:904)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:904)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:904)
at javax.faces.component.UIForm.processValidators(UIForm.java:170)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:904)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:342)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:78)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:595)

I have had worked well with selecy many list box before. But now it behaves strangely. Would appreciate any explanation for this .

Time is running off ,it time to finish with this. I don't know what I have to do.

Thank you very much for your cooperation.

Thanks,
Joe.
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
ohhh the code works when I put the backbean in session scope. Please any one can explain the logic behind that ?

But I don't want all the bean items into session scope. Is there any other method ?

Thanks,
Joe.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Use component bindings or use context.getExternalContext().getSessionMap().
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
Here's an interesting tutorial on some of the JSF taglibs.

http://www.exadel.com/tutorial/jsf/jsftags-guide.html

Hope it helps!


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Very thoughtful of you both Bauke and Paul.

Bauke, I need to try your 2 more solutions.

I don't know how to thank you enough. Very kind enough.

But I think I need to be here until I complete with my first project with jsf since I am running out of time.

Anyway thank you all.

Joe.
fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
I am rendering HtmlSelectManyCheckbox from server side at runtime. This renders the checkbox onto the UI.
But i am not able to retrieve the values of the rendered checkboxes on the server side on submitting.
I think, my value binding is not right.

How do i do that?
Please provide some server side code to accomplish the same.
fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
I am rendering HtmlSelectManyCheckbox from server side at runtime. This renders the checkbox onto the UI.
But i am not able to retrieve the values of the rendered checkboxes on the server side on submitting.
I think, my value binding is not right.

How do i do that?
Please provide some server side code to accomplish the same.
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Please have a look at Bauke's code in this post.

Regards,
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
Joe,

I saw that you also had a problem that the control is going back to the first tab.
In my project where MyFaces is used, I resolved it using the 'selectedIndex' attribute of t:panelTabbedPane. I bound it to a backing bean property and setting the property whenever the tab changes. Hope this will give you some idea.
Joe Jose
Ranch Hand

Joined: Jan 14, 2004
Posts: 125
Yes.Thank you very much Dusi. I need to try out it on Monday. Can you give me some code samples , that will be a great help for me .

Thanks,
Joe.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: selectManyCheckbox
 
Similar Threads
selectManyCheckBox within a panelgrid?
horizontal alignment
css
Action Event
ClassCastException