I'm looking a way to call a detail page from master page composer.
I have following files :
src/main/webapp/po_inquiry.zul
src/main/webapp/po_inquiry_detail.zul
on click event of po_inquiry.zul grid, I need to redirect to po_inquiry_detail.zul
I found an article on https://www.zkoss.org/wiki/ZK_Developer's_Reference/UI_Patterns/Communication/Inter-Application_Communication
However, I still can't redirect into detail page. Here is the code for calling detail page. Called from master page Composer (selected data prints correct data on log, the error message is just ZK can't find /order/po_inquiry_detail.zul) :
#Listen("onDetail = #lstPoHeaders")
public void onDetail(ForwardEvent evt) {
PurchaseOrderHdr selectedData = (PurchaseOrderHdr) evt.getData();
Map<String, Object> params = new HashMap<String, Object>();
params.put(PurchaseOrderHdr.class.getName(), selectedData);
LOG.debug(selectedData);
Executions.createComponents("~/order/po_inquiry_detail.zul", getSelf().getParent(), params);
getSelf().detach();
}
I've also tried to put po_inquiry_detail.zul files under src/main/resources (classpath), but it didnt work too
Any help will be appreciated. Thank you
I think you make a mistake by reading that article.
That article is about multiple web apps and reaching out to pages of other apps.
Just try this :
Executions.createComponents("po_inquiry_detail.zul",getSelf().getParent(),params);
Now, a second mistake is that this is no redirection.
Redirection means, you will change the url, and in this case it will not happen.
Difference is seen in pressing F5 => you way will be the previous page and you will not see the detail.
Real redirection will show the detail page again.
Related
From current JSP I need to open new page with sending to it POST data. How I can make it?
In other words I need redirect from one page to another, but I cant use sendRedirect(because only GET) and requestDispatcher(because context of pages are different)
You have to create <form method="post">, fill the fields with respective data and submit it by JavaScript.
But on the other hand, what is your reason for that? There probably exists a cleaner solution.
Just make the behaviour that would happen if the initial POST data is received the default behaviour of the JSP when no post data is received.
e.g (in pseudo code - I don't know Java)
if (is_set(POST) ) {
if(POST == expectedInitialVals) {
defaultBahaviour();
} else {
handleOtherValues();
}
} else {
defaultBahaviour();
}
If you also want to persist the POST data in the page set the values on the relevant form fields in the page in your JSP.
First of all let me describe what I'm trying to do, which I'm guessing is pretty simple.
I have a website with users and want to restrict access to a view_profile.jsp page only to logged users. I have a filter mapped to:
<url-pattern>/auth/*</url-pattern>
which looks like this
try {
HttpSession session = ((HttpServletRequest)request).getSession();
UserBean user = (UserBean)session.getAttribute("currentUser");
if (user != null && user.isValid()){
System.out.println("Filter: context -> " + ((HttpServletRequest)request).getContextPath()); //returns ""
chain.doFilter(request, response);
}
else{
((HttpServletResponse)response).sendRedirect("/login.jsp"); //works fine
}
This filter is run when on the index.jsp page user will click on a link:
<a href="./auth/view_profile?profile=${sessionScope.currentUser.username}">
//yeah, he will 'view' himself - it's just an example
which is suppose to take the user to the servlet mapped to ViewProfileServlet mapped to:
<url-pattern>/auth/view_profile</url-pattern>
which looks like that:
try {
String username = (String) request.getParameter("profile");
// here is getting info from database and setting request attributes
// works fine
//response.sendRedirect("/view_profile.jsp");
System.out.println("ViewProfileServlet: In context -> " + getServletContext().getContextPath()); // returns ""
dis = getServletContext().getRequestDispatcher("/view_profile.jsp");
// i've tried request.getRequestDispatcher. no difference
System.out.println("ViewProfileServlet: forward to '/view_profile.jsp'");
dis.forward(request, response);
}
Which in turn should take the user to the /view_profile.jsp (in the root context, not in /auth) and work, which it doesn't. What happens is the ViewProfileServlet runs and the view_profile.jsp shows, although it seems that the context is still /auth because all the links on view_profile.jsp point to i.e localhost:8080/auth/some-page.jsp. Also, css files are not being loaded, they're not even requested (at least according to firebug), and page source shows 404 Glassfish Error where css's suppose to be.
I would greatly appreciate any help, it's the first time i'm even doing something in jsp and i'm completely lost here.
A forward happens entirely at server-side. The browser doesn't know about it. When it sends a request to /auth/view_profile, and receives HTML from this response, he doesn't care if the HTML has been generated by a servlet, a JSP, both, or anything else. It reads the HTML and considers it comes from the path /auth/view_profile. All the relative path in the HTML are thus relative to /auth/view_profile.
It's far easier to use absolute paths to reference images, JS and CSS paths (and even other actions, most of the time). Just make sure to use the <c:url> tag to generate the URL, so that the context path of the web-app is prepended:
<script src="<c:url value='/js/myScript.js'/>" type="text/javascript"/>
^-- the slash here makes the path absolute.
I'm noticing some odd behavior with redirect when I set my app.context a certain way. I found a bug in the Grails JIRA which describes my problem perfectly, but it was marked as UTR: http://jira.grails.org/browse/GRAILS-7546
Here is my description of the problem:
I'm currently using Grails 2.0M2. I have the following properties defined in my application.properties file:
app.context=/
app.name=foobar
When I call redirect in a controller, redirect is adding the app name onto the uri I provide, which then causes a 404. Here is how I'm doing this:
String partialUrl = createLink(mapping: 'helloworld') // returns `/hello/world`
redirect(uri: partialUrl) // INCORRECTLY redirects to
// `http://mysite.com/foobar/hello/world`
// instead of `http://mysite.com/hello/world`
Assume that I have a URL mapping named helloworld defined in my UrlMappings.groovy file with a path of /hello/world.
So, long story short, if I set the app.context to /, I would NOT expect the app.name to show up in my final redirect URL.
Is this a bug or expected behavior? Any idea on the easiest way I could build up the redirect URL without doing too many manual steps?
I hate to say it, but I cannot reproduce it either. I created a test project with one controller (named Hello), using your code to create an action that does nothing but redirect:
HelloController.groovy
package test1
class HelloController {
def index() {
def model = [:]
model.content = 'content...'
model
}
def redir() {
String partialUrl = createLink(mapping: 'helloworld') // returns `/hello/world`
redirect(uri: partialUrl) // INCORRECTLY redirects to
// `http://mysite.com/foobar/hello/world`
// instead of `http://mysite.com/hello/world`
}
}
I created an index page, index.gsp in the views/hello
index.gsp
<h1>index.gsp</h1>
<html>
<body>
<p>This data is coming from the model:</p>
<p>content: ${content}</p>
</body>
</html>
Setup helloworld in the UrlMappings to map to the index action of the hello controller:
UrlMappings.groovy
class UrlMappings {
static mappings = {
"/helloworld"(controller: "hello", action: "index")
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(view:"/index")
"500"(view:'/error')
}
}
And changed the application.properties to have the app.context=/
application.properties
#Grails Metadata file
#Sun Nov 06 14:51:56 EST 2011
app.grails.version=2.0.0.RC1
app.context=/
app.name=test1
app.servlet.version=2.5
app.version=0.1
When I ran the app, I could go to localhost:8080/hello and it would show my simple GSP. I tried localhost:8080/helloworld and also got it as expected per the mapping. Then I tried localhost:8080/hello/redir and I was properly redirected to localhost:8080/helloworld.
However, if you're still facing this issue, I have a few suggestions
1) Try using the new link generator available in 2.0 instead of createLink. It may not do anything different, but worth a try: grailsLinkGenerator.link(mapping: 'helloworld')
2) If it's only on redirects from within controllers, you could just add the http://mysite.com portion yourself to the partialUrl.
3) Last resort, write a Filter attached to afterView that does a regex search and replace on the contents for mysite.com/foobar. Not sure this will catch redirects though, but if anything would, I'd assume this would be it since filters can be applied at broad level.
def yourAction = {
redirect(uri:"helloworld")
}
That doesnt work for you?
It's not a direct anwser to your question but my practice is : I never modify app.context in the grails properties since tomcat override it on production and I don't care which context it uses on my dev.
I have a mobile flow for registration that I want to use in my app, and I do not have control of the source --
I am looking for a way to grab a few pieces of data when the user finishes registering, (confirmation number, etc.) that will be sent to my app (hopefully via Android's addJavascriptInterface)
I am certain on one thing - the id of the element I need. The flow could change, and is already a few pages long, So I'm looking for a general solution. The basic Idea I'm hoping for is this:
Inject a JavaScript snippet to each page during shouldOverrideUrlLoading, which will automatically call my JavaScript Interface and check for the value of the field with the id I'm looking for. (or just return the entire HTML, and I'll do it in Java)
view.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//inject javascript here to get value
return false;
}});
I've seen tutorials on using addJavascriptInterface, but they all seem to assume some control or understanding of the 'single' page that will be navigated to. Since I have a potentially lengthy flow (3+ pages) and no control over the source, I am interested in hearing any suggestions.
Check URL of the current page and if it's the right one insert JavaScript in the curent page. With the help of Java-JS binding you could get some data out. See my previous answer: Determine element of url from webview shouldOverRideUrlLoading
I'm updating a Selenium program I wrote a while back and part of it has stopped working. I want to go through a whole series of links on a page, click on each, making sure that some expected text is present. But sometimes a log-in page (https://library.med.nyu.edu/sso/ezproxy_form.php) appears before the desired page, in which case I need to log in before checking the page. The problem is, no matter what string I put in to check whether I've landed on the log in page, Selenium concludes it's not present and skips logging in, obviously causing everything else to fail. See below--I'm not sure that was actually the problem. It seems to be instead that it's rushing through the "if we need to sign in" code without actually signing in, then obviously failing the main part of the test because it's not on the right page.
Here's the code--does anyone see my mistake?
for (int i = 0; i < Resources.size(); i++) {
try {
selenium.open("/");
selenium.click("link=" + Resources.get(i).link);
selenium.waitForPageToLoad("100000");
if (selenium.isTextPresent("Please sign in to access NYUHSL e-resources")) {
selenium.type("sso_user", kid);
selenium.type("sso_pass", password);
selenium.click("name=SignIn");
selenium.waitForPageToLoad("100000");
}
if (!selenium.isTextPresent(Resources.get(i).text)) {
outfile.println(Resources.get(i).name + " failed");
}
} catch (Exception e) {
outfile.println(Resources.get(i).name + " could not be found--link removed?");
}
}
Does the login page have a page title? If yes, try validating the page title using selenium.getTitle() method to check if you are headed to login page. If not, proceed clicking on the link without logging in.
I think page title validation can help resolve this issue
Try putting:
selenium.setSpeed("1000");
Right after the selenium.open this will inject 1 second delay (1000ms) between selenium commands. You should make it a standard practice to add this, especially if you're not running headless browsers.
Also you might consider using, since you know the url you are expecting to be on if on the login page, the selenium command getLocation. This will return the absolute URL of the current page. Might be more effective than trying to look for elements that can change at any time within the page.
So to use getLocation in your code above:
if (selenium.getLocation() == "your reference url"){
do your login stuff here
}
Again this is just a sample to illustrate what I'm saying. Hope it helps you out.