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;
}
Related
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;
}
Implementation: org.glassfish 2.2.12
I have the following session-scoped validator:
#ManagedBean
#SessionScoped
public class CreateGroupNameValidator extends LengthValidator implements Serializable{
#ManagedProperty(value="#{myDao}")
private MyDao myDao;
//Validate methods
}
In spite of being session-scoped and Serializable, the validator fails to restore the value of the property myDao when postback comes. I used debugger and figuredOut that the state is saved by the class StateHolderSaver which has the following consturctor:
public StateHolderSaver(FacesContext context, Object toSave) {
className = toSave.getClass().getName();
if (toSave instanceof StateHolder) {
// do not save an attached object that is marked transient.
if (!((StateHolder) toSave).isTransient()) {
Serializable [] tuple = new Serializable[StateHolderTupleIndices.LastMember.ordinal()];
tuple[StateHolderTupleIndices.StateHolderSaverInstance.ordinal()] =
(Serializable) ((StateHolder) toSave).saveState(context);
if (toSave instanceof UIComponent) {
tuple[StateHolderTupleIndices.ComponentAddedDynamically.ordinal()] = ((UIComponent)toSave).getAttributes().containsKey(DYNAMIC_COMPONENT) ? Boolean.TRUE : Boolean.FALSE;
}
savedState = tuple;
} else {
className = null;
}
} else if (toSave instanceof Serializable) {
savedState = (Serializable) toSave;
className = null;
}
}
So, since LenghtValidator implements javax.faces.component.StateHolder it didn't save my initial Dao value. Is it a normal behavior?
This is indeed specified behavior. See also a.o. Validator javadoc:
...
Validator implementations must have a zero-arguments public constructor. In addition, if the Validator class wishes to have configuration property values saved and restored with the view, the implementation must also implement StateHolder.
...
Converters and validators can be saved in JSF state so that the JSF implementation can ensure that they have after restoring the view exactly the intented property values as they were during rendering the view of the previous request (such as minimum and maximum in case of LengthValidator, might it happen that they refer a dynamic EL expression).
Although I must admit that they did during designing the JSF 1.0 specification (on which the converter/validator is still based) not really thought about the possibility to inject business service instances in a JSF converter/validator. You of course don't want to save it in the JSF view state. In case of managed properties (and thus not EJB/CDI proxies), it would only blow up the JSF view state (and thus also the HTTP session in case of server side state saving).
If you don't need your validator being JSF state aware, use composition instead of inheritance.
public class CreateGroupNameValidator {
private LengthValidator lengthValidator;
public CreateGroupNameValidator() {
lengthValidator = new LengthValidator();
}
// ...
}
Nonetheless, putting a validator in the session scope is kind of fishy. This implies that the validator's behavior is specific to the current HTTP session. I can't think of sensible real world use cases for this as they are inherently view scoped (not the validator instances but the validator properties). Usually the session scoped data (such as logged-in user) is instead injected/resolved on a thread local basis. You'd better make it request scoped if it's stateful (i.e. validator properties may vary on a per request/view basis), or application scoped if it's stateless (i.e. validator properties are the same throughout application's lifetime).
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);
I still get confused about the PAGE and the CONVERSATION (temp) scope. Maybe I get some help here.
As fas as I know, variables outjected to the PAGE scope live as long as the user only postbacks the same page. The temporary CONVERSATION scope instead even survives a redirect to the next page.
Here is a little example with two effects that are confusing to me:
First, component and outjections are in CONVERSATION scope and the tempUser data is displayed in a jsf page. But in the save method called from that jsf-page, the injected tempUser is null. Why?
Second, if I do the same but change component and #In/#Outs scopes to PAGE scope, the tempUser gets correctly injected on postback - but gets not saved, for wathever reason, although even the super.update()-method on userHome gets called. Or is there a problem in using the homeEntities that ways (the idea iwa to use them only as DAO wrapper)?
#Name("userAction")
#Scope(ScopeType.CONVERSATION)
public class UserAction implements Serializable {
private static final long serialVersionUID = -4852371546895918692L;
#In(create = true)
private UserHome userHome;
#Out(scope = ScopeType.CONVERSATION)
#In(required = false,scope = ScopeType.CONVERSATION)
User tempUser;
#RequestParameter
private Long userId;
#Factory("tempUser")
public User getUser() {
if (tempUser == null) {
userHome.setUserId(userId);
tempUser = userHome.getInstance();
userHome.clearInstance();
}
return tempUser;
}
public void save() {
userHome.setInstance(tempUser);
userHome.update();
}
}
The xhtml contains a a:form with
<a:commandButton
id="update"
styleClass="button admin"
action="#{userAction.save}"
value="#{messages['user.action.update']}"/>
Thanks for replies. Sorry, if this is two problems in one.
JSF view code:
<f:view>
<h:form>
<h:panelGrid>
<h:inputText id="key" value="#{myManagedBean.key}"/>
<h:selectBooleanCheckbox id="rerun" value="#{myManagedBean.rerun}" rendered="#{myManagedBean.displayRerun}"/>
<h:commandButton id="check" action="#{myManagedBean.check}"/>
</h:panelGrid>
</h:form>
<f:view>
JSF model code:
public class MyManagedBean {
private boolean displayRerun;
public void setDisplayRerun(boolean aDisplayRerun) {
this.displayRerun = aDisplayRerun }
public boolean getDisplayRerun() {
return this.displayRerun;
}
private String key;
public void setKey(String aKey) {
this.key = aKey
}
public String getKey() {
return this.key;
}
private boolean rerun;
public void setRerun(boolean arerun) {
this.rerun = arerun
}
public boolean getRerun() {
return this.rerun;
}
public String check() {
//do data validation
setDisplayRerun(true);
System.out.println(getRerun());
}
}
This always prints false regardless of whether the checkbox is checked or not.
Additional Information on my requirement:
Nick/BalusC, my managed bean is of request scope. It is indeed simplified code snippet that I presented. My page has couple of user input controls along with a command button. On submit of command button, I call action method of backing bean, in which I do data validation (in this case I lookup database and see if the inputs are already registered.) If already registered, I come back to the same page, this is when I display the singleBooleanCheckBox for the user to select and hit the command button again.
I am toggling the display of the checkbox based on a managedbean property (a boolean flag set during data validation).
When I re-submit the page with checkbox checked, I do not receive this data.
For further verification, I replace the selectBooleanCheckbox, with a command button with similar behavior (basically do not render it initially, but only show it on data validation). I mapped its #action to my managedbean's action method. To my surprise, when I hit the button, the action method is not executed. Instead, the page is refreshed like in a "immediate" scenario or a redirect.
I have been struggling on this for almost 6 hrs. Appreciate your experienced insights.
Thanks.
So, you've actually a rendered attribute on the checkbox (that was not present in your initial question) and the bean is request scoped (it would have worked when it was session scoped). The submitted checkbox value will not be gathered during apply request values phase when this attribtue evaluates false at that point.
You basically need to retain the condition responsible for the rendered attribute in the subsequent request as well. This can be done in several ways: putting bean in session scope, using Tomahawk's t:saveState or h:inputHidden with a bean binding. Each is outlined in detail in this answer.