Skip to main content

combobox selected attribute removed?

8 replies [Last post]
charliet
Offline
Joined: 2007-10-23
Points: 0

I am using Netbeans 5.5 with Visual Web Pack. I've installed the JMaki plugin,
placed a combobox widget on a page and used the "value" attribute of the tag to
load the list data from a session bean. So far, so good.

Now I want to use the "selected" attribute to get the currently selected item
from the session bean. I've used the pattern I've seen in various
JMaki documentation -- such as
"Using JMaki Widgets as JavaServer Faces Components" -- to create the tag:

The "value" attribute works fine for me. However, when I add the
"selected" attribute I get an error message indicating the "selected"
attribute is not valid for a combobox. Looking at some recent forum
answers/blog entries it looks like the "selected" attribute has indeed
been removed from the JMaki 1.0. So, how do I bind the combobox
currently selected item to the "SessionBean1" session bean?

Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rasane
Offline
Joined: 2007-08-15
Points: 0

Hi Charlie,

I understand that beans integration with jMaki widgets is to the extent of "first time load" only. If you want client side updates from user to update a server side value
- you have a form submit
OR
- use jmaki.doAjax to send ajax update

On the client browser though, if you are interested in finding out the currently selected value, so that you could call jmaki.doAjax with an update, then use glue to listen for 'onSelect', which has target ID and value in its payload.
I cannot see a object.selected function in combobox's component.js file, but I see a object.getValue() function.

I would be happy to hear otherwise.

Regards,
rasane

Message was edited by: rasane

mediii
Offline
Joined: 2007-09-03
Points: 0

hello,

i'm working with the jmaki widget and i have the same problem like combobox, i think the jmaki event listener tag is a good approch, so i am working with the sample-app from this page https://ajax.dev.java.net/jmakieventlistenertag.html and i can't find the source code on the cvs (under the tag/branch: 'dev1dot1').

i need particulary the java class MyJMakiEventListenerBean.java someone can help me please ?

Message was edited by: mediii

a_laksmana
Offline
Joined: 2007-11-01
Points: 0

I think the listener it's not available in the distributed jmaki packs yet.

What you could do is to make use the doAjax like rasane recommended.

in your glue.js

// map topics
jmaki.subscribe("/config/team/addteam/onClick", function(args) {
jmaki.log("glue.js : onSelect request from: " + args.widgetId);
//get current fields
var idname = document.getElementById("page_user_accountid").value;
var team = document.getElementById("page_user_accounttype").value;
//execute bean method to add the team
jmaki.doAjax({
method : "POST",
url : jmaki.webRoot + "/faces/YourManagedBean-method.ajax",
content : { cmd : 'addteam', teamid : idname, teamname : team},
callback : function(req){
jmaki.log("returned response is = " + req.responseText);
var restext = req.responseText;
var res = eval("(" + restext + ")");
//update status message
document.getElementById("page_team_status").innerHTML = res.message;
//refresh table
jmaki.publish("/config/team/applyfilter/onClick", args);
document.getElementById("page_user_accountid").value = "";
document.getElementById("page_user_accounttype").value = "";
},
onerror : function(m){
jmaki.log("Error setting filter value.");
}
});
});

in your managed bean "YourManagedBean":

public void method(FacesContext context, AjaxResult result){
HttpServletRequest req = (HttpServletRequest)this.getExternalContext().getRequest();
//get command
String command = req.getParameter("cmd");
result.setResponseType(AjaxResult.JSON);
if("addteam".equals(command)){
this.filterTeamname = req.getParameter("teamname");

//System.out.println("The value of filter = " + this.filterTeamname);
//further implementation
}
else{
result.append("{message:'fail'}");
}
}

charliet
Offline
Joined: 2007-10-23
Points: 0

Hi,

Anyone able to answer my question? Just to make it clear -- various JMaki
documentation and blogs use this example combobox tag:

selected="#{ComboBoxBean.country}"
value="#{ComboBoxBean.completeCountry}"/>

I've based my tag on this pattern. The "value" attribute works fine for
me. My session bean method puts out a JSON formatted list of items
and the combobox looks and works as expected. However, when I
try to use the "selected" attribute to bind the user-selected item to my
session bean (using a simple getter/setter method in the bean) I get
a message from Netbeans saying "Attribute selected invalid for tag
widget according to TLD". Apparently the "selected" attribute is no
longer supported for the combobox tag. Is that correct? If so, how
do I bind the user-selected value to my session bean?

If my question is still not clear please let me know.

Thanks,
Charlie

rasane
Offline
Joined: 2007-08-15
Points: 0

Hi Charlie,

Looking at the jMaki data model for Combo box: http://wiki.java.net/bin/view/Projects/jMakiComboxModel, the intended JSON structure for value contains the selected element:
[
{ label : 'Alabama', value : 'AL'},
{ label : 'California', value : 'CA'},
{ label : 'New York', value : 'NY', selected : true},
{ label : 'Texas', value : 'TX'} ^^^^^^^^^^^^^^^^
]

Hope that helps.

Regards,
rasane

charliet
Offline
Joined: 2007-10-23
Points: 0

Hi Rasane,

Thank you for responding. However, as far as I understand it, the "selected"
element in the JSON structure sets the default selected item when the combobox
is first rendered on the page. What I'm trying to bind to my session bean is
the item that the user has currently selected after interacting with the combobox.

At one time, according to various JMaki docs, the currently selected item was
available via the "selected" attribute of the tag. But the "selected" attribute is no
longer supported. So, my question is, what do I use in my tag so that the user's
selected item is bound to my session bean?

I hope that makes sense. Again, thank you for responding.

Charlie

charliet
Offline
Joined: 2007-10-23
Points: 0

Hi,

Could someone involved with jMaki development please respond to my questions:

Was the "selected" attribute intentionally dropped from the combox tag?

If so, how do I bind the user's currently selected item to my session bean?

It seems to me they are pretty straightforward questions. If not, please
let me know the error of my ways. I really do appreciate all the time and
effort folks have put into jMaki -- and I'd love to use it -- but I can't unless
I can get beyond this little problem.

Thanks in advance,
Charlie

ntruchsess
Offline
Joined: 2007-01-05
Points: 0

to answer your question: the selected attribute is intentionally dropped, since the widget-tag is meant to be generic and not specialized on a specific use-case. Furthermore the client-side architecture has evolved to transfer everything via the publish/subscribe message bus, which doesn't fit into the picture of widgets posting their 'selected' state directly to the server, but just fire of a (client-side) message whenever the selection-state changes.

Have a look on https://ajax.dev.java.net/jmakieventlistenertag.html to see how to receive such message on the server in your menaged bean. On this page you find download-link to a sample-app that demonstrates the complete roundtrip. You will have to use the jMaki build included in this app to make use of this technique.

Unfortunally we didn't manage to include this into jMaki 1.0 (because we only have implemented it for jsf 1.2 yet), but it will be part of the next major release.

Currently (as of jMaki 1.0) the only thing you can directly bind to a managed bean is the 'value' of the widget-tag. Be aware that this binding is using plain jsf techniques - it is executed whenever there is a form on the page enclosing the widget (that writes its value to a hidden field) and this form is submitted to the server where it is processed using the regular jsf lifecycle (regular page reload - no ajax).

To do ajax-style communication with the server in jMaki 1.0 you would have to write an subscribe-handler that receives the 'selected' message and forwards it to the server. (which is, what the eventlistener-mechanism described above does under the covers)