what error is in the code snippet below? - eclipse

I have the following jsp code which uses struts tag:
<input type = "radio"
id = "<s:property value="name"/>"
name = "<s:property value="name"/>"
value = "<s:property value="value"/>"
<s:if test="fieldValue==null">
<s:if test="defaultOption==true">
checked="checked"
</s:if>
</s:if>
<s:else>
<s:if test="value==fieldValue">
checked="checked"
</s:if>
</s:else>
/>
Eclipse says that:
Start tag (input) not closed properly, expected >.
But I cannot find where is the error. Please help.

It is probably an eclipse bug because with Netbeans there is no error
if you dont want to see the error with Eclipse (and in that case only) :
in the first if, put test like that :
fieldValue==null && defaultOption==true
and get rid of the internal if
it should be the same
PS : try to find a way to use s:radio maybe

Eclipse complains because it does not accept tags (for example <s:if>) inside input tag, you can deactivate JSP validation as suggested in comments .
Go to project properties and uncheck JSP Content Validator, then clean your project
If you don't want to disable validation, here is a suggested solution:
<s:if test="fieldValue==null">
<s:if test="defaultOption==true">
<input type = "radio" id = "<s:property value="name"/>" name = "<s:property value="name"/>" value = "<s:property value="value"/>" checked="checked" />
</s:if>
</s:if>
<s:else>
<s:if test="value==fieldValue">
<input type = "radio" id = "<s:property value="name"/>" name = "<s:property value="name"/>" value = "<s:property value="value"/>" checked="checked" />
</s:if>
</s:else>
Just as a note, your JSP code give same result(I guess it's just for illustration :) ).

Related

Excepted int for property "maxLength" of sap fiori Input component

Current I am trying to metadata binding xml, following this blog. When I did the maxLength of Input. But I got the following error.
error screenshot
demo service
init model with destination:
initModel: function() {
var sServiceUrl = "/odsrv/V2/Northwind/Northwind.svc/";
var oModel = new OM(sServiceUrl, true);
this.setModel(oModel, "oRefModel");
sap.ui.getCore().setModel(oModel, "oRefModel");
}
xml view:
<content>
<Label text="{oRefModel>/#Category/CategoryName/#type}"/>
<Input maxLength="{oRefModel>/#Category/CategoryName/#maxLength}"/>
</content>
The Label for type works fine if remove Input.
How to solve this problem...
Version with expression binding could be like that
<Input maxLength="{= isNaN(${oRefModel>/#Category/CategoryName/#maxLength}) ? 0 : parseInt(${oRefModel>/#Category/CategoryName/#maxLength})" />
typeof check is needed cause at the start of binding process value of property probably is 'NaN' and it gives an error and whole process will stop.
If you can improve that version please do :)
<Input maxLength="{parts:[{path:'oRefModel>/#Category/CategoryName/#maxLength'}],formatter: 'your.formatter.toNum' }" />
Formatter Code
toNum : function(maxlen){
return parseInt(maxlen);;
}
Converting string to integer is the key
Even shorter and without writing a custom formatter function: Use the built-in parseInt function.
<Input
maxLength="{
path: 'oRefModel>/#Category/CategoryName/#maxLength',
formatter: 'parseInt'
}" />
For some reasons expression binding does not work, maybe someone could tell me why:
<Input maxLength="{= parseInt(${oRefModel>/#Category/CategoryName/#maxLength}) }" />

JAX-RS, #FormParam display result in the same page

I have this program that I am coding, the main thing is mostly to get familiar with Jax-rs and rest API. I am sending from a form in JSP page one input and with POST I pass it to my java Response class(that I use annotation #FormParam), it does what calculation I need and then I get the result in another link, what can i do to take the result just below my button on the same page? For my button function I use javascript, and when I push it I don't want to be redirected and take the result like this.
So i use this form and a javascript function in my jsp to pass the value in my POST method in java throw #FormParam
<form name="Form1" method="post">
<p>
Name : <input type="text" name="malename" id="malename" autofocus
value="enter your name..." />
</p>
<input type="submit" name="action" id="malename" value="I'm feeling lucky"
onclick="OnButton1();"> </form>
function OnButton1() {
document.Form1.action = "webapi/perfectmatcher/mate"
document.Form1.target = "_self"; // Open in a new window
document.Form1.submit(); // Submit the page
//return;
}
Here after i have the value i use two other classes to do the calculations and return the result i need. In a few words i pass a value in my form and when i push the button i am redirected in another link(the path of POST) and i display the result. I want to display the result below my button. I hope the code is helpful and i hope i am clear with my explanation
#POST
#Path("/mate")
#Produces(MediaType.TEXT_PLAIN)
public Response postMaleName(#FormParam("malename") String malename) {
String femalename = NumMatcher.numMatcher(Numberizer.numberizer(malename));
// FemaleName female = new FemaleName(femalename);
female.setName(femalename);
System.out.println(female.getName());
return Response.status(200).entity("Perfect Match for " + malename + " is " + femalename).build();
}
P.S.:The object female that i am trying to create its for testing purposes, i was trying somehow to get the information that i store but i cannot find how!!I used even jsp expressions but i get null value of course ...
<%
FemaleName female = new FemaleName("john");
String string = female.getName();
out.print(string);
%>

Linking two jsp pages with Submit Button Liferay

I have a form where I allow user to select some data and submit the form and based on that selection data will be displayed in another jsp.
I have used the following code in first jsp:
<aui:form name="updateDailyAttendance" action = "<%=request.getContextPath()%> /admin/test.jsp" method="post" >
<input type = "date" name = "myDate"/>
<input type = "submit" name = "Submit"/>
</aui:form>
test.jsp is the second JSP. But the code above isn't working. How should I mention the second jsp name in the "action" above so that the above jsp takes me to second jsp. I am using lIferay
instead of passing a url as 'action', you should provide an actionUrl with the jsp page as param.
<portlet:actionURL var="actionName" name="yourMVCPortletFunctionName">
<portlet:param name="jspPage" value="/admin/test.jsp" />
</portlet:actionURL>
<aui:form name="updateDailyAttendance" action = "<%= actionName %>" method="post" >
<input type = "date" name = "myDate"/>
<input type = "submit" name = "Submit"/>
</aui:form>
then in Your Controller:
public void yourMVCPortletFunctionName(ActionRequest actionRequest, ActionResponse actionResponse){
throws PortletException, IOException
//Do your stuff
//Redirect
String redirectUrl = (String)request.getParameter("jspPage");
actionResponse.setRenderParameter("jspPage", redirectUrl);
}
This way you can have actions that do some standard stuff, like handling that "myDate" param, and have them redirect to other pages each time. So calling them from different points (different jsp page or form), will target ta a new redirect each time

Automatically update database with checkboxs that are unticked (false)

I currently update my database records with an input like this
$this->my_model->update($id, $this->input->post()));
(This is after I have performed a validation on all the input. The "model" also has a white_list of data to expect.)
Problem: if I am updating a checkbox, and it is "unticked" (i.e. 'false') - then that field is not 'posted' by the browser.
For example - if I tick checkbox_two - but leave checkbox_one unticked, $_POST shows:
[field_one] = "some value"
[field_two] = "some value"
[checkbox_two] = 1
Therefore my model will not update that field - since it is not part of the post.
The same does not happen in reverse - because a "ticked" checkbox is posted as "1" - and thus is correctly updated.
[field_one] = "some value"
[field_two] = "some value"
[checkbox_one] = 1
[checkbox_two] = 1
Question: Does anyone have an elegant solution to handle this, other than having to always specifically check for each checkbox?
<input type="hidden" name="example" value="FALSE" />
<input type="checkbox" name="example" value="TRUE" />
This practice is easy and logical. If checkbox is checked, $this->input->post('example') == 'TRUE' else, $this->input->post('example') == 'FALSE'.
The latest given value of a name="" overrides previous, thus givin prio checkbox > hidden.
EDIT: this solution is equal to given most rated answer in Rick Calder's comment. I've also come to this conclusion on my own, though.

(Lift) Ajax submit using SHtml.select onchange event

I'm tring to implement the classic functionality of this select:elements depends on this other select:selection using Lift, E.g. select the country and get the possible states for the selected country.
The problem that I'm facing is that the "this.myForm.submit()" that I have inside the onchange of the select element is not firing the ajax request. If I use an input type"submit" it works perfectly.
Is this behaivior related with Lift framework? Is there a better way of implementing this kind of functionality using Lift libraries?
The relevant snipped code:
"name=distributionPoints" #> SHtml.select(distributionPoints, Empty, selectedDistributionPoint = _, "id" -> "the_distributionPoints") &
"name=devices" #> (SHtml.select(devices, Empty, selectedDevice = _, "id" -> "the_devices") ++ SHtml.hidden(process))
The view html:
<form class="lift:form.ajax">
<select name="distributionPoints" id="the_distributionPoints" onchange="submit()">
<option></option>
</select>
<br/>
Device:
<select name="devices" id="the_devices">
<option></option>
</select>
</form>
The rendered HTML:
<form id="F391649920812YBACEZ" action="javascript://" onsubmit="liftAjax.lift_ajaxHandler(jQuery('#'+"F391649920812YBACEZ").serialize(), null, null, "javascript");return false;">
<div>
Punto de distribuciĆ³n:
<select onchange="submit()" id="the_distributionPoints" name="F630704816482OLP514"></select>
<br />
Equipo:
<select name="F391649920817BLRJW5" id="the_devices"></select><input type="hidden" name="F391649920818HPS35E" value="true" />
<br />
</div>
</form>
[edit]
I finally got the solution. Like Chris mentioned I used ajaxSelect instead of just selects and instead of using setHtml there's a method called JsCmds.ReplaceOptions that does exactly what I was looking for.
You should understand that when using Ajax submit the page is not reloaded. So I would suggest you to use JsCmds.setHtml on server side to "reset" the second select element.
So, in fact the first select is an ajaxSelect which is meant to modify the second one (so it is not concerned by the hidden submit in my opinion). The second select is updated when the first one is changed, using 'selectPoint(s)'
Piece of Scala code
def selectPoint(s):JsCmd = {
selectedDistributionPoint = s;
newDevices:List[String] = findCorrespondingDevices(s);
JsCmds.setHtml("name=devices", SHtml.select(newDevices, Empty, selectedDevice = _, "id" -> "the_devices")) ++ SHtml.hidden(process))
}
"name=distributionPoints" #> SHtml.AjaxSelect(distributionPoints, Empty, s=> selectPoint(s), "id" -> "the_distributionPoints") &
"name=devices" #> (SHtml.select(Nil, Empty, selectedDevice = _, "id" -> "the_devices") ++ SHtml.hidden(process))
Piece of template code
<input name="distributionPoints" id="the_distributionPoints" onchange="submit()"/>
<input name="devices" id="the_devices"/>