I have the following problem: from a button call a java method and this method would have the current value of inputText in this same page, you can do this?
Kinda hard to tell what you are asking, but if you are trying to ask: When I click a button, I want the button to call a method in a backing java bean and access the value of an input text field on the ADF Faces pages, the answer is yes. You need to set the Binding property on the input text field and add a method call to the button. Use the ActionListener property for the button, and specify or create a backing bean with an actionlistener method. Then set the binding property for the input text field. The backing bean should have the get/set methods for the text field and you can use them to get a reference to the text field and call the get/setValue() method.
-
-
easier to set the binding property for the textfield in the property inspector and then it will an object reference and accessors will be added to backing bean. – Joe Jul 6 '12 at 17:11
-
I disagree. One should use a
value
property instead ofbinding
on a text field to specify a field in the managed bean, where input's value should be stored. – dragn Jul 23 '12 at 9:26
1.create a managed bean. 2.define your method use this code ::
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
RichInputText inputText = (RichInputText)root.findComponent("it1");
String val=inputText.getValue();
where it1 is id for your input text
3.select button's action listener from the button property window. 4.call your managed bean and method
Specify a value
attribute on the inputText with a EL reference to the field in managed bean with a View or higher scope (e.g. value="#{viewScope.Bean.field}"
), in your bean you would have:
private String field;
public String getField(){
return field;
};
public void setField(String field){
this.field = field;
};
Then specify an actionListener
on the commandButton
with a reference to the handler method in the same bean: actionListener="#{viewScope.Bean.handleButton}"
. Access field
in this method:
public void handleButton(ActionEvent event){
System.out.println('Input field content: ' + getField());
};
-
good point, this approach works as well. It depends on what he wants to do. If he only wants the value, this is fine. If he wants to be able to manipulate the inputTextField in other ways, then he needs the binding. BTW, I do recommend calling your own accessor methods, and not reference the attribute directly. – Joe Jul 24 '12 at 16:20
-
Agree. I guess we should encourage good programmer's etiquette, i will update my answer... :) – dragn Jul 25 '12 at 7:40
-
-
@dragn i am having similar issue kindly help me : stackoverflow.com/questions/48378783/… – Pulkit Jan 22 '18 at 10:09
understood)
<af:panelFormLayout id="pfl1">
<f:facet name="footer">
<af:commandButton text="отправить" id="cb1"
actionListener="#{inBean.doSave}" partialSubmit="true"/>
</f:facet>
<af:inputText label="Ввести данные:" value="#{inBean.myParam}" id="it1"/>
<af:outputText value="#{inBean.myParam}" id="ot1" partialTriggers="cb1"/>
</af:panelFormLayout>
public void doSave(ActionEvent actionEvent) {
// ActionResponse response = (ActionResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
// response.setRenderParameter("myParam", myParam);
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot root = context.getViewRoot();
RichInputText inputText = (RichInputText) root.findComponent("it1");
myParam = (String)inputText.getValue();
}