Bitwise AND operator
To alternate the table background color:
rows [i].className = ((rows [i].index & 1) == 1) ? "alt" : "";
To alternate the table background color:
rows [i].className = ((rows [i].index & 1) == 1) ? "alt" : "";
Posted by Ginger at 9:59 AM 0 comments
Labels: Javascript, operator
- Example 1
var regex = /<title[^>]*>([\s\S]*?)<\/title>/i;
while(match = regex.exec(httpResp)){
if ('Login Page' == match[1]) {
...
html += ' <a href="javascript:showManyToMany (groupsForUser, \'' +
rowData.name.replace(/\'/g, "\\'").replace(/\"/g, "&.quot;") + '\');">Edit</a>';
Posted by Ginger at 5:18 PM 0 comments
Labels: Javascript, regex
DWR has a global handler textHtmlHandler for this purpose. When a DWR request receives a response that isn't Javascript. It indicates a server session has timed out, and we can redirect user to logon screen in this handler. So any DWR call doesn't need to worry about session timeout.
dwr.engine.setTextHtmlHandler(function() {
document.location.reload();
});
load: function(type, data, evt) {
sessionTimeoutCheck(data, evt);
...
}
dwr.engine.setErrorHandler(handler);
Remote.method(params, {
callback:function(data) { ... },
errorHandler:function(errorString, exception) { ... }
});
dwr.engine.beginBatch();
Remote.method(params, function(data) { ... });
// Other remote calls
dwr.engine.endBatch({
errorHandler:function(errorString, exception) { ... }
});
Posted by Ginger at 4:13 PM 0 comments
Labels: ajax
In JavaScript, undefined means a variable has been declared but has not yet been assigned a value, such as:
var TestVar;
alert(TestVar); //shows undefined
alert(typeof TestVar); //shows undefined
var TestVar = null;
alert(TestVar); //shows null
alert(typeof TestVar); //shows object
typeof(SomeObject) == 'undefined'
Posted by Ginger at 10:56 AM 0 comments
Labels: Javascript, undefined
DWR has a textHtmlHandler that allows you to manage what happens when a DWR request receives a response that isn't Javascript. This generally means that a server session has timed out, so it is usual in a textHtmlHandler to redirect to a login screen.
dwr.engine.setTextHtmlHandler(function() {
//automatically take user to logon page due to timeout
document.location.reload();
});
dwr.engine.setErrorHandler(handler);
Remote.method(params, {
callback:function(data) { ... },
errorHandler:function(errorString, exception) { ... }
});
dwr.engine.beginBatch();
Remote.method(params, function(data) { ... });
// Other remote calls
dwr.engine.endBatch({
errorHandler:function(errorString, exception) { ... }
});
Posted by Ginger at 10:42 AM 0 comments
- a Java component-oriented web framework (RAD)
- allows developers to think in terms of components, events, backing beans and their interactions, instead of requests, responses, and markup.
- higher level abstraction, Servlets and JSP were developed to make it easier to build applications on top of HTTP protocol. JSF was introduced so that developers can forget that they're using the protocol at all.
def: a software component is a unit of composition with contractually specified interfaces and explicit context dependencies only (container). A software component can be deployed independently and is subject to composition by third parties.
Events:
1. value change event
2. data model event - data row selected
3. action event - command from button or link
4. phase event - request processing life cycle event
Phases: (translate http request to events and update server side components value)
1. restore view
- find/create components tree, including event listeners, validators,converters associates with components; if initial request, skip to phase 6
2. apply request values
- update value of components to values in request, converter may get involved
-'immediate' property may trigger action event, handy for 'Cancel' button
3. process validation
- component validate itself
- value change events fired
4. update model values
- update value of backing beans or model objects associated with components
5. invoke application
- action events fired
6. render response
- render response, and save view in user session (?) to be restored later
Question: why may date model events be fired in phase2 - phase 4?
- 且就洞庭赊月色, 将船买酒白云边。
Posted by Ginger at 11:08 PM 0 comments
ScopeInterceptor is used to pull attributes out of session/applicaton and set action properties, i.e., dependency injection.
<action name="handleGeneralError" class="...">
<interceptor-ref name="scope">
<param name="key">FoglightError_</param>
<param name="session">exception,statusCode,originalRequestUri</param>
<param name="type">end</param>
</interceptor-ref>
<result .../>
</action>
Posted by Ginger at 3:57 PM 0 comments
Labels: webwork
1xx Informational
2xx Successful (200 OK)
3xx Redirection (302 Found)
4xx Client Error (403 Forbidden 404 Not Found)
5xx Internal Server Error
We can define how a web application handles errors using the error-page
element in the WEB-INF/web.xml file. The error-page
element defines exceptions by exception type or by error code, as the following sections describe. The order of these elements in the web.xml file determines the error handler.
<error-page>
<error-code>500</error-code>
<location>/common/error/handleGeneralError.jsp</location>
</error-page>
<error-page>
<exception-type>java.io.FileNotFoundException </exception-type>
<location>/error-pages/404.jsp </location>
</error-page>
Object status_code = req.getAttribute("javax.servlet.error.status_code");
Object message = req.getAttribute("javax.servlet.error.message");
Object error_type = req.getAttribute("javax.servlet.error.exception_type");
Throwable throwable = (Throwable) req.getAttribute("javax.servlet.error.exception");
Object request_uri = req.getAttribute("javax.servlet.error.request_uri");
Posted by Ginger at 5:18 PM 0 comments
Labels: error handling, http
A British man who went on a wild spending spree after doctors said he only had a short time to live, wants compensation because the diagnosis was wrong and he is now healthy - but broke. John Brandrick, 62, was diagnosed with pancreatic cancer two years ago and told that he would probably die within a year. He quit his job, sold or gave away nearly all his possessions, stopped paying his mortgage and spent his savings dining out and going on holiday. It emerged a year later that Brandrick's suspected "tumour" was actually an inflamed pancreas.
- spree: a time of free and wild fun, spending, drinking, etc.
- inflamed: (of a part of body) read and swollen because hurt or diseased
Posted by Ginger at 9:23 PM 0 comments
Besides the default result type "dispatcher", there are some common result types:
1. redirect
Important for those create actions, reload confirmation page may result in re-create sth if URL stick to the previous create action. Parameter can be passed in by value in stack. e.g,
.. type="redirect">listBundles.action?archiveFilename=${archiveFilename}
2. chain
Action chaining is different from dispatching to another action in that:
- In same ActionInvocation
- Copy common properties from most recent action
In both cases, every action executed is pushed onto stack since they run in same thread/request.
3. StreamResult
For download file. BTW, use setTimeout() on init() to both refresh a page and download a file sounds a better solution than using refresh metatag which causes 'back' button problem.
We may even create customized ResultType such as JSON for AJAX call.
Posted by Ginger at 11:00 AM 0 comments
- Number
value?c converts a number to string for ``computer audience'' as opposed to human audience.e.g., number 3600 will be parsed as 3600 instead of 3,600
- Handle missing values
exp1!exp2 deprecates exp1?default(exp2)
exp1! deprecates exp1?if_exists (replace with empty string "", empty set etc if not exists)
exp1?? deprecates exp1?exists
Note:
product.color?default("red")
This examines if the product hash contains a subvariable called color or not, and returns "red" if not. The important point is that product hash itself must exist, otherwise the template processing will die with error.
(product.color)?default("red")
This examines if product.color exists or not. That is, if product does not exist, or product exists but it does not contain color, the result will be "red", and no error will occur.
Posted by Ginger at 5:51 PM 0 comments