Submit in Spring form using DWR library - ajax

In one of J2EE project, we are using DWR libary. Being familiar with simple ajax calls and little DWR, I am not able to figure out which service call is used on our backend on clicking the submit button in one of our spring forms.
KRIDeclaration.jsp file:
Spring Form tag :
<form:form commandName="KRIDeclarationCommand" name="krideclaration" method="post" enctype="multipart/form-data">
........
Submit button: <td height="20" colspan="4" align="right" class="dvtCellLabel">
<div align="center"><span style="padding-top: 5px;"> <input
class="btnstyle" type="button" name="btnSendForApproval"
value="Submit" onClick="declareIncident();" />
KRIDecleration.js
declareIncident()
{
Basic front end Validation
Backend Validation using DWR generated js file with a callback
}
callbackmethod(Result)
{
if (success)
document.krideclaration.submit();
else
//code for displaying errors.
}
dwr-context.xml:
dwr:annotation-scan base-package="com.abc.riskdashboard.common" scanDataTransferObject="true" scanRemoteProxy="true" />
<!-- DWR will map util.js and engine.js files to the dwrController.
You can then include this files as external Javascript references from your JSP -->
<dwr:url-mapping />
<!-- Defines the dwrController. During production, set the debug property to false -->
<dwr:controller id="dwrController" debug="true" />
<!-- This is required if you want to configure any beans not managed by
Spring. Leaving it enabled doesn't do any negative effects.
-->
<dwr:configuration>
<dwr:convert type="bean" class="com.abc.riskdashboard.common.dto.RiskAreaMasterDTO" />
<dwr:convert type="bean" class="com.abc.riskdashboard.common.dto.RiskIndicatorDTO" />
<dwr:convert type="bean" class="com.abc.riskdashboard.common.dto.RiskDeclarationDTO" />
<dwr:convert type="bean" class="com.abc.riskdashboard.common.dto.UserMasterDTO" />
<dwr:convert type="bean" class="com.abc.riskdashboard.common.dto.RoleMasterDTO" />
Need to find out what document.krideclaration.submit() in KRIDecleration.js calls when success. There is not submit function or action attribute in spring form

Related

Conditional rendering in Spring in Action 4

I've been working on an example on conditional rendering from Spring in Action 4.
The code looks this way:
<sec:authorize access="hasRole('ROLE_SPITTER')">
<s:url value="/spittles" var="spittle_url" />
<sf:form modelAttribute="spittle" action="${spittle_url}">`
<sf:label path="text"><s:message code="label.spittle" text="Enter spittle:"/> </sf:label>
<sf:textarea path="text" rows="2" cols="40" />
<sf:errors path="text" />
<br/>
<div class="spitItSubmitIt">
<input type="submit" value="Spit it!" class="status-btn round-btn disabled" />
</div>
</sf:form>
</sec:authorize>
The question is what does the code attribute, namely label.spittle refers to? Does it refer to the modelAttribute from the form? Or does it mean that there should be message bundle with key label.spittle?
It means a key in a resource bundle (documentation):
<s:message code="label.spittle" text="Enter spittle:"/>

Extraction Rule configuration in Visual Studio 2013 web performance tests

I've been following this guide to create my web performance tests in VS 2013 and I found interesting thing, which I am not sure how to understand.
I have a web application. On certain request this application returns me a page, where I have a span element which has style attribute, which is equal to "color:Blue;". In my performance test I go to that page and I have "Extract Attribute Value" extraction rule to get a value of style attribute of that span tag. When I configure my rule to get attribute style1 for that tag, the rule fails (which I expect to happen), but when I create a rule with match attribute value "c#l#r-BBBB", it doesn't fail (although, I expect it to fail).
Does anybody know why?
Here is the page source:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="Blue.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="QG+BA5tJt9bUUKK/SNJvCYaITvz71sZMdjWwNGygbhGjjs6Vy/29qy+kskbo3g4Vaz2Zfpi8hlr2F4g366EChHwtM2N676WWg0LBR3+9hc0=" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="D66C0198" />
</div>
<div>
<span id="Label1" style="color:Blue;">Blue</span>
</div>
</form>
</body>
</html>
These is the extraction rule in .webtest, that I expect to fail:
<ExtractionRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractAttributeValue, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" VariableName="ExtractionTest" DisplayName="Extract Attribute Value" Description="Extract the value of an attribute from a specified HTML tag.">
<RuleParameters>
<RuleParameter Name="TagName" Value="span" />
<RuleParameter Name="AttributeName" Value="style" />
<RuleParameter Name="MatchAttributeName" Value="" />
<RuleParameter Name="MatchAttributeValue" Value="c#l#r-BBBB" />
<RuleParameter Name="HtmlDecode" Value="True" />
<RuleParameter Name="Required" Value="True" />
<RuleParameter Name="Index" Value="0" />
</RuleParameters>
</ExtractionRule>
I believe you need to specify vales for both the MatchAttributeName and the MatchAttributeValue properties. The documentation for the ExtractAttributeValue rule is not clear about what combinations of its properties are supported. However, I interpret the rule as saying: look for a TagName tag TagName where the attribute MatchAttributeName has the value MatchAttributeValue and from that tag return the value in AttributeName. Using that interpretation has always worked for me.
The documentation for AttributeName says that it "is used to identify the attribute whose value you want to extract", it does not say it is used to match any values. This documentation goes on to say that MatchAttributeName and (my emphasis) MatchAttributeValue are used in some cases.

Struts2 client side validation without using action class

Need to do client side validation in struts2 only using validation.xml but my beans are in bean class. validation.xml only supports action class based validation.
i need client side validation without using javascript or any validate method.
Struts Validator Framework provides an easy-to-use mechanism for performing client-side validation.
For each validation routine defined in the validation-rules.xml file Struts provides an optional JavaScript code that can run on the client-side to perform the same validation that takes place on the server side.
LoginForm extends DynaValidatorForm
<form-bean name="LoginForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="userName" type="java.lang.String" />
<form-property name="password" type="java.lang.String" />
</form-bean>
following validations are defined in the validation.xml file.
<form name="LoginForm">
<field property="userName" depends="required">
<arg key="LoginForm.userName"/>
</field>
<field property="password" depends="required,minlength">
<arg0 key="LoginForm.password"/>
<arg1 key="${var:minlength}" name="minlength" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
</form>
To enable client-side validation you have to place the Struts HTML Tag Library's javascript tag in each jsp page for which you need to preform client-side validation.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JS Validation</title>
</head>
<body>
<html:form action="/Login" onsubmit="validateLoginForm(this);">>
<html:javascript formName="LoginForm" />
User Name : <html:text name="LoginForm" property="userName" />
Password : <html:password name="LoginForm" property="password" />
<html:submit value="Login" />
</html:form>
</body>
</html>

Embed Spring Security login form to an existing page

How do I add the spring security login form to an existing page?
For example, let's say I have the following test.jsp page (which is not a spring login form page):
<html>
<head>Existing Page</head>
<body>
<div id="login-form"></div>
</body>
</html>
I would like to add the login form configured in my spring-security.xml inside the login-form div.
Typically I believe people just put the form right in the page (i.e. within the div you have there.) Something like:
<form id="blah" action="/j_spring_security_check">
<input type="text" name="j_username" />
<input type="text" name="j_password" />
<input type="submit" name="submit" value="login" />
<input type="reset" name="reset" />
</form>
Then use your css to make it fit the look and feel of the rest of your application.

How to use Spring security with Primefaces

I have found so many examples but the problem is all of them are using JSP/JSF as view. The problem is they always use j_username as username input id and j_password as password id. What I found is these names are standard names. Primefaces doesn't allow me to give name to p:inputtext component. Do you have any solution?
Here is an example : http://krams915.blogspot.com/2012/01/spring-security-31-implement_13.html
j_username and j_password are only default values in Spring Security. You can customize these names as you expected. To do this, you set values for password-parameter and username-parameter as below:
<security:form-login login-page="/login.html"
default-target-url="/welcome.html"
always-use-default-target="true"
authentication-failure-url="/login.html?error"
password-parameter="your_value"
username-parameter="your_value"/>
I'm using Spring Security 3.1. With another version, the configuration is possibly something like above.
Try to use a normal HTML form pointing to the URL of login controller instead of a Primefaces tags:
<form name='f' action="/j_spring_security_check" method='POST'>
<input type='text' name='j_username' value=''>
<input type='password' name='j_password' />
<input name="submit" type="submit" value="submit" />
</form>
You can post directly to j_spring_security_check, but sometimes it might come handy to do it programmatically to combine both worlds.
<p:commandButton value="Login" action="#{loginController.login}" ajax="false">
<h:inputText id="j_username" required="true" />
<h:inputSecret id="j_password" required="true" />
with h xmlns:h="http://java.sun.com/jsf/html"
in your loginController:
ExternalContext context = FacesContext.getCurrentInstance()
.getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/j_spring_security_check");
dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());

Resources