• Post Reply Bookmark Topic Watch Topic
  • New Topic

Live updating selectOneMenu

 
Karolis Kalanta
Greenhorn
Posts: 7
Android Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey code farmer, I have a dropDownList a.k.a. selectOneMenu and the user can add values to it. My problem is that it updates only when two values are added and only the pre-last value shows up. f.e. if you add "test" nothing shows up... if you add "test2", then "test" will show up on the list... if you add "test3", then "test2" will show up on the list and so on and so forth. What my problem is I need to figure it out how to add a value and show it on the list right away. Waiting for suggestions !

---HTML code---



---Java code---

 
Karolis Kalanta
Greenhorn
Posts: 7
Android Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Common cowboys..
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have some very basic misconceptions here.

This expression:



Is expecting to obtain a String from the "getComponents" backing bean. That String would be JavaScript text. Your getAllComponents() method returns void. And last, but not least, the "onsubmit" attribute value must contain a "return" statement indicating whether the submit is to be processed (true) or suppressed (false).

Beyond that, since this is a property EL expression, the proper coding of it would have been "onsubmit="#{getComponents.allComponents}", as the "get" and "set" is implicit in a property reference.

And, incidentally, JSF isn't HTML, so if you think that "onsubmit" is how you call the backing bean action method, you need to go back and read the JSF book very carefully.

Likewise, action="#{addComponents.addProcessor()}" is bad practice, because - again - you're not supposed to be coding logic, you're supposed to be coding a logic reference, so the proper syntax is as follows:


Beyond such basic stuff as that, I'd recommend trying to get things working right without the dialog wrapping it first. Dialogs are tricky in JSF, because they're not OS-style dialogs, they're JavaScript magic that show and hide stuff that's an actual part of the web page (not a separate pop-up window).
 
Karolis Kalanta
Greenhorn
Posts: 7
Android Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,

Regarding the form, I need it to load the method when a request is sent so i guessed onsubmit was the most logical option.
The point of this for it to be in a dialog box, so I can't really put it outside of it.

What would be your alternative suggestions?
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"onsubmit" is a javascript attribute corresponding the the HTML FORM onsubmit javascript attribute. It does not execute any Java code on the server, only Javascript code on the client.

As I mentioned, JSF dialog boxes are not OS-level dialog boxes. In essence, they are overlay HTML DIV elements that can be displayed or hidden over the top of the rest of the HTML page. It's all done in Javascript, no server-side code is involved and no separate dialog window pops open.

The Primefaces Dialog control has to be paired with a JSF h:form control, I forget which one has to contain the other, but it's in the documentation. The dialog JSF form works like any other JSF h:form in that in order to submit the form, and thereby trigger a JSF action method, you have to either use a JSF command control (h:commandButton, h:commandLink) or use AJAX. For command controls, the 'action=' attribute defines a reference to a backing bean method. NOT a method call. JSF does the actual method call, not the form. Thus: 'action="#{myBean.loadComponents}"', which would cause the backing bean's "public String loadComponents()" method to be invoked when the button or link was clicked.

AJAX operation is similar, except that instead of specifying a "public String method()" action method, you specify a reference to an AJAXListener method, whose signature is something like "public void myListener(AjaxEvent event)".

A full form submit (commandButton/commandLink) causes the entire form's input control values to be sent to the server, and if they are valid, the backing bean updates their corresponding properties, the action method is invoked, and then JSF navigates to whatever page the action method returns a reference to. Which, if it's null, would be the same page. Or, if the action is "immediate", the property validation and updating is skipped and the action method is invoked directly.

An AJAX submit is essentially the same process except that you can limit what input values from the form will be submitted and instead of rendering a fresh copy of the page, you can indicate that only selected parts of the current page should be updated.

Finally, note that when you display a primefaces dialog, all that's actually happening is that Javascript is making an existing DIV visible. The contents of that displayed DIV - including its control values - will be whatever they were when the page was initially displayed unless you have some sort of JavaScript or AJAX logic that updates them,
 
Karolis Kalanta
Greenhorn
Posts: 7
Android Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:"onsubmit" is a javascript attribute corresponding the the HTML FORM onsubmit javascript attribute. It does not execute any Java code on the server, only Javascript code on the client.

As I mentioned, JSF dialog boxes are not OS-level dialog boxes. In essence, they are overlay HTML DIV elements that can be displayed or hidden over the top of the rest of the HTML page. It's all done in Javascript, no server-side code is involved and no separate dialog window pops open.

The Primefaces Dialog control has to be paired with a JSF h:form control, I forget which one has to contain the other, but it's in the documentation. The dialog JSF form works like any other JSF h:form in that in order to submit the form, and thereby trigger a JSF action method, you have to either use a JSF command control (h:commandButton, h:commandLink) or use AJAX. For command controls, the 'action=' attribute defines a reference to a backing bean method. NOT a method call. JSF does the actual method call, not the form. Thus: 'action="#{myBean.loadComponents}"', which would cause the backing bean's "public String loadComponents()" method to be invoked when the button or link was clicked.

AJAX operation is similar, except that instead of specifying a "public String method()" action method, you specify a reference to an AJAXListener method, whose signature is something like "public void myListener(AjaxEvent event)".

A full form submit (commandButton/commandLink) causes the entire form's input control values to be sent to the server, and if they are valid, the backing bean updates their corresponding properties, the action method is invoked, and then JSF navigates to whatever page the action method returns a reference to. Which, if it's null, would be the same page. Or, if the action is "immediate", the property validation and updating is skipped and the action method is invoked directly.

An AJAX submit is essentially the same process except that you can limit what input values from the form will be submitted and instead of rendering a fresh copy of the page, you can indicate that only selected parts of the current page should be updated.

Finally, note that when you display a primefaces dialog, all that's actually happening is that Javascript is making an existing DIV visible. The contents of that displayed DIV - including its control values - will be whatever they were when the page was initially displayed unless you have some sort of JavaScript or AJAX logic that updates them,


Well that's what I'm trying to use, running ajax event to update the list, but from your answer I understood that I need a function in js to do that, since ajax is working only half way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!