How to make a check box editable - xpages

Domino 8.5.3 FP5, Designer 9.0.1.
I have an empty xpage containing only the following checkbox. I am not able to make it editable. It show the right value, but appear as disabled.
<xp:checkBox text="Label" id="checkBox1" uncheckedValue="true"
checkedValue="false"
value="#{javascript:jBeanConfigSupport.validationEnabledTxt}">
</xp:checkBox>
If I remove the binding to Java bean, all run fine. This is the Java bean code (part)
private boolean isValidationEnabled=true;
public String getValidationEnabledTxt() {
return String.valueOf(isValidationEnabled);
}
public void setValidationEnabledTxt(String onOff) {
isValidationEnabled=Boolean.parseBoolean(onOff);
}
public void setValidationEnabledTxt(boolean onOff) {
isValidationEnabled=onOff;
}
Where Am I wrong?

You're binding using SSJS, so instead of binding to the validationEnabledTxt property of your bean, the result of jBeanConfigSupport.validationEnabledTxt is being used to determine what it should be bound to. value="#{jBeanConfigSupport.validationEnabledTxt}" should work to map to the getter and setter.

Francesco,
You need to have a working setter method for this to be editable. In your case there is probably a problem with the setValidationEnabledTxt() method that is causing the field in the UI to be readonly.
Try adding "this" to your code so that it reads this.isValidationEnables = Boolean.parseBoolean(onOff);

Related

PanelBox disclosed attribute not works

PanelBox component has set the disclosed attribute to "false".
When I disclose one child, after re-logging the entire panel box is disclosed.
If everything is disclosed and I set one child to close, after re-logging everything is closed.
I need PanelBox closed each time I go to that page or log into app.
Maybe it's connected with MDS, but I do not know which configuration should be used for this particular situation.
I use ADF 11 R1, JSF 1.2 and WebLogic server.
edit
I can show this sample:
<af:panelBox text="#{row.date} - #{row.name}" id="pb1"
styleClass="AFStretchWidth" disclosed="false"
type="flow">
Bind the disclosed value in your Bean
<af:panelBox text="#{row.date} - #{row.name}" id="pb1"
styleClass="AFStretchWidth" disclosed="#{MyBean.isPanelClosed}"
type="flow">
In your java code
// Bean Constructor or your custom action listner or action
public MyBean(){
ADFContext.getCurrent().getSessionScope().put("myFlag",true);
}
private boolean panelClosed=false;
// Setter and getter
public void setPanelClosed(boolean panelClosed) {
this.panelClosed= panelClosed;
}
public boolean isPanelClosed() {
boolean tempFlag=false;
if(null!=ADFContext.getCurrent().getSessionScope().get("myFlag"))
tempFlag=(boolean)ADFContext.getCurrent().getSessionScope().get("myFlag");
return tempFlag;
}

JSF 1.1 - How to get the ID attribute of h:selectBooleanCheckbox in backing bean

So, here is the jsf component:
<h:selectBooleanCheckbox id="cb#{index}" value="backingBean.value" />
And here is a part of the backing bean java:
/**
* getValue is a method which checks if a checkbox is selected or not, using the checkbox ID
*/
public boolean getValue() {
//TODO: get the checkbox id
String checkboxID = ??
if (getCheckedIDs().contains(checkboxID)) {
return true;
}
return false;
}
When the page is loading the checkboxes, I want to check this way if the checkbox is selected or not.
So the question is, what to write instead of ?? to get the ID of the checkbox who called the method?
It's very important that I can use only JSF 1.1, so there are many solutions which won't work with this version.
EDIT: as #Kukeltje correctly notes, the main issue is that the value expression is incorrect. Once you change that, the below is applicable.
You don't need to "calculate" the value ("set" or "unset") of your checkbox. JSF will simply call backingbean.setValue(x) (with x being true or false) depending on whether the checkbox is on or off at that moment (i.e. when you submit the page).
This happens automatically because you said value="#{backingBean.value}".
So in setValue() you simply store the argument, in getValue you return the stored argument. The rest is done by JSF for you.
If you want the checkbox to be on by default, you set the stored value to true.
For example:
private boolean storedValue = true; // or false if you want it to be off by default
public boolean getValue() {
return storedValue;
}
public void setValue(boolean value) {
this.storedValue = value;
}

jsf menuitem does not set property

i try to set normal property by menu-item, but it is does not work.
jsf:
<p:menuitem value="Names"
url="/master.xhtml"
action="#{navigation.name}">
<f:setPropertyActionListener target="navigation.name"
value="Billy" />
</p:menuitem>
ManagedBean:
#ManagedBean(name="navigation")
#SessionScoped //
public class LinksNavigation {
public LinksNavigation() {
super();
this.milchFleisch = "./menuFleisch.xhtml";
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name= name;
}
}
But it does not work. I dont set with "f:setPropertyActionListener"
value = "Bully". How can i set property Value by menuItem??
Thanks
In setPropertyActionListeneryou have a String instead of an EL expression. Change
target="navigation.name"
to
target="#{navigation.name}"
Also, you need to take a closer look to at the tag documentation for p:menuitem. The attribute action is expecting a method expression. You will get a MethodNotFoundException with the way your code is set up. You need to change
action="#{navigation.name}"
to
action="#{navigation.getName}"
The abbreviated syntax #{navigation.name} is used for value expressions.
You are mixing navigation methods. You cannot have the attributes url and action together for the same p:menuItem. When I tested your code action and setPropertyActionListener were never called when url was present. This behavior suggest that you have to pick one or the other.
COMMENT
Based on your sample, I think you should rethink your approach. Let's pretend for a moment that you decided not to use url="/master.xhtml" and let's go over the sequence of events. After you press the menu item, the expression #{navigation.name} in setPropertyActionListener will first set the value "Billy" to your name property (e.g. navigation.setName("Billy")). Then the expression #{navigation.getName} in the attribute action will call getName(). Now action will have the String value "Billy" and it will try to navigate to Billy.xhtml (assuming no navigation rules in faces-config and you have JSF 2.0). If that's the behavior you're after or if you have rules set up in faces-config and you are not hardcoding the value than that's another story entirely. Just keep this in mind.

Using #ManageProperty and datatable var "currentRow"

I have a view-scoped bean ManageFoo.java:
#ManagedBean(name = "ManageFoo")
#ViewScoped
public class ManageFoo {
#ManagedProperty(value = "#{currentRow}")
private Foo currentRowBean;
.
.
public void setCurrentRowBean(Foo foo) {...}
public Foo getCureentRowBean() {...}
public void edit(ActionEvent e) {
getCurrentRowBean();
.
.
}
}
I then have the facelets file ManageFoo.xhtml:
<h:dataTable value=#{ManageFoo.foos} var="currentRow">
<h:column>
<h:commandLink actionListener="#{ManageFoo.edit}"/>
.
.
When the 'commandLink' is clicked, however, 'getCurrentRowBean' returns null.
I have this working fine using FacesContext and a getBean("currentRow") helper method, but I'm trying to "JSF 2ify" my web application by using ManagedProperty's, ManagedBean's, etc. Am I just not implementing this properly or am I trying to use ManageProperty's in a way that doesn't make sense?
After feedback from Balus, his solution works well for my action methods, but I'm having trouble getting it to work for methods that return values (such as boolean). The following method is used in a bunch of "rendered" attributes for each row. For example, if you are editing a certain row, all of the other edit buttons on the other rows disappear and the edit button for the current row is replaced by a cancel edit button and save button. So, this method has different return results for each row:
public boolean isCurrentRowEditing() {
if(getCurrentRowDataBean().equals(getCurrentDataEditing())) {
return true;
} else {
return false;
}
}
Since I'm trying to eliminate the "getCurrentRowDataBean()" method everywhere, I need a way for this to work.
The #ManagedProperty is set directly after bean's construction. At the point the bean is been constructed, JSF is definitely not busy iterating over the datatable. Also, your bean is put in view scope, so it's been set when the view is requested for the first time, not when you submit the form to the same view. The #{currentRow} will always be null.
There are several ways to achieve this. If you're running an EL 2.2 capable container or are using JBoss EL, then you could just pass it to the action (not listener!) method:
<h:commandLink action="#{manageFoo.edit(currentRow)}"/>
(note that I fixed your managed bean name to start with lowercase, conform the coding conventions)
with
public void edit(Foo currentRow) {
// ...
}
If you aren't running an EL 2.2 capable container nor can't use JBoss EL, then you need to bind the datatable's value to DataModel and use DateModel#getRowData() inside the action(listener) method to obtain the current row.
See also:
How can I pass selected row to commandLink inside dataTable? (shows all possible ways)
Recommended JSF 2.0 CRUD frameworks (shows DataModel way)
Update backing bean in datatable from h:commandButton and JPA (shows EL 2.2 way)
Update as per your update, just compare it in EL. E.g.
rendered="#{currentRow == manageFoo.currentRow}"
and
rendered="#{currentRow != manageFoo.currentRow}"
(note that this only works if its equals() is properly implemented!)

NullpointerException Binding not working JSF managed bean

I created a simple HtmlInputText
<h:inputText binding="#{IndexBean.objUIInput}" />
Then in my managed bean, it is :-
private UIInput objUIInput;
public UIInput getObjUIInput() {
objUIInput.setValue("laala");
return objUIInput;
}
public void setObjUIInput(UIInput objUIInput) {
System.out.println("Set!!");
this.objUIInput = objUIInput;
}
But i always get NullpointerException. Do i need to do anything extra on my JSF page? like we do jsp:usebean setproperty? Please help me.
Whenever you'd like to change the component's default state/behaviour prior to display, then you need to instantiate it yourself. I.e. during declaration:
private UIInput objUIInput = new HtmlInputText();
or during construction:
public Bean() {
this.objUIInput = new HtmlInputText();
}
or, as Bozho suggested, using #PostConstruct:
#PostConstruct
public void init() {
this.objUIInput = new HtmlInputText();
}
(which will take place after construction of the bean and initialization/setting of all managed properties).
And indeed, you should preferably not do any business logic in getters/setters. They are to be used to access bean properties and they can be called more than once during bean's life.
As per the comments, you can alternatively also move the UIInput#setValue() call to the setter method. JSF will call it once directly after precreating the component.
public void setObjUIInput(UIInput objUIInput) {
this.objUIInput = objUIInput;
this.objUIInput.setValue("laala");
}
When you bind a component, the getter and setter are supposed to be simple - only get/set - no logic inside them.
Perhaps the JSF lifecycle is calling the getter to check whether it needs to instantiate the component, and the getter initially would throw a NPE.
Remove all logic from your getter, or at least add a null check.
Actually, I'd advice for not using binding at all.
If you want to set an initial value to your component, use a method annotated with #PostConstruct and assign the value there, then use the value attribute.

Resources