Retrieve GWT radiobutton value in servlet - java

I'm having a headache figuring how to retrieve the gwt Radio Buttons values in the server side.
Here is my UiBinder form:
<g:FormPanel ui:field="form"><g:VerticalPanel ui:field="fruitPanel">
<g:RadioButton name="fruit">apple</g:RadioButton>
<g:RadioButton name="fruit">banana</g:RadioButton>
<g:SubmitButton>Submit</g:SubmitButton> ...
Here is how i initialize the form:
form.setAction("/submit");
form.setMethod(FormPanel.METHOD_POST);
So i though i would have to do this on the servlet:
fruit = req.getParameter("fruit")
But of course this doesn't work, parameter fruit doesn't exist :/
Edit: Ok i get parameter fruit but it's always "on"
I also did try to add the radio button in java with:
RadioButton rb0 = new RadioButton("fruit", "apple");
RadioButton rb1 = new RadioButton("fruit", "banana");
fruitPanel.add(rb0);
fruitPanel.add(rb1);
Edit: This is a GWT issue: Issue 4795

since I cannot comment on the question: Which version of GWT are you using?
I've create the exact same template as you did and Firebug tells me that it's posting:
"fruit=on"
Of course this payload is only posted when one of the checkboxes is checked. ;-)
But beware: I've recognized recently that GWT doesn't set the "value" of the radio button when used inside UiBinder template and instead just sends "on" as value which makes the radio button more or less useless to be used in a UiBinder template.
HTH
Max

NO, no, no, no. This is not JSP, buddy!
Seems to me that you have a lot of documentation reading to do about how GWT works. This I cannot make clear in one answer post, but to start somewhere:
1) You are not running your code on the server, this is client side!
2) You should use GWT RPC to transfer data to/from the server
3) RTFM :)

Related

Read external Files with GlassFish / Vaadin?

I would like to make .txt-files accessible for my VaadinApp on a GlassfishServer.
Lets say I have a .txt-file, its content is 12345.
Now, when I click a button on my Vaadin StartPage, I would like to show the Data that has been written into this .txt-file.
I know how Java Input/Output is working but I have no clue how to make those files accessible for my VaadinApplication running on Glassfish 4.1.2.
Is there a folder I can put the .txt-file in, or how would I access the file?
Thanks
There is component named Label is available in Vaadin.
So that, the values which needs to be shown on the screen can be set as a caption/value for that object.
This can be done either through constructor or setter in that object.We will set the value through the setter as we need to display the value, once the button is clicked. That can be done like this.
Label sampleLabel = new Label();
sampleLabel.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
Now we will see how this can be added to the label, when a button is clicked.
Button sampleButton = new Button("Click");
sampleButton.addClickListener(event -> sampleLabel.setValue(<call the method that reads data from the text file>));
I hope this will be helpful.
Note: Basically you can place the file anywhere in the system.
But most preferred way.
If you are using maven to build the project, place the files in the resource folder.(src/main/resources)

replacing Result's html

I have an URL which shows me a coupon form based on id:
GET /coupon/:couponId
All the coupon forms are different and submit different POST params to:
POST /saveCoupon/:id
I want to have a convenient way of debugging my coupons and be able to have a way of viewing actual POST params submitted.
I've made a controller on URL POST /outputPOST/saveCoupon/:id which saves nothing, but prints to browser POST params received.
Now I want to have an URL like GET /changeActionUrl/coupon/:couponId which calls GET /coupon/:couponId and then substitutes form's action URL POST /saveCoupon/:id with POST /outputPOST/saveCoupon/:id .
In other words I want to do something like:
Result.getHtml().replace("/saveCoupon/","/outputPOST/saveCoupon/");
With this I can easily debug my coupons just by adding "/outputPOST" in the browser.
You could just use a bookmarklet and javascript to replace all of the forms' action attributes. That way your developer can do it with one click instead of changing urls.
Something like this will prefix all form actions on the page with "/outputPOST".
javascript:(function(){var forms=document.getElementsByTagName('FORM');for(i=0;i<forms.length;++i){forms[i].setAttribute('action','/outputPOST'+forms[i].getAttribute('action'));}})();
I don't understand, at least not everything ;)
In general you can debug every piece of Play app using debugger (check for your favorite IDE tips how to do that) - this will be always better, faster, etc etc, than modifying code only for checking incoming values.
I.e. Idea 13+ with Play support allows for debbuging like a dream!

IceFaces 1.8.2 "couldn't find container for property: bridge" on button click

I have a two simple IceFaces buttons created this way. (I don't use xhtml but create things from Java code.)
HtmlCommandButton comp = new HtmlCommandButton();
comp.setId(id);
comp.setImmediate(immediate);
boolean clientSide = props.getBooleanValue("clientside", false);
if(clientSide) {
comp.setOnclick(props.getValue("script") + ";return;");
} else {
// ignore
}
I create two buttons this way: one with clientSide == true with a simple alert('hello'); script and one would run the attached javascript server side in a BSF box.
Thw two buttons are displayed, the clientSide button works with it's alert well. However when I click on the other button that has no onClick set programmatically, I get an error message in Firebug console (in IE9 as well):
uncaught exception: couldn't find container for property: bridge
I use ICEFaces 1.8.2. After Googling around I saw this error related to jsp:root tags, but I have no jsp in my project.
The button was rendered outside of the HTML form. That's all.. :-)

jquery-mobile spinner loading

i tried to do that while js is creating a timetable... it shows spinner loading..
i tried to do this $.mobile.pageLoading(); $.mobile.pageLoading(true); and also tried to use this plugin http://contextllc.com/tools/jQuery-showLoading
The result is the same.. it shows spinner after he generate time table.. and i don't know why...here is where i tried to use it...
$('#timeDropList').change(function() {
$.mobile.pageLoading(false);
$('div.addedEntry').remove();
drawTemplate();
});
Are you using the right version of jQuery Mobile? Looks like they took away the pageLoading method in 1.0b1 in favor of two separate methods: showPageLoadingMsg and hidePageLoadingMsg. The last reference I see to pageLoading is in 1.0a4.1.
$('#home').live('pagebeforecreate',function(event){
alert('This page was just enhanced by jQuery Mobile!');
$.mobile.loadingMessage = "pagebeforeshow Page...";
$.mobile.showPageLoadingMsg();
});

selecting pulldown in htmlunit

I am using htmlunit in jython and am having trouble selecting a pull down link. The page I am going to has a table with other ajax links, and I can click on them and move around and it seems okay but I can't seem to figure out how to click on a pulldown menu that allows for more links on the page(this pulldown affects the ajax table so its not redirecting me or anything).
Here's my code:
selectField1 = page.getElementById("pageNumSelection")
options2 = selectField1.getOptions()
theOption3 = options2[4]
This gets the option I want, I verify its right. so I select it:
MoreOnPage = selectField1.setSelectedAttribute(theOption3, True)
and I am stuck here(not sure if selecting it works or not because I don't get any message, but I'm not sure what to do next. How do I refresh the page to see the larger list? When clicking on links all you have to do is find the link and then select linkNameVariable.click() into a variable and it works. but I'm not sure how to refresh a pulldown. when I try to use the webclient to create an xml page based on the the select variable, I still get the old page.
to make it a bit easier, I used htmlunit scripter and got some code that should work but its java and I'm not sure how to port it to jython. Here it is:
try
{
page = webClient.getPage( url );
HtmlSelect selectField1 = (HtmlSelect) page.getElementById("pageNumSelection");
List<HtmlOption> options2 = selectField1.getOptions();
HtmlOption theOption3 = null;
for(HtmlOption option: options2)
{
if(option.getText().equals("100") )
{
theOption3 = option;
break;
}
}
selectField1.setSelectedAttribute(theOption3, true );
Have a look at HtmlForm getSelectedByName
HtmlSelect htmlSelect = form.getSelectByName("stuff[1].type");
HtmlOption htmlOption = htmlSelect.getOption(3);
htmlOption.setSelected(true);
Be sure that WebClient.setJavaScriptEnabled is called. The documentation seems to indicate that it is on by default, but I think this is wrong.
Alternatively, you can use WebDriver, which is a framework that supports both HtmlUnit and Selenium. I personally find the syntax easier to deal with than HtmlUnit.
If I understand correctly, the selection of an option in the select box triggers an AJAX calls which, once finished, modifies some part of the page.
The problem here is that since AJAX is, by definition, asynchronous, you can't really know when the call is finished and when you may inspect the page again to find the new content.
HtmlUnit has a class named NicelyResynchronizingAjaxController, which you can pass an instance of to the WebClient's setAjaxController method. As indicated in the javadoc, using this ajax controller will automatically make the asynchronous calls coming from a direct user interaction synchronous instead of asynchronous. Once the setSelectedAttribute method is called, you'll thus be able to see the changed made to the original page.
The other option is to use WebClient's waitForBackgrounfJavascript method after the selection is done, and inspect he page once the background JavaScript has ended, or the timeout has been reached.
This isn't really an answer to the question because I've not used HtmlUnit much before, but you might want to look at Selenium, and in particular Selenium RC. With Selenium RC you are able to control the interactions with a page displayed in a native browser (Firefox for example). It has developer API's for Java and Python amongst others.
I understand that HtmlUnit uses its own javascript and web browser rendering engine and I'm wondering whether that may be a problem.

Categories