Allowing only digits in aui:form, with Liferay portlet-model-hints.xml - validation

My portlet-model-hints.xml below stipulates that quantity is required, that works fine.
Now I also want to stipulate that quantity must be made of digits:
<model-hints>
<model name="com.example.model.MyEntity">
[...]
<field name="order" type="long">
<validator name="required" />
<validator name="digits" /> <----- Does not work
</field>
[...]
</model>
</model-hints>
PROBLEM: Adding <validator name="digits" /> makes the text field disappear.
Is there a problem in my syntax? Should I do the validation in the JSP instead? By the way here is the JSP form to add/edit my entity:
<aui:form action="<%= editMyEntityURL %>" method="POST" name="fm">
<aui:fieldset>
[...]
<aui:input name="quantity" />
[...]
</aui:fieldset>
[....]
</aui:form>

[Workaround, I am still looking for a better solution]
Not elegant at all, but moving digits validation to the JSP works:
<aui:form action="<%= editMyEntityURL %>" method="POST" name="fm">
<aui:fieldset>
[...]
<aui:input name="quantity">
<aui:validator name="digits"/>
</aui:input>
[...]
</aui:fieldset>
[....]
</aui:form>
It must be done in all JSP forms that use the entity.

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:"/>

Added orderable=true to Liferay search container, controls appeared but order does not change

I have written a Liferay search container, it works great.
Now I want columns to be sortable by alphabetical order, so I added orderable="true":
<liferay-ui:search-container
<liferay-ui:search-container-results
results="<%= BicycleLocalServiceUtil.getBicyclesByCompanyId(
themeDisplay.getCompanyId()) %>"
total="<%= BicyleLocalServiceUtil.getBicyclesCount() %>" />
<liferay-ui:search-container-row
className="com.example.portal.portlet.navigation.model.Bicycle"
keyProperty="bicycleId"
modelVar="bicycle"
escapedModel="<%= true %>">
<liferay-ui:search-container-column-text
name="name"
property="name"
value="<%= bicycle.getName() %>"
orderable="<%= true %>"
/>
<liferay-ui:search-container-column-text
name="nickname"
property="nickname"
orderable="<%= true %>"
/>
<liferay-ui:search-container-column-jsp
align="right"
path="/html/bicycle/bicycle_actions.jsp" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
The results looks good: but when I click on the name or any of the small arrows, the order of the rows below does not change.
Am I missing something?
I don't need any custom comparator as the value are simple Strings such as "Bob" and "Joe".
You need to specify the oderableProperty:
<liferay-ui:search-container-column-text
name="nickname"
property="nickname"
orderableProperty="nickname"
orderable="<%= true %>"
/>

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.

Do I need separate Struts Action for each form?

Do I need separate Struts action for each form?
Currently, one web page have two forms in jsp. I currently put all validation code in validate() in the Action class. The problem is that it appears the net result is that Form A will then be linked to Form B and vice versa since the validation code is inside the same Action class.
So am I correct that if I want the two forms to be validated independently, then I would require two separate Actions?
Form A:
<font color="red" size="2"><s:actionerror /> <s:fielderror /></font>
<s:form action="NewcreateUser" method="post">
<s:textfield type="text" name="form1filed" key="temp" size="11" label="Mobile_Num" required="true"></s:textfield><br />
<s:submit value="Continue" id="continueSignUp" validate="true"></s:submit>
</s:form>
Form B:
<font color="red" size="2"><s:actionerror /> <s:fielderror /></font>
<s:form action="NewcreateUser" method="post">
<s:textfield type="text" name="form2filed" key="formb" size="11" label="Mobile_Num" required="true"></s:textfield><br />
<s:submit value="Continue" id="continueSignUp" validate="true"></s:submit>
</s:form>
Here You can validate your fields,both form1filed,form2filed with the same Action class
NewcreateUser,And the NewcreateUser-validation.xml file looks like this,
<field name="form1filed">
<field-validator type="required" short-circuit="true">
<message key="form1filed Is Required" />
</field-validator>
</field>
<field name="form2filed">
<field-validator type="required" short-circuit="true">
<message key="form2filed Is Required" />
</field-validator>
</field>

Separation of forms & also drop down menu alteration when object selected

In the image provided of my registration page, I wish to put a vertical separator inbetween the form on the left to have another form on the right to be completed for the registration but I have no idea how to do it.
http://puu.sh/1FJIA
Also the second part of my question pertains to the drop down menu, how would I put an extra option other than #_usergroups that when selected will alter the drop down menu to change into a text box? Below is the coding used for the xml.
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="default"
label="COM_USERS_REGISTRATION_DEFAULT_LABEL"
>
<field name="spacer" type="spacer" class="text"
label="COM_USERS_REGISTER_REQUIRED"
/>
<field name="name" type="text"
description="COM_USERS_REGISTER_NAME_DESC"
filter="string"
label="COM_USERS_REGISTER_NAME_LABEL"
message="COM_USERS_REGISTER_NAME_MESSAGE"
required="true"
size="30"
/>
<field name="username" type="text"
class="validate-username"
description="COM_USERS_DESIRED_USERNAME"
filter="username"
label="COM_USERS_REGISTER_USERNAME_LABEL"
message="COM_USERS_REGISTER_USERNAME_MESSAGE"
required="true"
size="30"
validate="username"
/>
<field name="password1" type="password"
autocomplete="off"
class="validate-password"
description="COM_USERS_DESIRED_PASSWORD"
field="password2"
filter="raw"
label="COM_USERS_REGISTER_PASSWORD1_LABEL"
message="COM_USERS_REGISTER_PASSWORD1_MESSAGE"
required="true"
size="30"
validate="equals"
/>
<field name="password2" type="password"
autocomplete="off"
class="validate-password"
description="COM_USERS_REGISTER_PASSWORD2_DESC"
filter="raw"
label="COM_USERS_REGISTER_PASSWORD2_LABEL"
message="COM_USERS_REGISTER_PASSWORD2_MESSAGE"
required="true"
size="30"
/>
<field name="email1" type="email"
description="COM_USERS_REGISTER_EMAIL1_DESC"
field="id"
filter="string"
label="COM_USERS_REGISTER_EMAIL1_LABEL"
message="COM_USERS_REGISTER_EMAIL1_MESSAGE"
required="true"
size="30"
unique="true"
validate="email"
/>
<field name="email2" type="email"
description="COM_USERS_REGISTER_EMAIL2_DESC"
field="email1"
filter="string"
label="COM_USERS_REGISTER_EMAIL2_LABEL"
message="COM_USERS_REGISTER_EMAIL2_MESSAGE"
required="true"
size="30"
validate="equals"
/>
<field name="title" type="sql"
default="-None Listed-"
label="Select your University"
description="Select the University you are currently attending, if
it's not on the list then create it below"
query="SELECT title FROM #__usergroups WHERE ID > '8 ' "
required="true"
/>
<field
name="captcha"
type="captcha"
label="COM_USERS_CAPTCHA_LABEL"
description="COM_USERS_CAPTCHA_DESC"
validate="captcha"
/>
</fieldset>
</form>
1. Vertical separator:
you can use a hack i.e. create some fields which will output markup.
The idea here is to insert an extra
<div style='width:50%'>
before the first field;
Then a
</div><div style='width:49%;border-left:1px dashed black'>
where you want the separator
and finally a at the end.
Create three new spacer fields.
You can either insert properly escaped html directly:
<field type="spacer" name="splitterinit" label="<div>" />
or put the html as language constants in the language file:
SPLITTER_MID="</div><div style='width:49%;border-left:1px dashed black'>"
and simply use the constant in the .xml:
<field type="spacer" name="splittermid" label="SPLITTER_MID" />
2. Extra text option:
Easy: Simply add a text field below to allow the user to type in.
Harder: Create a custom element, there you can write php and make it
as you want it
3. A word of advice
Chronoforms features a user registration override that lets you define all the fields you want, and for sure you'll find more similar extensions on the JED
Also, all community solutions feature custom profiles.

Resources