ERROR IN TAKING INPUT IN JSF FORM - jsf

the login page is displaying "#{ad.userid}" in input text box when loaded . I erased it and entered userid and pwd.when i clicked submit button the action method is called but the value in userid is being null in bean.could you resolve please.

Do you have getter and setter method for your name property in your bean?
Are they being call when you press submit button ?
Do you have all your components inside the h:form?
ex:-
<h:form>
<h:inputText value="#{mybean.name}" />
<h:commandButton value="CLICK" action="#{bean.method}" />
</h:form>
post your xhtml and bean

Related

Call a bean-method with a submit button and process the input of a textfield in the method

I am struggling in trying to send some information from a textfield to a bean-method and process the input there. My code looks like that:
<h:form id="form2">
<p:inputText id="casTextBox" value="#{TsneDAODB.getNearestNeighborsAsJSON('blubb2')}" />
<br/>
<p:commandButton id="nearestNeighborsSubmit" type="post" action="#{TsneDAODB.getNearestNeighborsAsJSON('blubb')}" value="Surrounding substances">
</p:commandButton>
</h:form>
I would like to send the input in the textfield to the method nearestneighborsAsJSON(String) of the bean TsneDAODB but i can't figure out how i access the content of the textfield and what attribute i have to use to send it away. The current code at least triggers the method with the given input through the action= attribute of the commandbutton (but without even pushing it). So where do i have to add the respective EL to submit the input and what would the correct EL syntax look like to access the casTextBox input?
You should link the input text box to a field contained into your bean then in your getNearestNeighborsAsJSON method you can access the value posted by your form. Remember that the bean should expose getter and setter for that field
<h:form id="form2">
<p:inputText id="casTextBox" value="#{TsneDAODB.fieldXXX}" />
<br/>
<p:commandButton id="nearestNeighborsSubmit" type="post" action="#{TsneDAODB.getNearestNeighborsAsJSON('blubb')}" value="Surrounding substances">
</p:commandButton>
</h:form>

how can I call bean method on button click in jsf

I have a jsf component with action
<h:form>
<a4j:commandButton value="click" action="#{myBean.method()}" />
</h:form>
the problem is that bean's method "method" was called only once at first click,
how can I fix it that it will be called at every click on

Reset inputText after Button Click with JSF

Is it possible to reset the value of an inputText after clicking on the commandButton in JSF? The inputText UIElement provides the method ResetValue so I tried something like this:
<h:inputText id="measurementadd" binding="#{inputTextMeasurement}">
<f:validateRegex pattern="[a-zA-Z ]*"/>
<f:ajax event="keyup" render="measurementaddmessage submit" execute="#this"/>
<h:inputText>
<p:commandButton id="submit" action="#{Bean.addMeasurement(inputTextMeasurement.value)}"
value="submit" update="dataTable measurementadd measurementaddmessage"
disabled="#{empty inputTextMeasurement.value or facesContext.validationFailed }" >
<f:ajax event="mouseup" execute="#{inputTextMeasurement.resetValue()}" />
</p:commandButton>
<h:messages for="measurementadd" id="measurementaddmessage"/>
But after clicking the Button the inputTextMeasurement doesn't reset it's value.
Does someone know a good workaround for this?
I'm searching for a solution without JS and JAVA, so a realization in JSF would be very cool.
Your mistake is here in the execute attribute:
<f:ajax event="mouseup" execute="#{inputTextMeasurement.resetValue()}" />
The execute attribute should represent a space separated collection of client IDs to include in the process/decode of the ajax request. However, you specified a listener method there.
You need the listener attribute instead:
<f:ajax listener="#{inputTextMeasurement.resetValue()}" />
(and I omitted event as it defaults here to click which is already the right one)
Interesting detail is that the other <f:ajax> in the same piece of code used the exeucte attribute the right way.
Unrelated to the concrete problem, have you looked at <p:resetInput>? This saves an ajax listener method in the bean. Replace the whole <f:ajax> with
<p:resetInput target="measurementadd" />
Why dont we just use
<input type="Reset"/>
This one is works fine for me! ???
I have solved my problem as below
<p:commandButton id="submit" action="#{Bean.addMeasurement(inputTextMeasurement)}">
Sending back bean UIInput component. Get and Reset value in back bean.
public void addMeasurement(UIInput
String msr = (String) inputTextMeasurement.getValue()
inputTextMeasurement.resetValue();
}

Set f:param in external h:commandButton (JSF2)

I really love actionListener and the possibility to pass whole objects as as parameter, instead needing to pass values as String or creating (hidden) form fields. I'm using JSF 2.1 (Mojarra) and RichFaces (for popupPanel).
Currently I'm stuck with the following problem:
I create a table with a button that opens a popup. In that popup, the user can edit the data of the current user/object in the table.
When I click the button in the popup to save the edits, how can I submit the values from the popup AND tell the bean action which userObject I'm edited?
Currently, my workaround is using a hidden inputText field in the popup, but I don't like it this way. Is there an alternative?
This is what I try to achieve (minimized):
<h:datatable value="#{bean.users}" var="user">
<h:column>
Username #{user.name}
</h:column>
<h:column>
<input onclick="showPopup()"/>
</h:column>
</h:datatable>
<rich:popupPanel>
<h:inputText value="#{bean.text}" />
<h:commandButton value="Action" actionListener="#{bean.doSomething}">
<f:attribute name="selected" value="#{userObjectFromDatatable}" /> <-- HOW? -->
</h:commandButton>
</rich:popupPanel>
Looks pretty straightforward for you to preserve the selected the userObject in a conversation-like scope as in #ViewScoped. See this article for details on the #ViewScope. As an example, Declare a variable of the desired type as an instance variable in your backing bean
UserObject userObject;
//getters and setters
In your table you'll now have something like the following to set the selected object in your backing bean
<h:commandButton value="Action" actionListener="#{bean.doSomething}">
<f:setPropertyActionListener value="#{user}" target="#{bean.userObject}"/>
</h:commandButton>
By setting the variable in your backing bean from within the table, the viewscope will ensure that any other operation you perform on that object will be with the same instance, provided you stay on the same JSF view and you do not navigate away from it.

Why rich popupPanel component of richfaces submits null value to managed beans?

I'm using rich:popupPanel component of richfaces 4.0 & jsf 2.0 which contains some form fields like name.address & contact also one a4j:commandButton "Save". The text fields are bind to managed bean properties like
<h:inputText size="25" maxlength="20" value="#{us.patient.lname}"/>
When I click on save button then add method of button is executed which prints value of textfield (i.e properties of beans). As textfield value is not empty, the value of textfield is not bind to property of beans. It gives null result why this happen only for popup?
Do you render the <rich:popupPanel> after pressing the <a4j:commandButton> ?
For example , suppose your popupPanel has the id called popup ( <rich:popupPanel id="popup">) , you need to set the reRender attribute of the <a4j:commandButton> to defines which JSF componet you want to update as a response on Ajax interaction. In your case , you should update your <rich:popupPanel> after pressing the save <a4j:commandButton> , so you should use:
<a4j:commandButton value="Save" reRender="#{rich:clientId('popup')}" />
In <rich:popupPanel> we have to include <h:form> attribute.so when we click on button this form is submit and value are passes to beans.

Resources