I asked a related question here
How do I programatically write parameters into the URL using GWT? I've learned from my previous question that parameters need to go before the anchor, but how do I do that from GWT?
Here's the code that doesn't work:
Hyperlink pg1 = new Hyperlink("Test", "?testing=abc#pg1");
It results in the following url:
http://localhost:8080/Athena.html#?testing=abc%23pg1
I was thinking about using Window.Location.assign(), but the javadoc says that will loose the state of my application.
The object HyperLink seems to be for linking to internal states, and probably was written so that changing its href is difficult?
I suggest you use this class http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/InlineHTML.html instead - obviously you are generating the href programatically, so it should be easy to generate the element to supply to the InlineHTML object.
You are using this constructor which receives a history token as the second constructor argument, hence you are getting said result.
Use the setHTML() method to set the correct value on the link.
Related
I am building some sort of discussion board, where you can ask questions and write answers. Now I ran into a problem with routing and seem to be understanding them wrong.
I have a homepage called index, from there you can click a button "Ask question" or another button "Write Answer". Each button leads to another webpage (askQuestion.scala.html or writeAnswer.scala.html) where you can write a question or answer. After hitting submit you come back to the index-page, where the new question or answer is put into the view. In the background, the question / answer gets put into a DB.
My routes.conf:
# Home page
GET / controllers.Application.index()
#Questions
GET /FrageStellen controllers.Application.askQuestion()
POST / controllers.Application.sendQuestion()
#Answers
GET /AntwortGeben controllers.Application.writeAnswer()
POST / controllers.Application.sendAnswer()
But when I enter an answer, it gets written into the question-table in the DB! This is due to the fact that the question-route is higher up in the routing table and therefore it seems to get selected first.
This is against my understanding of routes, I thought a route consists of a 3-tuple: HTTP-Method, Request Path, Call definition ... and as the call definitions differ (sendQuestion() and sendAnswer()), the correct one should be used?
Why is this not the case?
I've read about routing in the documentation of the play framework and googled, but still dont understand.
I am also aware how to fix my problem, but I want to understand what's happening here.
Fix 1:
Change this
POST / controllers.Application.sendAnswer()
to this
POST /Antwort controllers.Application.sendAnswer()
Disadvantage: This is not the homepage (index) anymore. Seems weird.
Fix 2:
Write a combined method for sending stuff from the form to the index.
Disadvantage: I want to keep the methods separate, in order to maintain a better structure in my project. Also I would have to see if a question gets asked or an answer written and based on that omit one of the fields or use another one (answer has an extra questionID-field to link an answer to a question).
So, why is this happening in the routes and whats the best way to deal with it?
In Play each route is combination of route method (GET/POST) and path (determined by static parts and params types) so if you have two routes with the same type and path only first will be resolvable, other will be ignored even if you'll use other name of param (but same param type).
In this case the bar(String bar) method won't be resolved ever:
GET /foo/:foo controllers.Application.foo(foo: String)
GET /foo/:bar controllers.Application.bar(bar: String)
The safest way to make sure that you won't mishmash the routes is using unique paths always in sets:
GET / controllers.Application.index()
GET /FrageStellen controllers.Application.askQuestion()
POST /FrageStellen controllers.Application.sendQuestion()
GET /AntwortGeben controllers.Application.writeAnswer()
POST /AntwortGeben controllers.Application.sendAnswer()
Finally if you want to go to the root page after post you can return a redirect() instead of ok()
You should post to an action with different request path and then redirect to index. It is a recommended approach in web development.
http://en.wikipedia.org/wiki/Post/Redirect/Get
i am working on a project. my work is retrieve data from database and displaying them. if required sent to next page for further processing. my problem is i got value from database and i want to send it another jsp or servlet using href.
value i am retrieving is :
<%=special.getString("id")%>
send it to:
Buy Now
but when send data like this error is
is that correct? how do i do it? what is the correct method. i am struck here for long time please help me.
Use single quotes around id instead double.
"new.jsp?id=<%=special.getString('id')%>"
If you're serious about JSP development ditch scriptlets (which went out of common use 10+ years ago) and familiarize yourself with the Java Standard Tag Libraries and JSP Expression Language.
I am not quite sure what 'special' is here, however using EL your code will look something like the below:
<!-- special is an object with a method getId()-->
Buy Now
or
<!-- special is an object with a method getString(String key) -->
Buy Now
If this doesn't work then there is no bean with key 'special' in any scope.
Note that if you are working with a database in your JSP you should consider refactoring to use the standard JSTL SQL tags. See below for an example:
http://www.tutorialspoint.com/jsp/jstl_sql_query_tag.htm
See also:
http://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm
http://beginnersbook.com/2013/11/jsp-expression-language-el/
*Note for the second example to work your app need to be compliant with the Servlet 3 specification (as passing mthod params was nut supported in EL before this). See further: https://stackoverflow.com/a/6337222/1356423
Use single quote inside double quote.
I am trying to type code but not able to type.
now it should work
You need to escape your quotes first or use single quotes so that your double quotes can work:
Note: Untested.
Buy Now
I see in your error message it says DOUBLE_WHITESPACE in QUERY. I would suggest you try encoding you url.
<% String id=java.net.URLEncoder.encode(special.getString("id") , "UTF-8");%>
Buy Now
we are trying to add a simple test using JMeter in a JSF Application. We followed the instructions in:
http://jmeter.apache.org/usermanual/build-adv-web-test-plan.html
It has a simple login page with user name and password and a submit button. You can see from the screenshots that we used a proxy. With the settings in the screenshot we are getting HTTP 500 Error. I am not sure if I placed the question in a right way.. Please ask if you need any clarification.
The error code is:
EDIT:
I think this is going to be the longest question of SO. But images are better than words sometimes. Anyway, what we have done is to sent the data that is equivalent to what we see in the firebug. But still getting 500 error. You can see in the attachments Tomcat log.
HTTP 5xx codes are related to server or application errors. Search log files first.
Your script don't need a "User Defined Variables" component because there's no variable expression that really need to be evaluated per thread/user.
The "Regular Expression Extractor" component suffice to extract the JSF ViewState value.
I suggest you to delete the last part of your expression, " />", and change the regular expression grouping (.+?) to (\w+?) 'cause it will evaluate to a few matches (probably only 2). Change the value of "Match No." field to 1 (no need to use random if all values matched are identical).
I didn't understand why you used both "XPath Extractor" and "Regular Expression Extractor" components to extract the same value. I prefer to use the last one when leading with html. XPath is better when treating with well-formed xml strings/files.
To capture a script from scratch, I suggest you to add a "HTTP Proxy Server" inside Workbench, configure it, start it, configure a browser to use this proxy and navigate those pages using the browser. This way you'll capture all requests made and request headers used by the browser you choose. After this, remove unnecessary requests and change query parameters, like javax.faces.ViewState, to the corresponding variables.
Consider using extractors (Pos-Processors) inside an HTTP Sampler prior to the one that will use the variable in Parameter Values. Ex.: if /EBS request comes first and /EBS/login.xhtml request have a javax.faces.ViewState parameter then, probably, /EBS response will contain a hidden input with the javax.faces.ViewState value.
This is a common make up of JSF application test scripts I use. Providing more information about the cause of the HTTP 500 error should clarify the way to a better solution.
On the Regular Expression Extractor for jsfViewState, add (?s) to the start of the regular expression. So you have:
(?s)<input type="hidden" name="javax\.faces\.ViewState" id="javax\.faces\.ViewState" value="(.+?)" />
This allows the (.+?) to span line break characters.
Your regular expression extractor is in the wrong place. You cannot extract a value from the response to a request and then send it with the same request. The only way to achieve this is to use a time machine, but these don't exist yet and even if they did, it probably wouldn't work.
Typically you get a viewstate in the response to a GET and then you later need it in the POST of the same page. So, put the regular expression extractor as a child of the GET call where the login.xhtml page is first called (as a GET). If your recording does not include this GET call then either add it manually or examine the responses of previous calls before your login POST to find it, eg. maybe the GET homepage.xhtml (or similar) will include it.
I'm writing a unit test for a Wicket WebPage. I want to fire up a page, type into a field, click a link, and then make some assertions.
Looking at the API of WicketTester and BaseWicketTester, I couldn't find any method that takes a path (like "form:input") to locate an input field and lets you enter text in it.
// set up WicketTester; create page
tester.startPage(page);
tester. // Type into input field - how to do this?
tester.clickLink("form:continueButton");
// assert something
Did I miss something? This seems like a pretty basic use case. Are you not supposed to use WicketTester like this? (That would be surprising given the presence of methods like clickLink().)
Use FormTester:
FormTester formTester = tester.newFormTester("form");
formTester.setValue("myformfield", "Hello Sailor");
Reference:
FormTester javadoc
Testing Pages (Wicket wiki, somewhat outdated but still relevant)
I'm trying to assign a js variable to java's request or session and want to access it from the server side. I dont want the js variable to be passed on in the URL. Help me, I'm seeking for a solution.
Thanks in advance
JavaScript only runs on the browser, it has no connection to the database except for ajax type calls.
But, you can add data to the post request for example from javascript, and that would get to the servlet, which is probably your best solution.
But, this really depends on which javascript library you are using, though, for more details.
I'm not sure if I understood your question. But if You want asynchronously manipulate "objects in browser" from server it is not possible directly.
There are workarounds, search for reverse ajax.
It sounds like you need to review the difference between GET and POST variable submission. GET will put it in the address (exmple.com/index.html?var=6) and POST will not. After that you'll have to look at your js library to determine how to direct what the variable hooks up to.
The typical most simple way is to use hidden input fields and have your JavaScript fill those input fields with the values you need. When your form gets submitted the hidden input fields will be accessibel in your Java