asp.net mvc4 clientside validation doesn't work - asp.net-mvc-4

I have clientside validation enabled in my config and I'm also including the appropriate jquery files for validation, but every time I submit, the page posts to server without first doing clientside validation. I have pasted the markup generated in the source below. It seems to be generating the data- validation messages fine. Just somehow not triggering validation.
I'm using the BeginCollection library that's available on Nuget to build my dynamic form. Could that be a reason for my clientside validation for somehow not working?
<input class="text-box single-line valid" data-val="true"
data-val-number="The field DaysAbsent must be a number."
data-val-required="The DaysAbsent field is required."
id="students_471abdc8-b190-42da-9f72-ed30a1e33b10__DaysAbsent"
name="students[471abdc8-b190-42da-9f72-ed30a1e33b10].DaysAbsent"
type="text" value="0">
My web.config:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
_Layout.cshtml:
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/jqueryui")
#Scripts.Render("~/bundles/jqueryval")
#RenderSection("scripts", required: false)
BundleConfig.cs:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));

You mentioned dynamic form, so if you are loading your inputs dynamically jquery.validate doesn't know they are there. You have to "refresh" your form validations to validate your new inputs.
After adding a new input, use this code to "refresh" the validations for your form:
$('form').removeData('validator');
$('form').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse($('form'));

Related

Umbraco not authenticating against Active Directory

I'm creating an internet site for the follow configuration:
- public website
- users need to authenticate agains active directory
- roles are servered by an 3th party ERP system, also using AD for authentication
What I have done
So I tried to follow this guide (https://our.umbraco.org/wiki/how-tos/membership-providers/active-directory-membership-provider) for the authentication, and wrote a custsom role provider for the ERP roles. I used the built in template for the login form.
The role part works just fine. The authentication does not.
The problem
It seems that Umbraco is still using the UmbracoMembershipProvider. When I create a member in umbraco I can login with the umbraco credentials. When I try any AD accounts it won't authenticate.
I tried to
Change the LDAP connectionstring to use a non existing OU or CN. It gives me errors, so connection to AD is made somewhere in the proces.
I also tried RB.ActiveDirectoryProviders. Same result.
I don't get any exception thrown, just "Invalid username or password". The logs say:
2015-08-19 08:45:20,764 [126] INFO Umbraco.Core.Security.UmbracoMembershipProviderBase - [P6460/T133/D8] Login attempt failed for username nico from IP address ::1, the user does not exist
My best guess I made some configuration error.
So how do I use Active Directory as only MembershipProvider?
Any help is welcome.
My setup:
local box with iis/umbraco/VS2012 running a virtual PC with the AD. I run Umbraco 7.2.8 in Visual Studio/IISExpress. I used the Nuget package of Umbraco.
web.config
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://192.168.2.50/dc=XXX,dc=YYY" />
</connectionStrings>
<membership defaultProvider="ADMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider" type="Umbraco.Web.Security.Providers.MembersMembershipProvider, Umbraco" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="true" enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Member" passwordFormat="Hashed" />
<add name="UsersMembershipProvider" type="Umbraco.Web.Security.Providers.UsersMembershipProvider, Umbraco" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="true" enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" passwordFormat="Hashed" />
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnectionString" connectionUsername="[USER]" connectionPassword="[PASSWORD]"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
#using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
{
<fieldset>
<legend>Login</legend>
#Html.ValidationSummary("loginModel", true)
#Html.LabelFor(m => loginModel.Username)
#Html.TextBoxFor(m => loginModel.Username)
#Html.ValidationMessageFor(m => loginModel.Username)
<br />
#Html.LabelFor(m => loginModel.Password)
#Html.PasswordFor(m => loginModel.Password)
#Html.ValidationMessageFor(m => loginModel.Password)
<br />
<button>Login</button>
</fieldset>
}
After hours of searching I finally resolved this. It seems that the UmbLoginController always uses the UmbracoMembershipProvider. This is in my opinion not transparent.
Anyhow, I created a new surface controller like mentioned here and everything works fine now.

linq query to datatable error vb

I'm trying to send the results of a linq query to a new datatable. I will then use this datatable as a datasource for a datagridview. Aim being for edits made in datagridview to go back to the dataset and in turn to the xml. Followed this, here:
msdn guide
with this code:
Dim xmlFile As XmlReader
xmlFile = XmlReader.Create(My.Settings.CfgFile, New XmlReaderSettings())
Dim ds As New DataSet
_XMLRawDS.ReadXml(xmlFile)
Dim _XMLquery = From xmlsystem In _XMLRawDS.Tables("system").AsEnumerable()
Join xmlcontroller In _XMLRawDS.Tables("controller").AsEnumerable() On xmlsystem.Item("system_Id") Equals xmlcontroller.Item("system_Id")
Join xmlinput In _XMLRawDS.Tables("input").AsEnumerable() On xmlinput.Item("controller_Id") Equals xmlcontroller.Item("controller_Id")
Join xmlport In _XMLRawDS.Tables("port").AsEnumerable() On xmlport.Item("input_Id") Equals xmlinput.Item("input_Id")
Join xmlnewseq In _XMLRawDS.Tables("newseq").AsEnumerable() On xmlnewseq.Item("port_Id") Equals xmlport.Item("port_Id")
Select New With
{
.input = xmlsystem.Field(Of String)("Input"),
.name = xmlsystem.Field(Of String)("Name"),
.id = xmlcontroller.Field(Of String)("id"),
.type = xmlport.Field(Of String)("type"),
.newseqtext = xmlnewseq.Field(Of String)("newseq_Text")
}
Dim _XMLCtrlsDT As DataTable = _XMLquery.copytodatatable()
However, the last line won't compile due to:
'copytodatatable' is not a member of 'System.Collections.Generic.IEnumerable(Of <anonymous type>)'.
Looks pretty much the same as the msdn one to me, but sure there's something quietly at work.. Did take a look at this, but I'm damned if I could get it to work...
msdn-Implement CopyToDataTable Where the Generic Type T Is Not a DataRow
not even confident that's the issue..
The XML is as below:
<!--
Configuration Remap file
-->
<mameconfig version="10">
<!--
############################################################
Define controller aliases, This just makes the controller names
a little easier to deal with for the rest of the file.
############################################################
-->
<controlleralias>
<id>Ultimarc Ultra-Stik Player 1</id>
<alias>U360 Player1</alias>
</controlleralias>
<controlleralias>
<id>WingMan Extreme Digital 3D</id>
<alias>Flightstick</alias>
</controlleralias>
<controlleralias>
<id>HID#VID_061C_PID_AA00#7_35df86d5_0_0000#</id>
<alias>Lightgun1</alias>
</controlleralias>
<!--
############################################################
This is the System Default section
It generally should be the FIRST system section in the cfg file
############################################################
-->
<system name="default">
<!-- put a controller element here to have it copied into ONLY this particular
system element
-->
<controller id="U360 Player1">
<input>
<port type="P1_JOYSTICK_UP">
<newseq type="standard">JOYCODE_YAXIS_UP_SWITCH</newseq>
</port>
<port type="P1_JOYSTICK_DOWN">
<newseq type="standard">
JOYCODE_YAXIS_DOWN_SWITCH
</newseq>
</port>
</input>
</controller>
<controller id="Flightstick">
<input>
<port type="P1_SELECT">
<newseq type="standard">JOYCODE_BUTTON_7</newseq>
</port>
<port type="START1">
<newseq type="standard">JOYCODE_BUTTON8_SWITCH</newseq>
</port>
</input>
</controller>
<!-- this keyboard section provides a way to specify keyboard input
mappings that should ALSO be made for the specific port types. -->
<controller id="keyboard">
<input>
<port type="P1_JOYSTICK_UP">
<newseq type="standard">KEYCODE_UP</newseq>
</port>
<port type="P1_JOYSTICK_DOWN">
<newseq type="standard">KEYCODE_DOWN</newseq>
</port>
<port type="P1_JOYSTICK_LEFT">
<newseq type="standard">KEYCODE_LEFT</newseq>
</port>
<port type="P1_JOYSTICK_RIGHT">
<newseq type="standard">KEYCODE_RIGHT</newseq>
</port>
</input>
</controller>
<!--
###################################################
ACTUAL INPUT MAPPING STARTS HERE
DO NOT actually put anything in this section.
It is completely cleared and regenerated!
###################################################
-->
<input></input>
</system>
<!--
###################################################
This is a GAME specific section
Add additional <controller> sections here
to define how those controllers should map for this
particular game
###################################################
-->
<system name="ribbit">
<!-- This would be stupid to actually use, but as an example
For this game ("Ribbit"), reverse the UP and DOWN directions
on the joystick -->
<controller id="U360 Player1">
<input>
<port type="P1_JOYSTICK_UP">
<newseq type="standard">
JOYCODE_YAXIS_DOWN_SWITCH
</newseq>
</port>
<port type="P1_JOYSTICK_DOWN">
<newseq type="standard">
JOYCODE_YAXIS_UP_SWITCH
</newseq>
</port>
</input>
</controller>
<!--
###################################################
ACTUAL INPUT MAPPING STARTS HERE
DO NOT actually put anything in this section.
It is completely cleared and regenerated!
###################################################
-->
<input></input>
</system>
</mameconfig>
Which results in a Dataset of 7 tables (mameconfig, controlleralias, system,controller,input,port,newseq). All appear to have primary and foreign keys inserted by the import xml process.
Would appreciate any help. Really stuck on this one..

Spring Webflow - IllegalStateException when using multipart/form-data and file upload

I am trying to add file upload to my Spring Webflog form processing. As far as the form enctype is not set to multipart/form-data, form submition works just fine. But after I added enctype="multipart/form-data" to my Spring form, this Exception occurs:
java.lang.IllegalStateException: A flow execution action URL can only be obtained in a RenderRequest or a ResourceRequest
at org.springframework.webflow.context.portlet.PortletExternalContext.getFlowExecutionUrl(PortletExternalContext.java:215)
at org.springframework.webflow.engine.impl.RequestControlContextImpl.getFlowExecutionUrl(RequestControlContextImpl.java:178)
at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:189)
at org.springframework.webflow.engine.ViewState.render(ViewState.java:293)
at org.springframework.webflow.engine.ViewState.refresh(ViewState.java:242)
at org.springframework.webflow.engine.ViewState.resume(ViewState.java:220)
at org.springframework.webflow.engine.Flow.resume(Flow.java:537)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259)
at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
at org.springframework.webflow.mvc.portlet.FlowHandlerAdapter.handleAction(FlowHandlerAdapter.java:161)
at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:670)
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:520)
at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:461)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:71)
I have added CommonsMultipartResolver to my spring context:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- Limit uploads to one byte smaller than the server is allowed to handle -->
<property name="maxUploadSize" value="100000" />
</bean>
and have commons-fileupload.jar in my pom.xml:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
My JSP looks like this:
<portlet:actionURL var="processFormAction" >
<portlet:param name="execution" value="${flowExecutionKey}"/>
</portlet:actionURL>
<form:form action="${processFormAction}" modelAttribute="customerModel" enctype="multipart/form-data" method="post" >
<form:input path="firstName" cssClass="input-size-1 valid-required" />
<form:input path="lastName" cssClass="input-size-1 valid-required" />
<input name="avatar" id="avatar" type="file"/>
<input type="submit" name="_eventId_submit" id="send" value="Submit"/>
</form:form>
My flow.xml definition:
<view-state id="state1" model="customerModel">
...
<transition on="submit" to="submitFormActions"/>
</view-state>
<action-state id="submitFormActions">
<evaluate expression="portletAction.processForm(customerModel, flowRequestContext)" />
<transition on="success" to="state2"/>
<transition on="error" to="state1" />
</action-state>
The model object:
public class CustomerModel implements Serializable{
private String firstName;
private String lastName;
private MutlipartFile avatar;
...
//public getters and setters
}
Any thoughts what could be wrong? As I said, without enctype="multipart/form-data" the form processing works well.
Thanks
You are using org.springframework.web.multipart.commons.CommonsMultipartResolver which is not aware about the portlet context.
You need to change CommonsMultipartResolver to:
<bean id="portletMultipartResolver"
class="org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="100000"/>
</bean>
Also, for this bean to be recognised by DispatcherPortlet, you need to define this bean id as mentioned above. The doc says:
Any configured PortletMultipartResolver bean must have the following id (or name): "portletMultipartResolver".
If you have defined your PortletMultipartResolver with any other name, then the DispatcherPortlet will not
find your PortletMultipartResolver, and consequently no multipart support will be in effect.

Enunciate Data Model Documentaton

I'm using Enunciate on a multi module maven project. I use version 1.28 and I just use it for documentation purposes on SOAP Services.
This works just fine for all the Services.
The targetNamespace and endpointInterface has to be declared in the #WebService annotation and everything works fine. I got my zip with wsdl/wadl/xsd/html output.
All javadoc is recognized and published through the output files.
BUT...I would not write here if there is no but...
All data model files won't! I tried the following options:
<api-import pattern="package.model.**" />
<modules>
<spring-app disabled="true" />
<docs docsDir="/docs" title="Web Service API" copyright="ME" />
<!-- Disable all the client generation tools -->
<basic-app disabled="true" />
<c disabled="true" />
<csharp disabled="true" />
<java-client disabled="true" />
<jaxws-client disabled="true" />
<jaxws-ri disabled="true" />
<jaxws-support disabled="true" />
<jersey disabled="true" />
<obj-c disabled="true" />
<xml forceExampleJson="true" />
<jaxws disabled="true" />
<amf disabled="true" />
</modules>
module is not included in webarchive but declared as dependency:
<dependency>
<groupId>package.model</groupId>
<artifactId>model</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
The DTOs and ENUMS in the Data Model are normally provided with:
#XmlType(namespace = "https://package/DTO")
And Javadoc on class and attributes.
But I tried Javadoc on getters and setters too.
I even tried some xml annotation from the example implementation in my project:
#javax.xml.bind.annotation.XmlType(name = "socialGroup", namespace = "http://api.ifyouwannabecool.com/link")
#javax.xml.bind.annotation.XmlRootElement(name = "socialGroup", namespace = "http://api.ifyouwannabecool.com/link")
Without success. The javadoc won't be included in xsd/wsdl/html files as it does for the SOAP Services.
Do you have any idea?
If the classes are in a different Maven module, as you have declared in a dependency, you have to explicitly tell Enunciate to "import" them in order to get the JavaDoc included.
So let's pretend your model classes are in a package called "org.mycompany.widgets.model" and in a package called "org.mycompany.gadgets.model". Tell Enunciate to import those like this:
<enunciate ...>
...
<api-import pattern="org.mycompany.gadgets.model.**"/>
<api-import pattern="org.mycompany.widgets.model.**"/>
...
Please add #XmlRootElement on top of the class so that enunciate will make them appear in Data Model documentation.
Example :
#XmlRootElement
public class Foo{
....
}
I think the problem is <scope>provided</scope>. If the classes aren't present in the classpath, enunciate will not be able to find them. Change it to <scope>compile</scope>, along with the #XmlRootElement annotations and it should work.

I can't submit a form with Dojo DateTextBox

I'm working on a project with struts2 and dojo. Our dojo version is 1.4.x
I can't submit a form with DateTextBox control when my browser language is English.
However, when I change the local into other language like ZH_CN, it works.
I'm wondering why this would happen.
Here is my jsp code snippet:
<div id="projectForm" dojotype="dijit.form.Form">
<!-- end Date -->
<span class="manager_create_from_components">
<s:text name="manager.create.endDate"></s:text>
</span>
<input type="text" name="project.endDate" constraints="{datePattern:'yyyy-MM-dd'}" dojotype="dijit.form.DateTextBox"><br />
</div>
Thanks for you help.
HTTP Status 404 - No result defined for action
com.ternwit.tms.web.action.ManagerAction and result input.
This error is due to the fact you don't specified a result page in your struts.xml
<action name="actionName" class="package.yourClass" method="yourMethod">
<result name="success">successPage.jsp</result>
<result name="error">errorPage.jsp</result>
<result name="input">errorPage.jsp (or yourFormPage.jsp)</result>
</action>
Hope this helped
And about the dateTextBox, I have the same problem as you have. I think it's because of the value returned. Ex : "Wed Nov 16 2011 00:00:00 GMT+0100"