keyFilter remove special characters - primefaces

I am working with Primefaces inputMask and keyFilter
<p:inputMask inputStyleClass="#{(newDesWeb eq '_')? 'selectfile' : 'form-control lg200 input-sm'} errorCible"
id="zoneResidenceAssure" styleClass="#{(newDesWeb eq '_')? 'ng-pristine ng-invalid ng-touched' : ''} errorCible"
style="width: 100%"
value="#{devisPresBean.currentAssureDevisBean.adresseActuelle.zipCode}" maxlength="#{msg['form.control.input.codepostal.maxlength']}">
<c:ajax onevent="displayAjaxSatus" event="change" execute="#this" render="#this" />
<p:keyFilter regEx="[0-9]" for="zoneResidenceAssure" />
</p:inputMask>
How to remove speciale characters like "_" and "-" also '

It's not that well documented, but the p:keyFilter expects a JavaScript regular expression, as all the examples in the documentation start with /. So you need to use /[0-9]/ instead of [0-9].

Related

How to fix the Angular syntax parser error within a Struts 2 <s:checkbox> tag?

I have encountered a strange error using AngularJS + Struts 2.
I have a Java object form with a boolean attribute named paid.
When I write:
<div class="col-sm-10 form-checkbox">
<s:checkbox name="xxxxx" ng-model="model"
ng-init="model = <s:property value = '%{form.paid}' />"
theme="simple" />
</div>
I get FireBug complaining about AngularJS syntax parser error which directs me to this page:
syntax error page
suggesting expression error.
And if I write:
<div class="col-sm-10 form-checkbox">
<s:checkbox name="xxxxx" ng-model="model"
ng-init="%{form.paid}"
theme="simple" />
</div>
No error is reported. I guess it is because Struts tags begin with <, which is not welcomed in Angular.
But, with this line no error is reported:
<select ng-model="estadoId"
ng-init="estadoId=<s:property value='%{form.estadoId}'/>"
name="form.estadoId" id="form.estadoId"
value="<s:property value='%{form.estadoId}' />" >
So, AngularJS is complaining about <> in Struts 2? Or, I am nor permitted to use <s:...> inside another <s:...>? If the latter is the case, why is complaning Angular not Struts 2??
In the first snippet, you are nesting Struts tags, that is a syntax error:
<s:checkbox name="xxxxx"
ng-model="model"
ng-init="model = <s:property value = '%{form.paid}' />"
theme="simple" />
In the second one, you are doing it right with OGNL, but you omitted the model = part:
<s:checkbox name="xxxxx"
ng-model="model"
ng-init="%{form.paid}"
theme="simple" />
The right version is the mix of the two:
<s:checkbox name="xxxxx"
ng-model="model"
ng-init="model = %{form.paid}"
theme="simple" />
Otherwise you could use a raw HTML tag (as in your <select> example, that is a standard HTML tag and not an <s:select>, hence no tags nesting is happening):
<input type="check" name="xxxxx"
ng-model="model"
ng-init="model = %{form.paid}" />
Note: in that case, you should create an hidden parameter under each checkbox to emulate the <s:checkbox> tag behavior and make the Checkbox Interceptor happy.

Dynamically Creating list in Struts2 using tags

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(2012);
list.add(2013);
list.add(2014);
list.add(2015);
can we do same as above using struts2 tags. may be by using
<s:set name="myList" value={somedynamic values} />
actually I want to create a list of number of 10 years on JSP page using Struts2 tags.
Regarding to your question answer is yes,but that is not an good idea to create number of 10 years in jsp page.
However, this is using arrylist in dynamic way
     
<s:select label="Years" headerKey="-1" headerValue="Select Years" list="list" name="your desire name" />
in the place of list property you have to give arrayList variable in your case it is list
means,
<s:select ---- list="your array list variable" --------- />
     and you have to define this action name in struts.xml
   eg:
<action name="yourarrylistvariable" class="your class" method="your method">
<result name="success">your jsp page</result>
</action>
    
     This is using arrylist in static way here you have to change the list value 
<s:select label="Years" headerKey="-1" headerValue="Select Years"
list="#{'2000':'2000', '2013':'2013',.....}" name="your desire name" />
For More Info You can refer this link struts2 select
Sure you can, thanks to the OGNL you can create lists like so:
<s:set var="myList" value="{2012,2013,2014,2015}" />
See this link.

jstl split function

I wanted to split a given string using jstl 1.2
eg:
Bean thesis.url contains "http:website1.com : http:website2.com"
which needs to be splited into
http:website1.com
http:website2.com
<c:set var="url">
<c:out value="${thesis.url}" />
</c:set>
<c:set var="offUrls" value="${fn:split(url,' : ')}" />
<c:forEach items="${offUrls}" var="link">
<a href=" <c:out value='${link}' />" target="_blank">
<c:out value="${link}" />
</a>
</c:forEach>
But the output is not want I wanted which is
http
website1.com
http
website2.com
I tried another way, and its dint work either.
<c:set var="_split" value= " : "/>
<c:set var="offUrls" value="${fn:split(url,_split)}" />
fn:split will split your string on any of the delimiter characters, so in your case both space and :. The solution is to do a fn:replace first:
<c:set var="urls" value="http://website1.com : http://website2.com"/>
<c:set var="urls" value="${fn:replace(thesis.url, ' : ', '|')}"/>
Make sure to replace the separator with a character that is not present in your string, or else you will run into the same problem. Now you can use fn:split(urls, '|'), but it would be easier to use <c:forTokens/>:
<c:forTokens items="${urls}" delims="|" var="url">
${url}
</c:forTokens>
A better solution would be to simply do the work at the back end of your application and pass a list of strings to the front end.

How do i include jsp code in tags? See example

Like the topic says; How do I include ordinary jsp code in tags? (In my case liferay tags, but it could as well be html-tags)
Example:
<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
extended="<% if (noService==false) {
out.print("false");
}
%>">
Test panel
</liferay-ui:panel>
In the example i just want to insert "false" so the expression looks like the following:
<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
extended="false">
Test panel
</liferay-ui:panel>
This gives me a jasperException.. I´m used to PHP where this kind of code-includes are daily meat.
Can someone please point me in the right direction?
Thanks in advance!
<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
extended="${noService}">
Test panel
</liferay-ui:panel>
noService must be set in request e.g.:
java:
...
request.setAttribute("noService", false);
...
You can have (I'm using ELs, as they are much cleaner):
If variable noService is a boolean:
<c:set var="isExtended"><%=noService ? "true" : "false" %></c:set>;
<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
extended="${isExtended}">
Test panel
</liferay-ui:panel>
If variable noService is a String:
<c:set var="isExtended"><%="false".equals(noService) ? "false" : "true" %></c:set>
<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
extended="${isExtended}">
Test panel
</liferay-ui:panel>
You can also do this.
<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
extended="<%=String.valueOf(noService)%>">
You need to use a Bean
read this:
http://www.exampledepot.com/egs/javax.servlet.jsp/usebean.jsp.html

Struts 1 bean tag inside HTML quotes

Here is my code:
<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name="rptData" property="status" />' , this.id)" />
This is nested inside a logic:iterate tag. What i need to do, is to pass value of 'status' to the javascript checkIfEmpty method. But i guess there is some error in the quotes. It is not working properly. Please anyone guide me. Thanks.
You can't nest custom tags like that, period, and it's unfortunate most of the answers imply you can, because that represents a fundamental misunderstanding of JSP.
Ideally, you wouldn't use the <logic:iterate> tag, as its use is not recommended when you have JSTL available: when JSTL and Struts 1 tag functionality overlaps, use the JSTL option. Then use standard JSP EL to access the variable.
<c:forEach items="listOfThings" var="current">
...
<html:text ... onblur="checkIfEmpty('${rptData.status}', ${current.id})" ...
...
In this example I also assumed that this was supposed to refer to the current iteration object, defined in the <c:forEach> tag.
ok after doing some research i found out the answer.
if i have some code like this:
<html:text styleId="emailAddress+<%=statusC.toString() %>" name="rptData" property="emailAddress" />
its output is as follows:
<input type="text" name="emailAddress" value="abc#gmail.com" id="emailAddress+<%=statusC.toString() %>" />
but if i use
<html:text styleId="<%=statusC.toString() %>" name="rptData" property="emailAddress" />
the output is:
<input type="text" name="emailAddress" value="abc#gmail.com" id="Approved" />
That means without string concatenation the output is correct. i.e. only using
styleId="<%=statusC.toString() %>"
rather then
styleId="emailAddress + <%=statusC.toString() %>"
or even
styleId="emailAddress" + <%=statusC.toString() %> - This results in an error, though
yeilds correct output.
So the workaround is to first intialize a complete java String in a scriplet then use it inside the styleId tag.
<% String emailId = "emailAddress" + statusC.toString() ;%>
<html:text styleId="<%=emailId%>" name="rptData" property="newEmailAddress" />
It will work fine. Cheers !
You might want to try adding some escape characters while using double quotes inside double quotes like in your case it would be some like:
onblur="checkIfEmpty('<bean:write name=\"rptData\" property=\"status\" />' , this.id)"
Try this:
<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name=\'rptData\' property=\'status\' />' , this.id)" />