File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selectManyCheckbox

 
Joe Jose
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically it looks like as follows:

JSF

MyBean
 
Joe Jose
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use component bindings or use context.getExternalContext().getSessionMap().
 
Paul Michael
Ranch Hand
Posts: 697
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an interesting tutorial on some of the JSF taglibs.

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

Hope it helps!
 
Joe Jose
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at Bauke's code in this post.

Regards,
 
A. Dusi
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic