I'm mistified why a checkbox would show up disabled.
What do I need to do to enable it?
Already tried using String object for the requestInvoice property, does not help.
JSP:
<fieldset class="aa-list-primary-indent">
<label class="custombox-wrapper custombox" data-behavior="custombox">
<div class="control checkbox"></div>
<html-el:checkbox styleId="requestInvoiceCheckbox" property="form(creditCardForm).personalId.requestInvoice" />
In need of an invoice (factura)
</label>
</fieldset>
Form:
private boolean requestInvoice = false;
public boolean isRequestInvoice() {
return requestInvoice;
}
public void setRequestInvoice(boolean requestInvoice) {
this.requestInvoice = requestInvoice;
}
HTML generated by the browser (Chrome):
<input type="checkbox" name="form(creditCardForm).personalId.requestInvoice" value="on" id="requestInvoiceCheckbox">
Sorry, it's a bad question.
The CSS setup makes the checkbox look disabled, even though it is not. Bad CSS design.
All the JSP/Java/HTML code above is fine.
Related
Action:
public class TuAction() extends ActionSupport{
private boolean loseItemFlg=false;
private String doFuilureOrder(){
if(...){
loseItemFlg=true;
}
return SUCCESS;
}
public boolean isLoseItemFlg() {
return loseItemFlg;
}
public void setLoseItemFlg(boolean loseItemFlg) {
this.loseItemFlg = loseItemFlg;
}
}
And my Jsp:
function dialogOpen(formName,actionName){
if(comfirm("do you want do this?")){
....
document.forms[formName].action=actionName;
document.forms[formName].submit();
}else{
//i want do not reload the page.
}
}
<input type="button" disable="%{loseItemFlg}" value="lose"
onclick="dialogOpen('tuAction', '<%request.getContextPath()%>/tuAction_doFuilureOrder.action')"
/>
But this code the button's disable property is not by my control!!
Then i change the jsp to:
<s:submit type="button" disable="%{loseItemFlg}" value="lose"
onclick="dialogOpen('tuAction', '<%request.getContextPath()%>/tuAction_doFuilureOrder.action')"
/>
Now the button's disable property is by my control,but the "doFuilureOrder()" is not by used.
About do not reload the page should do what in my jsp.
My English is terrible,And this is my first time to use the stackoverflow. Someone know what I means.
For the input tag, disabled property is not based on true/false. When u write disabled attribute then the input is disabled by default, Please check Fiddle
<input type ='button' disabled='true' value='Button1'/>
<input type ='button' disabled='false' value='Button2'/>
In above code, both buttons is in disabled state.
For your purpose we can rewrite your code as:
Method 1:
By using struts if tag
<s:if test="%{loseItemFlg}"> // if true - button disabled state
<input type="button" disabled value="lose" onclick="dialogOpen('tuAction','<%request.getContextPath()%>/tuAction_doFuilureOrder.action')"/>
</s:if><s:else> //button enabled
<input type="button" value="lose" onclick="dialogOpen('tuAction','<%request.getContextPath()%>/tuAction_doFuilureOrder.action')"/>
</s:else>
Method 2:
Rewrite your java code as,
private String loseItemFlg='';
private String doFuilureOrder(){
if(...){
loseItemFlg="disabled";
}
return SUCCESS;
}
public String getLoseItemFlg() {
return loseItemFlg;
}
public void setLoseItemFlg(String loseItemFlg) {
this.loseItemFlg = loseItemFlg;
}
then in jsp :
<input type = "button"
<s:property value="%{loseItemFlg}"/> value="lose" onclick = "dialogOpen('tuAction'),'<%request.getContextPath()%>/tuAction_doFuilureOrder.action')" />
You can't nest scriptlet in Struts tags (like in your second case), while you can (but you should NOT, because using scriptlets is a bad-practice) inject them in HTML tags.
You can then use the <s:property /> tag in the HTML tag (first case)
<input type = "button"
disable = "<s:property value="%{loseItemFlg}"/>"
onclick = "dialogOpen('tuAction'), '<%request.getContextPath()%>/tuAction_doFuilureOrder.action')"
/>
, or substitute the scriptlet in your Struts tag (second case), better using the <s:url /> tag to mount the URL:
<s:url action = "tuAction_doFuilureOrder.action"
namespace = "/"
var = "myUrl"
/>
<s:submit type = "button"
disable = "%{loseItemFlg}"
onclick = "dialogOpen('tuAction'), '%{myUrl}')"
/>
they both work.
The <s:url /> usage can (and should) be applied to the first case too:
<s:url action = "tuAction_doFuilureOrder.action"
namespace = "/"
var = "myUrl"
/>
<input type = "button"
disable = "<s:property value="%{loseItemFlg}"/>"
onclick = "dialogOpen('tuAction', '<s:property value="%{#myUrl}"/>')"
/>
I am using jquery validation plugin for validating my form data ,I have a fileupload element and then a button ,which opens browsing window to select file, as default error message is displayed between fileuplad element and button,I want to display this error message after button. I have tried many syntax as other similar question available on StackOverflow but none of them worked for me.
My jsp code is:
<tr>
<td>Browse Query File:</td>
<td>
<span id="input_span" style="background-color: red">
<INPUT type="text" id="inputfilepath" name="inputfilepath" placeholder="Query File" autocomplete='off' class="text" readonly="true" onclick="hidehint();" style="margin-left: 10%">
<input type="file" name="upFile" id="upFile" class="file" onchange="return do_upload(this.value);"/>
<input type="button" value="Browse" class="content_button2" onclick="do_click();"/>
</span>
<span id="error_span"> </span>
</td>
</tr>
I want my error message to be displayed in span having id-"error_span" on after it.
I have tried suggested code as:
errorPlacement: function(label, element)
{
if(element.attr("name") === "inputfilepath")
{
alert("call");
error.appendTo($('#error_span'));
}
else
{
error.insertAfter(element);
}
},
I also tried:
error.appendTo(element.parent("span").next("span"));
But it did't work for me.
rules: {
//rule stuff
}
groups: {
fileUpload: "upFile upButton"
},
errorPlacement: {
function(error, element) {
if(element.attr("name") == "upFile") {
error.insertAfter("#upButton");
} else {
error.insertAfter(element);
}
}
Be sure and give your button the name "upButton" for this to work.
You are basically saying you want to group those elements, and the error placement says, in the event that there is a validation error on the upFile, you want that error message to display after the upButton element.
Onclick of a form button, I need to call a small javascript function. This javascript function should validate some fields in the same form and then call the onSubmit() of the form which is in java.
Main Idea is that let validate happen in client side and not in java.
Complete idea :
I have help.html file as shown below :
<form wicket:id="form">
<input type="text" wicket:id="one"/>
<input type="text" wicket:id="two"/>
<input type="submit" wicket:id="save"/>
</form>
In help.java, I created a WebMarkupContainer and added this form with this submit button :
container.add(new Button("save") {
#Override
public void onSubmit() {
//saved
}
});
On click of the button in html, it calls onSubmit() and here we can do a validation on the text box values.
But I need to do all the validations in the HTML page itself.
OnClick of the Button Save, it should call a javascript funciton as shown below :
<form wicket:id="form">
<input type="text" wicket:id="one"/>
<input type="text" wicket:id="two"/>
<input type="submit" wicket:id="save" onclick="validateRange()"/>
</form>
JavaScript :
function validateRange(){
//logic
//Submit the form
}
Can this be done?
You need an AjaxSubmitLink or something like this. The you need to create a new IAjaxCallListener
public class MyAjaxCallListener implements IAjaxCallListener{
#Override
public CharSequence getBeforeHandler(Component component) {
return YOUR_JAVA_SCRIPT;
}
#Override
public CharSequence getBeforeSendHandler(Component component) {
return YOUR_JAVA_SCRIPT;
}
// ... not needed overrides can return null
}
Then in your AjaxSubmitLink you can add this AjaxCallListener
#Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new MyAjaxCallListener());
}
Here you have an example Try if yourself
HTML:
<form id="form" action="#">
<input id="text" type="text"/>
<input type="button" onclick="validate()" value="TEST"/>
</form>
JS:
function validate() {
var value = document.getElementById("text").value;
if (value == "") {
alert("you have to write something");
return false;
}
else
document.getElementById("form").submit();
}
I have an html form containing a check box & a ListView containing some text fields. On checking the checkbox i want the textfields to be disabled & vice versa.
I am using checkbox with AjaxFormComponentUpdatingBehavior. But its not setting the textfields as enabled/disabled. Below is the code snippet -
Checkbox.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
#Override
protected void onUpdate(AjaxRequestTarget target) {
listView.setEnabled(!Checkbox.getModelObject());
listViewContainer.addOrReplace(listView);
listViewContainer.setOutputMarkupId(true);
target.addComponent(listViewContainer);
}
});
HTML is -
<form wicket:id="geoForm">
Checkbox: <input type="checkbox" wicket:id="unmanagedChk" />
<div id="listViewContainer" wicket:id="listViewContainerId">
<div wicket:id="customGeoForChannel">
<div>
Latitude(decimal):
<input type="text" wicket:id="lat" maxlength="18" />
</div>
<div>
Longitude(decimal):
<input type="text" wicket:id="lon" maxlength="19" />
</div>
<div>
Radius(miles):
<input type="text" wicket:id="radius" maxlength="3" />
</div>
</div>
</div>
</form>
geoForm --- Form
customGeoForChannel --- ListView
lat, lon, radius --- textfields
unmanagedChk --- checkbox
Your listViewContainer has to write out its markup id before you update it via ajax. Do this immediately when you construct it!
listViewContainer.setOutputMarkupId(true);
BTW the following is superfluous, since the listView is already contained in the component tree (at least I hope you added it already):
listViewContainer.addOrReplace(listView);
I added the listviewcontainer to the form & added the form to the target as below. This solved the issue.
protected void onUpdate(AjaxRequestTarget target) {
listView.setEnabled(!Checkbox.getModelObject());
listViewContainer.addOrReplace(listView);
listViewContainer.setOutputMarkupId(true);
target.addComponent(listViewContainer);
form.add(listViewContainer);
target.addComponent(form);
}
#inputText(
signupForm("email"), '_label -> "Email",
'_help -> "Enter a valid email address."
)
How would I write this in pure html?
I have no idea how i add the value to the signupForm, so that I can use it in my controller with bindfromRequest() (in html)
Edit:
I normally used this approach
final static Form<User> signupForm = form(User.class);
and the the binding process
Form<User> filledForm = signupForm.bindFromRequest();
and my rendered form looks like this:
<div class="control-group ">
<label class="control-label" for="email">Email</label>
<div class="controls">
<input type="text" id="email" name="email" value="" >
<span class="help-inline"></span>
</div>
</div>
And this worked for me I was just curious how to use pure html, so I could create my own little helpers.
Edit2:
public static Result blank() {
return ok(form.render(signupForm));
}
and in the template itself
#(signupForm: Form[User])
Edit 3:
I don't know if this helps but the helper looks like this. (for the inputtext)
I just have no idea what this means, scala looks really cryptic to me.
#(field: play.api.data.Field, args: (Symbol,Any)*)(implicit handler: FieldConstructor, lang: play.api.i18n.Lang)
#input(field, args:_*) { (id, name, value, htmlArgs) =>
<input type="text" id="#id" name="#name" value="#value" #toHtmlArgs(htmlArgs)>
}
Use your browser to check the source coderendered by Play and copy/paste the HTML into your template.
In general the most interesting for you is proper inserting value to the manually created field:
<input type="text" name="email" value='#signupForm.field("email").value' />
It's also important to set the proper name attribut otherwise filling Form in controller will fail.
Edit:
Of course in blank action your signupForm is empty so that's normal that there's no value, in next action let's name it saveBlank, you need to fill the form with request's data, validate and save. If there are errors in form you need to render form.scala.view again with data binded to the form from previous request:
public static Result saveBlank(){
signupForm = signupForm.bindFromRequest();
if (signupForm.hasErrors()){
return badRequest(form.render(signupForm));
}
User user = new User();
user = signupForm.get();
user.save();
return ok("user saved);
}
of course if you'll want to edit existing user, you have to prefill it with data from DB ie:
public static Result edit(Long id){
signupform = signupForm.fill(User.find.byId(id));
return ok(form.render(signupForm));
}
(note: I wrote it just from top of my head, so check pls if there are no typos or errors)
Finally you don't need to use Form object in every case, you can also use DynamicForm:
public static Result saySomething(){
DynamicForm df = form().bindFromRequest();
return("you entered :" + df.get("email"));
}
or even in one line:
public static Result sayShorter(){
return("you entered :" + form().bindFromRequest().get("email"));
}