यह सरल कस्टम घटक अन्य घटकों रैप करने के लिए इस्तेमाल किया जा सकता है और यदि अक्षम अक्षम = "सत्य" या सत्य की मूल्यांकन करने वाली ईएल अभिव्यक्ति के साथ उपयोग किया जाता है तो यह उन्हें अक्षम कर देगा। जिस तरह से यह काम करने का इरादा है कि अगर एक wrappped घटक पहले से ही तो अक्षम किया गया है यह अक्षम = "true" के साथ करता है, तो disablePanel प्रयोग किया जाता है सक्षम नहीं हो (या ajax फिर से प्रदान की गई है)। घटक केवल UIInput & UICommand घटकों को अक्षम करने के लिए है, जो मुझे लगता है कि ठीक है, लेकिन बदला जा सकता है प्रयास करता है।
xmlns:fnc="http://myco.co.uk/fnc"
...
<fnc:disablePanel disabled="#{bean.isItDisabled}">
<h:inputText/>
...
</fnc:disablePanel>
...
UIDisablePanel.java
package uk.co.myco.component;
import java.io.IOException;
import javax.faces.component.*;
import javax.faces.context.FacesContext;
/*
* @author Brendan Healey (Oversteer)
*/
@FacesComponent("uk.co.myco.component.UIDisablePanel")
public class UIDisablePanel extends UIComponentBase {
private enum PropertyKeys {
disabled;
}
public UIDisablePanel() {
setRendererType(null);
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
boolean toDisable = isDisabled();
processDisablePanel(this, toDisable);
//super.encodeBegin(context);
}
public void processDisablePanel(UIComponent root, boolean toDisable) {
/*
* The key point here is that a child component of <x:disablePanel> may
* already be disabled, in which case we don't want to enable it if the
* <x:disablePanel disabled= attribute is set to true.
*/
for (UIComponent c : root.getChildren()) {
if (c instanceof UIInput || c instanceof UICommand) {
if(toDisable) { // <x:disablePanel disabled="true">
Boolean curState = (Boolean) c.getAttributes().get("disabled");
if(curState == null || curState == false) {
c.getAttributes().put("UIPanelDisableFlag", true);
c.getAttributes().put("disabled", true);
}
}
else { // <x:disablePanel disabled="false">
if(c.getAttributes().get("UIPanelDisableFlag") != null) {
c.getAttributes().remove("UIPanelDisableFlag");
c.getAttributes().put("disabled", false);
}
}
}
if (c.getChildCount() > 0) {
processDisablePanel(c, toDisable);
}
}
}
@Override
public String getFamily() {
// Got to override it but it doesn't get called.
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean isDisabled() {
return (boolean) getStateHelper().eval(PropertyKeys.disabled, false);
}
public void setDisabled(boolean disabled) {
getStateHelper().put(PropertyKeys.disabled, disabled);
}
}
disablepanel.taglib।xml
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">
<namespace>http://myco.co.uk/fnc</namespace>
<tag>
<tag-name>disablePanel</tag-name>
<component>
<component-type>uk.co.myco.component.UIDisablePanel</component-type>
</component>
<attribute>
<name>disabled</name>
</attribute>
</tag>
</facelet-taglib>
+1 मुझे इसे मारो। एक विकल्प 'rendered' का उपयोग करना है और केवल कुछ भी छिपाएं जो उन उपयोगकर्ताओं से संपादित करने की क्षमता देता है जो ऐसा करने के लिए अधिकृत नहीं हैं। –
यह एक विकल्प हो सकता है, हालांकि यह बहुत काम करेगा। मैं उम्मीद कर रहा था कि वहां कुछ और सुरुचिपूर्ण होगा (जो मुझे पता है संभव नहीं है) ' ' –
SomeFatMan
इतना तत्व नहीं है, तत्व जोड़ते समय, बस जोड़ें अक्षम पैरामीटर। भविष्य में भी आप उदाहरण के लिए भूमिकाओं या समूहों के अनुसार अनुमति समूह समूह कर सकते हैं :) – pakore