I have to disable one input text field based on some condtions. Below is the code.
<h:inputText maxlength="14" id="adjusAuthAmt"
value="#{Budget.fundCodeVO.adjustedAuthorizedAmount}"
disabled="#{!Budget.enableBudgetAmt || Budget.controlRequired || Budget.fundCodeVoidProtect}"
onchange="javascript:isFormChanged()" onblur="this.value=validateAmountCurrency(this.value,this.id,11);javascript:selectOne=true;javascript:fileSavedFlag=false;"
/>
Here, Budget.enableBudgetAmt is false now. But it still showing in editable mode.
Requirement is If the boolean variable enableBudgetAmt is false then i have to disable this input field.
Please tell me what is the simple thing that i missed here...
Thanks in Advance...
Related
Hello I have to disable checkbox in spring html form and pass the checked value to controller. I use the below code, but the problem is that I am not able to pass the checked value to controller when the disabled attribute is set to true
<form:checkbox path="agreementCats" disabled="true" value="${x.value}" class="category-checkboxes" id="agreementCat-cb-${i.index}" /><label class="control-label" for="agreementCat-cb-${i.index}"> ${x.label}</label>
<form:hidden path="agreementCats" value="${x.value}" />
The above code sends all the values to controller. Please help!!
in HTML have two tag with similar meaning but different context is Disabled and ReadOnly.
disabled: Disabled the input in the form and the data isn't in form query.
readonly: Omit the user UI interaction but the input is in form query.
Try use readonly tag instead disabled, I hope this help you.
That solution works for all inputs except checkbox... Checkbox can't use readonly, but you can do a little trick, is a dirt trick, but it can you help to not permit user touch check box.
If you know in server side what checkbox can be edited, try this code:
<input type="checkbox" <c:if test="condition">onclick="return false;"</c:if> ></input>
That code not permit user click the checkbox if the condition is true. Maybe with this can solved your problem.
Instead of disabled="true" change it to readonly= "true"
Disabled doesn't send a value if you insert but readonly does.
I am working on Spring MVC application and I am having a problem of getting the value of the check box when it is disabled.
in report.jsp page :
<form:checkbox type="checkbox" path="corporateColumn" id="corporateColumn" value="true" checked="checked" disabled="true" />
in ReportForm.java :
boolean corporateColumn ;
public boolean isCorporateColumn() {
return corporateColumn;
}
public void setCorporateColumn(boolean corporateColumn) {
this.corporateColumn = corporateColumn;
}
In ReportController.java ;
boolean corporateColumn = reportDTO.isCorporateColumn(); // this evaluates to false
//Which expected as true when corporateColumn checkbox is checked
Everything works fine unless it is used as disabled="true" (/ disabled="${'true'}") for checkbox field.
I had the similar issue previously also when getting the value of a disabled textfield and overcome it by making the field readonly.
So I am not sure in Spring MVC whether it is not possible to get the value of input field when it is disabled.
Any guidance would be really appreciated.
Thanks!
It's sorry to say that but that's impossible.
Use developer tool(like in Chrome) to check posted data, you can confirm browser will not send your checkbox's data if it's disabled or unchecked.
Why don't you simply use 'readonly' instead of 'disabled'?
Disabled field data is not passed on to server.
What is the best approach to disable a commandButton if the fields with required=true are not filled with values?
The button should be disabled on first page load, and only be enabled in case all required fields are fields with values.
By best approach i mean no javascript and minimum-code :-)
In addition it would be excellent if the commandButton is only enabled when all validators evaluate to true.
Using PF 3.2
EDIT
by best approach i also mean, it should only be evaluate on client-side
This is not possible for two reasons.
For client side validation, you would definitely require javascript.
The required attribute of components is stored server side ONLY, the client has no idea of which fields are required by default.
Without using required, you could achieve this in client-side as following. validateContent should contain the logic to disable the commandButton.
<h:inputText value="#{bean.text}" >
<pe:javascript event="keyup" execute="validateContent();"/>
</h:inputText>
If going to server is okay, then you could do this:
<h:inputText id="test1" value="#{bean.text}" required="true" immediate="true">
<f:ajax listener="#{bean.makeDisable()}" render="test2" />
</h:inputText>
</h:commandButton id="test2" value="commandButton1" disabled="#{bean.disable}" />
And in the bean:
private String text;
private boolean disable;
// setter & getter of text
public boolean isDisable()
{
return disable;
}
public void makeDisable(AjaxBehaviorEvent event)
{
if(text == null || text.equals(""))
this.disable=true;
else
this.disable=false;
}
This basically will load the commandButton disabled on initial load and it will only be enabled on entering any value in text field.
It is possible but I would hardly call it the "best way".
You would need to supply an ajax tag for change events on each field. Each field would have to be immediate to skip initial validation and process will need to be set to #this.
In an event listener you can check if values exist for each of the required fields and if so then set a boolean field that determines if the commandButton is disabled or not.
These ajax tags will need to render #this as well as the commandButton.
But even then there is a LOT of Javascript actually going on, just none that you would have to write directly.
I've seen BalusC's page on passing values to a validator but that is using inputText components. I'm using rich:inplaceInput components and it doesn't seem to work. Can someone tell me if it is possible, and if it is how to do simply?
Thanks
For sure you can add validators to rich:inplaceEdit.
Here is an example:
<rich:inplaceEdit required="true" value="#{myBean.name}">
<f:validateLength minimum="3" maximum="25" />
</rich:inplaceEdit>
This validates that the field is filled in (required="true") and that the entered text has a length between 3 and 25 characters ().
If you don't see any error message make sure you have a message component that displays your error message and that is properly updated.
I have a form which, when the button gets clicked by a user, redirects to another page, but when I simulate the click with javascript, the redirect fails. Tha ajax calls are exactly the same (except for the javax.faces.ViewState, but have different results.
The form looks something like:
<h:form id="form" onkeypress="trapEnter(event);">
<h:outputText value="Number" />
<h:inputText value="#{form.number}" />
<a4j:commandButton id="act" value="Go" action="#{form.go}" />
</h:form>
The javascript function:
function trapEnter(evt) {
// cut out to save space
if (keycode == 13) {
document.getElementById('form:act').click()
return false;
} else {
return true;
}
}
When I enter 3 into the text input box and click Go, the page is redirected as expected to the target returned by #{form.go}.
When I enter 3 into the text input box and press enter, #{form.go} is called correctly but the page is NOT redirected.
In both cases form.go is called correctly and returns the correct value for the redirection. Could anyone tell me why the javascript click() does not work, and if I'm doing something completely wrong, please tell me how to do it right.
I'm using Firefox 3.5 if that makes a difference.
Thanks.
The a4j:commandButton generates a button element with a bunch of JavaScript to fire an ajaxical request. Your functional requirement however ("redirect page") can be as good done with a "plain vanilla" h:commandButton. So I would use that instead.
You however don't need to return true or false from the keypress. Rewrite your function as follows:
function trapEnter(event) {
if (event.keyCode == 13) document.getElementById('form:act').click();
}
That's all (yes, detecting the enter key is browser independent).
return false; prevents from redirection.
I never did find out why this didn't work. As far as I know, it still doesn't work.
However, after asking the same question in the JBoss community forum, there is a different way to achieve this in richfaces:
<rich:hotKey selector="#form" key="return" handler="document.getElementById('form:act').click();"/>
this is included in the page to which it applies. This works.